registrytest

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2024 License: Apache-2.0, MIT Imports: 15 Imported by: 0

Documentation

Overview

Package registrytest provides test-doubles and fakes for the registry.Client and other related types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GzipTarballBytes

func GzipTarballBytes(fs fs.FS) []byte

GzipTarballBytes returns a gzipped tarball of the given filesystem as a byte slice.

func TarballBytes

func TarballBytes(fs fs.FS) []byte

TarballBytes returns a tarball of the given filesystem as a byte slice.

Types

type CacheListener

type CacheListener struct {
	registry.BaseCacheListener
	// contains filtered or unexported fields
}

CacheListener is a fake implementation of the registry.CacheListener interface.

func NewCacheListener

func NewCacheListener() *CacheListener

func (*CacheListener) CacheHits

func (l *CacheListener) CacheHits(registry, pkg, version string) int

CacheHits returns the number of times [OnCacheHit] was called for the given package.

func (*CacheListener) DeleteCalls

func (l *CacheListener) DeleteCalls(registry, pkg, version string) int

DeleteCalls returns the number of times [OnDelete] was called for the given package.

func (*CacheListener) FetchBytes

func (l *CacheListener) FetchBytes(registry, pkg, version string) int64

FetchBytes returns the total number of bytes fetched for the given package.

func (*CacheListener) FetchCalls

func (l *CacheListener) FetchCalls(registry, pkg, version string) int

FetchCalls returns the number of times [OnFetch] was called for the given package.

func (*CacheListener) FetchWriteCalls

func (l *CacheListener) FetchWriteCalls(registry, pkg, version string) int

FetchWriteCalls returns the number of times [OnFetchWrite] was called for the given package.

func (*CacheListener) FetchWriteContent

func (l *CacheListener) FetchWriteContent(registry, pkg, version string) io.Reader

FetchWriteContent returns a reader that reads the bytes written during fetch for the given package.

func (*CacheListener) FetchWriteTotal

func (l *CacheListener) FetchWriteTotal(registry, pkg, version string) int64

FetchWriteTotal returns the total number of bytes written during fetch for the given package.

func (*CacheListener) OnCacheHit

func (l *CacheListener) OnCacheHit(registry, pkg, version string)

OnCacheHit is a no-op implementation of the CacheListener interface.

func (*CacheListener) OnDelete

func (l *CacheListener) OnDelete(registry, pkg, version string)

OnDelete is a no-op implementation of the CacheListener interface.

func (*CacheListener) OnFetch

func (l *CacheListener) OnFetch(registry, pkg, version string, bytes int64)

OnFetch is a no-op implementation of the CacheListener interface.

func (*CacheListener) OnFetchWrite

func (l *CacheListener) OnFetchWrite(registry, pkg, version string, bytes []byte)

OnFetchWrite is a no-op implementation of the CacheListener interface.

func (*CacheListener) OnUnpack

func (l *CacheListener) OnUnpack(registry, pkg, version, file string, size int64)

OnUnpack is a no-op implementation of the CacheListener interface.

func (*CacheListener) OnUnpackWrite

func (l *CacheListener) OnUnpackWrite(registry, pkg, version, file string, bytes []byte)

OnUnpackWrite is a no-op implementation of the CacheListener interface.

func (*CacheListener) UnpackCalls

func (l *CacheListener) UnpackCalls(registry, pkg, version string) int

UnpackCalls returns the number of times [OnUnpack] was called for the given package.

func (*CacheListener) UnpackFileCalls

func (l *CacheListener) UnpackFileCalls(registry, pkg, version, file string) int

UnpackFileCalls returns the number of times [OnUnpack] was called for the given package and file.

func (*CacheListener) UnpackFileTotal

func (l *CacheListener) UnpackFileTotal(registry, pkg, version, file string) int64

UnpackFileTotal returns the total number of bytes unpacked for the given file in the package.

func (*CacheListener) UnpackTotal

func (l *CacheListener) UnpackTotal(registry, pkg, version string) int64

UnpackTotal returns the total number of bytes unpacked for the given package.

func (*CacheListener) UnpackWriteCalls

func (l *CacheListener) UnpackWriteCalls(registry, pkg, version string) int

UnpackWriteCalls returns the number of times [OnUnpackWrite] was called for the given package.

func (*CacheListener) UnpackWriteContent

func (l *CacheListener) UnpackWriteContent(registry, pkg, version string) io.Reader

UnpackWriteContent returns a reader that reads the bytes written during unpack for the given package.

func (*CacheListener) UnpackWriteTotal

func (l *CacheListener) UnpackWriteTotal(registry, pkg, version string) int64

UnpackWriteTotal returns the total number of bytes written during unpack for the given package.

type FakeClient

type FakeClient struct {
	*registry.Client
	// contains filtered or unexported fields
}

FakeClient is a fake registry client which can be used for local-only testing, without needing to spawn up an http server.

This makes it easier to write tests that require a client without needing to worry about network connectivity.

FakeClient is thread-safe/goroutine-safe.

func NewFakeClient

func NewFakeClient() *FakeClient

NewFakeClient creates a new fake client for testing.

func (*FakeClient) Set

func (fc *FakeClient) Set(name, version string, statusCode int, content []byte)

Set sets the exact response/status-code for the given package and version.

func (*FakeClient) SetError

func (fc *FakeClient) SetError(name, version string, err error)

SetError sets the error response for the given package and version.

func (*FakeClient) SetGzipTarball

func (fc *FakeClient) SetGzipTarball(name, version string, content []byte)

SetGzipTarball sets the gzip response for the given package and version.

func (*FakeClient) SetTarball

func (fc *FakeClient) SetTarball(name, version string, content []byte)

SetTarball sets the tar response for the given package and version.

func (*FakeClient) SetTarballFS

func (fc *FakeClient) SetTarballFS(name, version string, fs fs.FS)

SetTarballFS sets the tarball respons for the given package and version, done as a filesystem

type FakeServer

type FakeServer struct {
	// contains filtered or unexported fields
}

FakeServer is a server that can be spawned up for testing registry clients.

func NewFakeServer

func NewFakeServer() *FakeServer

NewFakeServer creates a new fake server for testing.

The server is not started by default, and must be started by calling the Start function.

func (*FakeServer) Close

func (f *FakeServer) Close()

Close shuts down the fake server.

func (*FakeServer) SetContent

func (f *FakeServer) SetContent(name, version, contentType string, bytes []byte)

SetContent sets the content response that will be returned by the server for the given package.

func (*FakeServer) SetError

func (f *FakeServer) SetError(name, version string, err error)

SetError makes the fake server return an error for the given package.

func (*FakeServer) SetGzipTarball

func (f *FakeServer) SetGzipTarball(name, version string, bytes []byte)

SetGzipTarball adds a gzipped tarball to the fake server.

func (*FakeServer) SetIndirectGzipTarball

func (f *FakeServer) SetIndirectGzipTarball(name, version string, content []byte)

SetIndirectGzipTarball adds a package to the fake server that redirects to another URL for the tarball content.

func (*FakeServer) SetIndirectTarball

func (f *FakeServer) SetIndirectTarball(name, version string, content []byte)

SetIndirectTarball adds a package to the fake server that redirects to

func (*FakeServer) SetIndirectTarballFS

func (f *FakeServer) SetIndirectTarballFS(name, version string, fs fs.FS)

SetIndirectTarballFS sets the indirect tarball response for the given package and version, done as a filesystem.

func (*FakeServer) SetStatusCode

func (f *FakeServer) SetStatusCode(name, version string, code int)

SetStatusCode makes the fake server return an error for the given package.

func (*FakeServer) SetTarball

func (f *FakeServer) SetTarball(name, version string, bytes []byte)

SetTarball adds a package to the fake server.

func (*FakeServer) SetTarballFS

func (f *FakeServer) SetTarballFS(name, version string, fs fs.FS)

SetTarballFS sets the tarball response for the given package and version, done as a filesystem.

func (*FakeServer) URL

func (f *FakeServer) URL() string

URL returns the URL of the fake server, which can be used in the client for testing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL