testutil

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Overview

Package testutil implements functions used to test the different packages

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertChartAnnotations

func AssertChartAnnotations(t *testing.T, chartDir string, annotationsKey string, expectedImages []AnnotationEntry, msgAndArgs ...interface{}) bool

AssertChartAnnotations checks if the specified chart contains the provided annotations

func AssertErrorMatch

func AssertErrorMatch(t *testing.T, err error, re *regexp.Regexp, msgAndArgs ...interface{}) bool

AssertErrorMatch fails the test t if err is nil or if its message does not match the provided regexp re

func AssertFileDoesNotExist

func AssertFileDoesNotExist(t *testing.T, path string, msgAndArgs ...interface{}) bool

AssertFileDoesNotExist failts the test t if path exists

func AssertFileExists

func AssertFileExists(t *testing.T, path string, msgAndArgs ...interface{}) bool

AssertFileExists failts the test t if path does not exists

func AssertPanicsMatch

func AssertPanicsMatch(t *testing.T, fn func(), re *regexp.Regexp, msgAndArgs ...interface{}) bool

AssertPanicsMatch fails the test t if fn does not panic or if the panic message does not match the provided regexp re

func CosignImage added in v0.3.0

func CosignImage(url string, key string, opts ...crane.Option) error

CosignImage signs a remote artifact with the provided key

func CosignVerifyImage added in v0.3.0

func CosignVerifyImage(url string, key string, opts ...crane.Option) error

CosignVerifyImage verifies a remote artifact signature with the provided key

func CreateOCILayout added in v0.3.0

func CreateOCILayout(ctx context.Context, srcDir, destDir string) error

CreateOCILayout creates a oc-layout directory from a source directory containing a set of files

func CreateSampleImages

func CreateSampleImages(imageData *ImageData, archs []string) ([]v1.Image, error)

CreateSampleImages create a multiplatform sample image

func CreateSingleArchImage

func CreateSingleArchImage(imageData *ImageData, plat string) (v1.Image, error)

CreateSingleArchImage creates a sample image for the specified platform

func GenerateCosignCertificateFiles added in v0.3.0

func GenerateCosignCertificateFiles(tmpDir string) (privFile, pubFile string, err error)

GenerateCosignCertificateFiles generates sample signing keys for usage with cosign

func Measure

func Measure(fn func()) time.Duration

Measure executes fn and returns the time taken for it to finish

func MustNormalizeYAML

func MustNormalizeYAML(text string) string

MustNormalizeYAML returns the normalized version of the text YAML or panics

func NewOCIServer added in v0.4.0

func NewOCIServer(t *testing.T, dir string) (*repotest.OCIServer, error)

NewOCIServer returns a new OCI server with basic auth for testing purposes

func NewOCIServerWithCustomCreds added in v0.4.0

func NewOCIServerWithCustomCreds(t *testing.T, dir string, username, password string) (*repotest.OCIServer, error)

NewOCIServerWithCustomCreds returns a new OCI server with custom credentials

func NormalizeYAML

func NormalizeYAML(text string) (string, error)

NormalizeYAML returns a normalized version of the provided YAML text

func PullArtifact added in v0.3.0

func PullArtifact(ctx context.Context, src string, dir string, opts ...crane.Option) error

PullArtifact downloads an artifact from a remote oci into a oci-layout

func ReadRemoteImageManifest

func ReadRemoteImageManifest(src string, opts ...Option) (map[string]DigestData, error)

ReadRemoteImageManifest reads the image src digests from a remote repository

func RenderScenario

func RenderScenario(origin string, destDir string, data map[string]interface{}) error

RenderScenario renders a full directory specified by origin in the destDir directory with the specified data

func RenderTemplateFile

func RenderTemplateFile(file string, tplData interface{}, files ...string) (string, error)

RenderTemplateFile renders the golang template specified in file with the provided tplData. It can receive an optional list of files to parse, including templates

func RenderTemplateString

func RenderTemplateString(str string, tplData interface{}, files ...string) (string, error)

RenderTemplateString renders a golang template defined in str with the provided tplData. It can receive an optional list of files to parse, including templates

func UnpackOCILayout added in v0.3.0

func UnpackOCILayout(ctx context.Context, srcLayout string, destDir string) error

UnpackOCILayout takes an oci-layout directory and extracts its artifacts to the destDir

Types

type AnnotationEntry

type AnnotationEntry struct {
	Name  string
	Image string
}

AnnotationEntry defines an annotation entry

type Auth added in v0.4.0

type Auth struct {
	Username string
	Password string
}

Auth defines the authentication information to access the container registry

type Config added in v0.3.0

type Config struct {
	SignKey     string
	MetadataDir string
	Auth        Auth
}

Config defines multiple test util options

func NewConfig added in v0.3.0

func NewConfig(opts ...Option) *Config

NewConfig returns a new Config

type DigestData

type DigestData struct {
	Arch   string
	Digest digest.Digest
}

DigestData defines Digest information for an Architecture

type ImageData

type ImageData struct {
	Name    string
	Image   string
	Digests []DigestData
}

ImageData defines information for a docker image

func AddSampleImagesToRegistry

func AddSampleImagesToRegistry(imageName string, server string, opts ...Option) ([]ImageData, error)

AddSampleImagesToRegistry adds a set of sample images to the provided registry

type Option added in v0.3.0

type Option func(*Config)

Option defines a Config option

func WithAuth added in v0.4.0

func WithAuth(username, password string) Option

WithAuth sets the credentials to access the container registry

func WithMetadataDir added in v0.3.0

func WithMetadataDir(dir string) Option

WithMetadataDir sets a signing key to be used while pushing images

func WithSignKey added in v0.3.0

func WithSignKey(key string) Option

WithSignKey sets a signing key to be used while pushing images

type Sandbox

type Sandbox struct {
	sync.RWMutex
	// Root of the sandbox
	Root string
	// contains filtered or unexported fields
}

Sandbox allows manipulating files and directories with paths sandboxed into the Root directory

func NewSandbox

func NewSandbox(args ...string) *Sandbox

NewSandbox returns a new sandbox with the configured root or a random temporary one if none is provided

func (*Sandbox) Cleanup

func (sb *Sandbox) Cleanup() error

Cleanup removes all the resources created by the sandbox

func (*Sandbox) ContainsPath

func (sb *Sandbox) ContainsPath(path string) bool

ContainsPath returns true if path is contained inside the sandbox and false otherwise. This function does not check for the existence of the file, just checks if the path is contained in the sanbox root

func (*Sandbox) Mkdir

func (sb *Sandbox) Mkdir(p string, mode os.FileMode) (string, error)

Mkdir creates a directory inside the sandbox

func (*Sandbox) Normalize

func (sb *Sandbox) Normalize(path string) string

Normalize returns the fully normalized version of path, including the Root prefix

func (sb *Sandbox) Symlink(oldname, newname string) (string, error)

Symlink creates a symlink inside the sandbox

func (*Sandbox) TempFile

func (sb *Sandbox) TempFile(args ...string) string

TempFile returns a temporary non-existent file. An optional file tail can be provided

func (*Sandbox) Touch

func (sb *Sandbox) Touch(file string) string

Touch touches a file inside the sandbox

func (*Sandbox) Track

func (sb *Sandbox) Track(p string)

Track registers a path as a temporary one to be deleted on cleanup

func (*Sandbox) Write

func (sb *Sandbox) Write(path string, data string) (string, error)

Write writes data into the file pointed by path. This is a convenience wrapper around WriteFile

func (*Sandbox) WriteFile

func (sb *Sandbox) WriteFile(path string, data []byte, mode os.FileMode) (string, error)

WriteFile writes a set of bytes (data) into the file pointed by path and with the specified mode

type TestServer

type TestServer struct {
	ServerURL string
	// contains filtered or unexported fields
}

TestServer defines a images registry for testing

func NewTestServer

func NewTestServer() (*TestServer, error)

NewTestServer returns a new TestServer

func (*TestServer) AddImage

func (s *TestServer) AddImage(img *ImageData) error

AddImage adds information for an image to the server so it can be later queried

func (*TestServer) Close

func (s *TestServer) Close()

Close shuts down the test server

func (*TestServer) LoadImagesFromFile

func (s *TestServer) LoadImagesFromFile(file string) ([]*ImageData, error)

LoadImagesFromFile adds the images specified in the JSON file provided to the server

Jump to

Keyboard shortcuts

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