test

package
v1.46.2 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: Apache-2.0, BSD-2-Clause, MIT, + 1 more Imports: 22 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EXPECTPatch added in v1.19.0

func EXPECTPatch(ctx interface{}, c *mockclient.MockClient, expectedObj, mergeFrom client.Object, patchType types.PatchType, rets ...interface{}) *gomock.Call

EXPECTPatch is a helper function for a GoMock call expecting a patch with the mock client.

func EXPECTPatchWithOptimisticLock added in v1.32.0

func EXPECTPatchWithOptimisticLock(ctx interface{}, c *mockclient.MockClient, expectedObj, mergeFrom client.Object, rets ...interface{}) *gomock.Call

EXPECTPatchWithOptimisticLock is a helper function for a GoMock call with the mock client expecting a merge patch with optimistic lock.

func EnsureTestResources added in v1.17.0

func EnsureTestResources(ctx context.Context, c client.Client, path string) ([]client.Object, error)

EnsureTestResources reads test resources from path, applies them using the given client and returns the created objects.

func HasObjectKeyOf added in v1.25.0

func HasObjectKeyOf(expected client.Object) gomock.Matcher

HasObjectKeyOf returns a gomock.Matcher that matches if actual is a client.Object that has the same ObjectKey as expected.

func ReadTestResources added in v1.17.0

func ReadTestResources(scheme *runtime.Scheme, path string) ([]client.Object, error)

ReadTestResources reads test resources from path, decodes them using the given scheme and returns the parsed objects. Objects are values of the proper API types, if registered in the given scheme, and *unstructured.Unstructured otherwise.

func WithEnvVar

func WithEnvVar(key, value string) func()

WithEnvVar sets the env variable to the given environment variable and returns a function to revert. If the value is empty, the environment variable will be unset.

func WithFeatureGate added in v1.12.0

func WithFeatureGate(gate featuregate.FeatureGate, f featuregate.Feature, value bool) func()

WithFeatureGate sets the specified gate to the specified value, and returns a function that restores the original value. Failures to set or restore cause the test to fail. Example use:

defer WithFeatureGate(utilfeature.DefaultFeatureGate, features.<FeatureName>, true)()

func WithTempFile added in v1.18.0

func WithTempFile(dir, pattern string, content []byte, fileName *string) func()

WithTempFile creates a temporary file with the given dir and pattern, writes the given content to it, and returns a function to delete it. Failures to create, open, close, or delete the file case the test to fail.

The filename is generated by taking pattern and adding a random string to the end. If pattern includes a "*", the random string replaces the last "*". If dir is the empty string, WriteTempFile uses the default directory for temporary files (see ioutil.TempFile). The caller can use the value of fileName to find the pathname of the file.

Example usage:

var fileName string
defer WithTempFile("", "test", []byte("test file content"), &fileName)()

func WithVar

func WithVar(dst, src interface{}) func()

WithVar sets the given var to the src value and returns a function to revert to the original state. The type of `dst` has to be a settable pointer. The value of `src` has to be assignable to the type of `dst`.

Example usage:

v := "foo"
defer WithVar(&v, "bar")()

func WithVars

func WithVars(dstsAndSrcs ...interface{}) func()

WithVars sets the given vars to the given values and returns a function to revert back. dstsAndSrcs have to appear in pairs of 2, otherwise there will be a runtime panic.

Example usage:

defer WithVars(&v, "foo", &x, "bar")()

func WithWd

func WithWd(path string) func()

WithWd sets the working directory and returns a function to revert to the previous one.

Types

type Command added in v1.19.0

type Command struct {
	Name  string
	Flags []Flag
	Args  []string
}

Command is a command that has a name, a list of flags, and a list of arguments.

func (*Command) Slice added in v1.19.0

func (c *Command) Slice() []string

Slice returns a representation of this Command as a slice of strings.

func (*Command) String added in v1.19.0

func (c *Command) String() string

String returns a representation of this Command as a string.

type CommandBuilder added in v1.19.0

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

CommandBuilder is a builder for Command objects.

func NewCommandBuilder added in v1.19.0

func NewCommandBuilder(name string) *CommandBuilder

NewCommandBuilder creates and returns a new CommandBuilder with the given name.

func (*CommandBuilder) Args added in v1.19.0

func (c *CommandBuilder) Args(args ...string) *CommandBuilder

Args appends the given arguments to this CommandBuilder.

func (*CommandBuilder) Command added in v1.19.0

func (c *CommandBuilder) Command() *Command

Command returns the Command that has been built by this CommandBuilder.

func (*CommandBuilder) Flags added in v1.19.0

func (c *CommandBuilder) Flags(flags ...Flag) *CommandBuilder

Flags appends the given flags to this CommandBuilder.

type Flag added in v1.19.0

type Flag interface {
	// Slice returns a representation of this Flag as a slice of strings.
	Slice() []string
}

Flag is a flag that can be represented as a slice of strings.

func BoolFlag added in v1.19.0

func BoolFlag(key string, value bool) Flag

BoolFlag returns a Flag with the given key and boolean value.

func IntFlag added in v1.19.0

func IntFlag(key string, value int) Flag

IntFlag returns a Flag with the given key and integer value.

func StringFlag added in v1.19.0

func StringFlag(key, value string) Flag

StringFlag returns a Flag with the given key and string value.

func StringSliceFlag added in v1.19.0

func StringSliceFlag(key string, value ...string) Flag

StringSliceFlag returns a flag with the given key and string slice value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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