testhelpers

package
v0.0.0-...-bef4977 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertBlobsLen

func AssertBlobsLen(t *testing.T, path string, expected int)

func AssertContains

func AssertContains(t *testing.T, slice []string, elements ...string)

func AssertDockerMediaTypes

func AssertDockerMediaTypes(t *testing.T, image v1.Image)

func AssertDoesNotContain

func AssertDoesNotContain(t *testing.T, slice []string, elements ...string)

func AssertEq

func AssertEq(t *testing.T, actual, expected interface{})

AssertEq asserts deep equality (and provides a useful difference as a test failure)

func AssertEqAnnotation

func AssertEqAnnotation(t *testing.T, manifest v1.Descriptor, key, value string)

func AssertError

func AssertError(t *testing.T, actual error, expected string)

func AssertMatch

func AssertMatch(t *testing.T, actual string, expected *regexp.Regexp)

func AssertNil

func AssertNil(t *testing.T, actual interface{})

func AssertNotEq

func AssertNotEq(t *testing.T, v1, v2 interface{})

func AssertOCIMediaTypes

func AssertOCIMediaTypes(t *testing.T, image v1.Image)

func AssertPathExists

func AssertPathExists(t *testing.T, path string)

func AssertTrue

func AssertTrue(t *testing.T, p func() bool)

func BasicAuth

func BasicAuth(handler http.Handler, username, password, realm string) http.Handler

BasicAuth wraps a handler, allowing requests with matching username and password headers, otherwise rejecting with a 401

func CreateSingleFileLayerTar

func CreateSingleFileLayerTar(layerPath, txt, osType string) (string, error)

func CreateSingleFileTar

func CreateSingleFileTar(path, txt string) (io.Reader, error)

func CreateSingleFileTarReader

func CreateSingleFileTarReader(path, txt string) io.ReadCloser

func DeleteRegistryBlob

func DeleteRegistryBlob(t *testing.T, repoName string, digest v1.Hash, encodedAuth string)

DeleteRegistryBlob deletes the blob with the given digest from the registry by issuing an HTTP DELETE request.

func DockerCli

func DockerCli(t *testing.T) dockercli.CommonAPIClient

func DockerHostname

func DockerHostname(t *testing.T) string

DockerHostname discovers the appropriate registry hostname. For test to run where "localhost" is not the daemon host, a `insecure-registries` entry of `<host net>/<mask>` with a range that contains the host's non-loopback IP. For Docker Desktop, this can be set here: https://docs.docker.com/docker-for-mac/#docker-engine Otherwise, its set in the daemon.json: https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file If the entry is not found, the fallback is "localhost"

func DockerRmi

func DockerRmi(dockerCli dockercli.CommonAPIClient, repoNames ...string) error

func Eventually

func Eventually(t *testing.T, test func() bool, every time.Duration, timeout time.Duration)

func FetchManifestImageConfigFile

func FetchManifestImageConfigFile(t *testing.T, repoName string) *v1.ConfigFile

func FetchManifestLayers

func FetchManifestLayers(t *testing.T, repoName string) []string

func FileDiffID

func FileDiffID(t *testing.T, path string) string

func ImageID

func ImageID(t *testing.T, repoName string) string

func PullIfMissing

func PullIfMissing(t *testing.T, docker dockercli.CommonAPIClient, ref string)

func PushImage

func PushImage(t *testing.T, _ dockercli.CommonAPIClient, refStr string)

PushImage pushes an image to a registry, optionally using credentials from any set DOCKER_CONFIG

func RandString

func RandString(n int) string

func RandomLayer

func RandomLayer(t *testing.T, tmpDir string) (path string, sha string, contents []byte)

func ReadConfigFile

func ReadConfigFile(t *testing.T, manifest *v1.Manifest, path string) *v1.ConfigFile

func ReadIndexManifest

func ReadIndexManifest(t *testing.T, path string) *v1.IndexManifest

func ReadManifest

func ReadManifest(t *testing.T, digest v1.Hash, path string) *v1.Manifest

func ReadManifestAndConfigFile

func ReadManifestAndConfigFile(t *testing.T, path string) (*v1.Manifest, *v1.ConfigFile)

func ReadOnly

func ReadOnly(handler http.Handler) http.Handler

ReadOnly wraps a handler, allowing only GET and HEAD requests, otherwise rejecting with a 405

func RemoteImage

func RemoteImage(t *testing.T, testImageName string, opts []remote.Option) v1.Image

func RemoteRunnableBaseImage

func RemoteRunnableBaseImage(t *testing.T) v1.Image

func Run

func Run(t *testing.T, cmd *exec.Cmd) string

func RunE

func RunE(cmd *exec.Cmd) (output string, exitCode int, err error)

func RunnableBaseImage

func RunnableBaseImage(os string) string

RunnableBaseImage returns an image that can be used by a daemon of the same OS to create an container or run a command

func StringElementAt

func StringElementAt(elements []string, offset int) string

Types

type DockerRegistry

type DockerRegistry struct {
	Host string
	Port string
	Name string

	DockerDirectory string
	// contains filtered or unexported fields
}

func NewDockerRegistry

func NewDockerRegistry(ops ...RegistryOption) *DockerRegistry

func (*DockerRegistry) EncodedAuth

func (r *DockerRegistry) EncodedAuth() string

func (*DockerRegistry) EncodedLabeledAuth

func (r *DockerRegistry) EncodedLabeledAuth() string

func (*DockerRegistry) RepoName

func (r *DockerRegistry) RepoName(name string) string

func (*DockerRegistry) SetInaccessible

func (r *DockerRegistry) SetInaccessible(imageName string) string

SetInaccessible set the given image name to do not have any access when the ImagePrivileges feature was enabled Returns RepoName(imageName)

func (*DockerRegistry) SetReadOnly

func (r *DockerRegistry) SetReadOnly(imageName string) string

SetReadOnly set the given image name to be readable when the ImagePrivileges feature was enabled Returns RepoName(imageName)

func (*DockerRegistry) SetReadWrite

func (r *DockerRegistry) SetReadWrite(imageName string) string

SetReadWrite set the given image name to be readable and writable when the ImagePrivileges feature was enabled Returns RepoName(imageName)

func (*DockerRegistry) SetWriteOnly

func (r *DockerRegistry) SetWriteOnly(imageName string) string

SetWriteOnly set the given image name to be writable when the ImagePrivileges feature was enabled Returns RepoName(imageName)

func (*DockerRegistry) Start

func (r *DockerRegistry) Start(t *testing.T)

Start creates a docker registry following these rules:

  • Shared handler will be used, otherwise a new one will be created
  • By default the shared handler will be wrapped with a read only handler
  • In case credentials are configured, the shared handler will be wrapped with a basic authentication handler and if any image privileges were set, then the custom handler will be used to wrap the auth handler.

func (*DockerRegistry) Stop

func (r *DockerRegistry) Stop(t *testing.T)

type ImageAccess

type ImageAccess int
const (
	Readable ImageAccess = iota
	Writable
)

type ImagePrivileges

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

func NewImagePrivileges

func NewImagePrivileges(imageAccess ...ImageAccess) ImagePrivileges

NewImagePrivileges creates a new ImagePrivileges, use Readable or Writable to set the properties accordingly. For examples: NewImagePrivileges() returns ImagePrivileges{readable: false, writable: false} NewImagePrivileges(Readable) returns ImagePrivileges{readable: true, writable: false} NewImagePrivileges(Writable) returns ImagePrivileges{readable: false, writable: true} NewImagePrivileges(Readable, Writable) returns ImagePrivileges{readable: true, writable: true}

type RegistryOption

type RegistryOption func(registry *DockerRegistry)

func WithAuth

func WithAuth(dockerConfigDir string) RegistryOption

WithAuth adds credentials to registry. Omitting will make the registry read-only

func WithImagePrivileges

func WithImagePrivileges() RegistryOption

WithImagePrivileges enables the execution of read/write access validations based on the image name

func WithSharedHandler

func WithSharedHandler(handler http.Handler) RegistryOption

WithSharedHandler allows two instances to share the same data by re-using the registry handler. Use an authenticated registry to write to a read-only unauthenticated registry.

Jump to

Keyboard shortcuts

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