testhelper

package
Version: v0.0.0-...-8a004fb Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const VaultTestingRootToken = "jpuxZFWWFW7vM882GGX2aWOE"

Variables

View Source
var (
	// EquateErrorMessage reports errors to be equal if both are nil
	// or both have the same message.
	EquateErrorMessage = cmp.FilterValues(func(x, y interface{}) bool {
		_, ok1 := x.(error)
		_, ok2 := y.(error)
		return ok1 && ok2
	}, cmp.Comparer(func(x, y interface{}) bool {
		xe := x.(error)
		ye := y.(error)
		if xe == nil || ye == nil {
			return xe == nil && ye == nil
		}
		return xe.Error() == ye.Error()
	}))

	// RuntimeObjectIgnoreRvTypeMeta compares two kubernetes objects, ignoring their resource
	// version and TypeMeta. It is what you want 99% of the time.
	RuntimeObjectIgnoreRvTypeMeta = cmp.Comparer(func(x, y runtime.Object) bool {
		xCopy := x.DeepCopyObject()
		yCopy := y.DeepCopyObject()
		CleanRVAndTypeMeta(xCopy)
		CleanRVAndTypeMeta(yCopy)
		return cmp.Diff(xCopy, yCopy) == ""
	})
)

Functions

func ArtifactDir

func ArtifactDir(t TestingTInterface) string

ArtifactDir determines where artifacts should for for a test case.

func CleanRVAndTypeMeta

func CleanRVAndTypeMeta(r runtime.Object)

func CompareWithFixture

func CompareWithFixture(t *testing.T, output interface{}, opts ...Option)

CompareWithFixture will compare output with a test fixture and allows to automatically update them by setting the UPDATE env var. If output is not a []byte or string, it will get serialized as yaml prior to the comparison. The fixtures are stored in $PWD/testdata/prefix${testName}.yaml

func Diff

func Diff(t *testing.T, name string, x, y interface{}, opts ...cmp.Option)

func GetFreePort

func GetFreePort(t TestingTInterface) string

GetFreePort asks the kernel for a free open port that is ready to use.

func ReadFromFixture

func ReadFromFixture(t *testing.T, identifier string) []byte

ReadFromFixture reads an input fixture file and returns the data

func TmpDir

func TmpDir(t *testing.T, files map[string]fstest.MapFile) (string, error)

func Vault

func Vault(t *testing.T) string

Vault constructs a running Vault instance ready for testing. It returns its addess. VaultTestingRootToken is the initial root token.

func WaitForHTTP200

func WaitForHTTP200(addr, command string, t TestingTInterface)

WaitForHTTP200 waits 30 seconds for the provided addr to return a http/200. If that doesn't happen, it will call t.Fatalf

func WriteToFixture

func WriteToFixture(t *testing.T, identifier string, data []byte)

WriteToFixture reads an input fixture file and returns the data

Types

type Accessory

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

func NewAccessory

func NewAccessory(command string, args []string, portFlags, clientPortFlags PortFlags, env ...string) *Accessory

func (*Accessory) ClientFlags

func (a *Accessory) ClientFlags() []string

ClientFlags exposes the port on which we are serving content and any other flags that are needed for clients to consume this accessory.

func (*Accessory) Ready

func (a *Accessory) Ready(t TestingTInterface, o ...ReadyOption)

Ready returns when the accessory process is ready to serve data.

func (*Accessory) Run

func (a *Accessory) Run(t TestingTInterface)

Run begins the accessory process. this call is not blocking. Because testing.T does not allow to call Fatalf in a distinct goroutine, this will use Errorf instead.

func (*Accessory) RunFromFrameworkRunner

func (a *Accessory) RunFromFrameworkRunner(t TestingTInterface, parentCtx context.Context, stream bool)

RunFromFrameworkRunner begins the accessory process. Only test/e2e/framework.Run is allowed to call this as it required additional synchronization or your tests might pass incorrectly.

type Option

type Option func(*Options)

func WithExtension

func WithExtension(extension string) Option

func WithPrefix

func WithPrefix(prefix string) Option

func WithSuffix

func WithSuffix(suffix string) Option

type Options

type Options struct {
	Prefix    string
	Suffix    string
	Extension string
}

type PortFlags

type PortFlags func(port, healthPort string) []string

type ReadyOption

type ReadyOption func(*ReadyOptions)

type ReadyOptions

type ReadyOptions struct {
	// ReadyURL is the url to GET to check for readyness. Defaults to
	// http://127.0.0.1:${HEALTH_PORT}/healthz/ready
	ReadyURL string
}

type T

type T struct {
	*testing.T
	// contains filtered or unexported fields
}

T allows us to provide a similar UX to the testing.T while doing so in a multi-threaded context. The Go unit testing framework only allows the top-level goroutine to call FailNow so it's important to provide this interface to all the routines that want to be able to control the test execution flow.

func NewT

func NewT(ctx context.Context, t *testing.T) *T

func (*T) Errorf

func (t *T) Errorf(format string, args ...interface{})

func (*T) Fatal

func (t *T) Fatal(args ...interface{})

func (*T) Fatalf

func (t *T) Fatalf(format string, args ...interface{})

func (*T) Log

func (t *T) Log(args ...interface{})

the testing.T logger is not threadsafe...

func (*T) Logf

func (t *T) Logf(format string, args ...interface{})

the testing.T logger is not threadsafe...

func (*T) Wait

func (t *T) Wait()

Wait receives data from producer threads and forwards it to the delegate; this call is blocking.

type TestingTInterface

type TestingTInterface interface {
	Cleanup(f func())
	Deadline() (deadline time.Time, ok bool)
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fail()
	FailNow()
	Failed() bool
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Helper()
	Log(args ...interface{})
	Logf(format string, args ...interface{})
	Name() string
	Parallel()
	Skip(args ...interface{})
	SkipNow()
	Skipf(format string, args ...interface{})
	Skipped() bool
	TempDir() string
}

TestingTInterface contains the methods that are implemented by both our T and testing.T

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL