testutil

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs added in v1.3.0

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

func CheckContains added in v0.25.0

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

func CheckDeepEqual added in v0.14.0

func CheckDeepEqual(t *testing.T, expected, actual interface{}, opts ...cmp.Option)

func CheckError

func CheckError(t *testing.T, shouldErr bool, err error)

func CheckErrorAndDeepEqual

func CheckErrorAndDeepEqual(t *testing.T, shouldErr bool, err error, expected, actual interface{}, opts ...cmp.Option)

func CreateFakeImageTar added in v0.41.0

func CreateFakeImageTar(ref string, path string) error

TODO(dgageot): create something that looks more like an actual tar file.

func EnsureTestPanicked added in v0.31.0

func EnsureTestPanicked(t *testing.T)

func ReadRefFromFakeTar added in v0.41.0

func ReadRefFromFakeTar(input io.Reader) (string, error)

func Run added in v0.31.0

func Run(t *testing.T, name string, f func(t *T))

func ServeFile added in v0.2.0

func ServeFile(t *testing.T, content []byte) string

ServeFile serves a file with http. Returns the url to the file and a teardown function that should be called to properly stop the server.

func SetupFakeWatcher added in v0.33.0

func SetupFakeWatcher(w watch.Interface) func(a fake_testing.Action) (handled bool, ret watch.Interface, err error)

SetupFakeWatcher helps set up a fake Kubernetes watcher

func TempFile added in v0.2.0

func TempFile(t *testing.T, prefix string, content []byte) string

TempFile creates a temporary file with a given content. Returns the file name and a teardown function that should be called to properly delete the file.

Types

type ContainerState added in v1.0.0

type ContainerState int
const (
	Created ContainerState = 0
	Started ContainerState = 1
)

type FakeAPIClient added in v0.21.0

type FakeAPIClient struct {
	client.CommonAPIClient

	ErrImageBuild   bool
	ErrImageInspect bool
	ErrImagePush    bool
	ErrImagePull    bool
	ErrStream       bool
	ErrVersion      bool

	Pushed map[string]string
	Pulled []string
	Built  []types.ImageBuildOptions
	// contains filtered or unexported fields
}

func (*FakeAPIClient) Add added in v0.35.0

func (f *FakeAPIClient) Add(tag, imageID string) *FakeAPIClient

func (*FakeAPIClient) Close added in v0.21.0

func (f *FakeAPIClient) Close() error

func (*FakeAPIClient) DistributionInspect added in v0.40.0

func (f *FakeAPIClient) DistributionInspect(ctx context.Context, ref, encodedRegistryAuth string) (registry.DistributionInspect, error)

func (*FakeAPIClient) ImageBuild added in v0.21.0

func (*FakeAPIClient) ImageInspectWithRaw added in v0.21.0

func (f *FakeAPIClient) ImageInspectWithRaw(_ context.Context, ref string) (types.ImageInspect, []byte, error)

func (*FakeAPIClient) ImageLoad added in v0.41.0

func (f *FakeAPIClient) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)

func (*FakeAPIClient) ImagePull added in v0.21.1

func (*FakeAPIClient) ImagePush added in v0.21.0

func (*FakeAPIClient) ImageTag added in v0.21.0

func (f *FakeAPIClient) ImageTag(_ context.Context, image, ref string) error

func (*FakeAPIClient) Info added in v0.21.0

func (*FakeAPIClient) ServerVersion added in v1.7.1

func (f *FakeAPIClient) ServerVersion(ctx context.Context) (types.Version, error)

type FakeCmd added in v0.6.0

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

func CmdRun added in v0.38.0

func CmdRun(command string) *FakeCmd

func CmdRunEnv added in v0.38.0

func CmdRunEnv(command string, env []string) *FakeCmd

func CmdRunErr added in v0.38.0

func CmdRunErr(command string, err error) *FakeCmd

func CmdRunInput added in v0.38.0

func CmdRunInput(command, input string) *FakeCmd

func CmdRunOut added in v0.38.0

func CmdRunOut(command string, output string) *FakeCmd

func CmdRunOutErr added in v0.38.0

func CmdRunOutErr(command string, output string, err error) *FakeCmd

func CmdRunWithOutput added in v1.5.0

func CmdRunWithOutput(command, output string) *FakeCmd

CmdRunWithOutput programs the fake runner with a command and expected output

func (*FakeCmd) AndRun added in v0.38.0

func (c *FakeCmd) AndRun(command string) *FakeCmd

func (*FakeCmd) AndRunEnv added in v0.38.0

func (c *FakeCmd) AndRunEnv(command string, env []string) *FakeCmd

func (*FakeCmd) AndRunErr added in v0.38.0

func (c *FakeCmd) AndRunErr(command string, err error) *FakeCmd

func (*FakeCmd) AndRunInput added in v0.38.0

func (c *FakeCmd) AndRunInput(command, input string) *FakeCmd

func (*FakeCmd) AndRunInputOut added in v1.7.1

func (c *FakeCmd) AndRunInputOut(command string, input string, output string) *FakeCmd

func (*FakeCmd) AndRunOut added in v0.38.0

func (c *FakeCmd) AndRunOut(command string, output string) *FakeCmd

func (*FakeCmd) AndRunOutErr added in v0.38.0

func (c *FakeCmd) AndRunOutErr(command string, output string, err error) *FakeCmd

func (*FakeCmd) AndRunWithOutput added in v1.5.0

func (c *FakeCmd) AndRunWithOutput(command, output string) *FakeCmd

AndRunWithOutput takes a command and an expected output. It expected to match up with a call to RunCmd, and pipes the provided output to RunCmd's exec.Cmd's stdout.

func (*FakeCmd) ForTest added in v0.38.0

func (c *FakeCmd) ForTest(t *testing.T)

func (*FakeCmd) RunCmd added in v0.6.0

func (c *FakeCmd) RunCmd(cmd *exec.Cmd) error

func (*FakeCmd) RunCmdOut added in v0.6.0

func (c *FakeCmd) RunCmdOut(cmd *exec.Cmd) ([]byte, error)

type ForTester added in v0.38.0

type ForTester interface {
	ForTest(t *testing.T)
}

type T added in v0.31.0

type T struct {
	*testing.T
}

func (*T) Chdir added in v0.31.0

func (t *T) Chdir(dir string)

func (*T) CheckContains added in v0.31.0

func (t *T) CheckContains(expected, actual string)

func (*T) CheckDeepEqual added in v0.31.0

func (t *T) CheckDeepEqual(expected, actual interface{}, opts ...cmp.Option)

func (*T) CheckEmpty added in v1.1.0

func (t *T) CheckEmpty(actual interface{})

func (*T) CheckError added in v0.31.0

func (t *T) CheckError(shouldErr bool, err error)

func (*T) CheckErrorAndDeepEqual added in v0.31.0

func (t *T) CheckErrorAndDeepEqual(shouldErr bool, err error, expected, actual interface{}, opts ...cmp.Option)

func (*T) CheckErrorContains added in v0.31.0

func (t *T) CheckErrorContains(message string, err error)

CheckErrorContains checks that an error is not nil and contains a given message.

func (*T) CheckFalse added in v1.1.0

func (t *T) CheckFalse(actual bool)

func (*T) CheckMatches added in v0.37.0

func (t *T) CheckMatches(pattern, actual string)

func (*T) CheckNil added in v1.1.0

func (t *T) CheckNil(actual interface{})

func (*T) CheckNoError added in v0.31.0

func (t *T) CheckNoError(err error)

func (*T) CheckNotNil added in v1.1.0

func (t *T) CheckNotNil(actual interface{})

func (*T) CheckTrue added in v1.1.0

func (t *T) CheckTrue(actual bool)

func (*T) CheckTypeEquality added in v1.7.1

func (t *T) CheckTypeEquality(expected, actual interface{})

func (*T) NewTempDir added in v0.31.0

func (t *T) NewTempDir() *TempDir

func (*T) Override added in v0.31.0

func (t *T) Override(dest, tmp interface{})

func (*T) RequireNoError added in v0.40.0

func (t *T) RequireNoError(err error)

func (*T) SetArgs added in v1.3.0

func (t *T) SetArgs(args []string)

SetArgs override os.Args for the duration of a test.

func (*T) SetEnvs added in v0.31.0

func (t *T) SetEnvs(envs map[string]string)

SetEnvs takes a map of key values to set using os.Setenv and returns a function that can be called to reset the envs to their previous values.

func (*T) SetStdin added in v1.1.0

func (t *T) SetStdin(content []byte)

SetStdin replaces os.Stdin with a given content.

func (*T) SetupFakeKubernetesContext added in v0.31.0

func (t *T) SetupFakeKubernetesContext(config api.Config)

SetupFakeKubernetesContext replaces the current Kubernetes configuration file to setup a fixed current context.

func (*T) TempFile added in v0.31.0

func (t *T) TempFile(prefix string, content []byte) string

type TempDir added in v0.3.0

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

TempDir offers actions on a temp directory.

func NewTempDir added in v0.12.0

func NewTempDir(t *testing.T) *TempDir

NewTempDir creates a temporary directory and a teardown function that should be called to properly delete the directory content.

func (*TempDir) Chdir added in v0.32.0

func (h *TempDir) Chdir() *TempDir

Chdir changes current directory to this temp directory.

func (*TempDir) Chtimes added in v0.12.0

func (h *TempDir) Chtimes(file string, t time.Time) *TempDir

Chtimes changes the times for a file in the temp directory.

func (*TempDir) List added in v0.12.0

func (h *TempDir) List() ([]string, error)

List lists all the files in the temp directory.

func (*TempDir) Mkdir added in v0.12.0

func (h *TempDir) Mkdir(dir string) *TempDir

Mkdir makes a sub-directory in the temp directory.

func (*TempDir) Path added in v0.12.0

func (h *TempDir) Path(file string) string

Path returns the path to a file in the temp directory.

func (*TempDir) Paths added in v0.26.0

func (h *TempDir) Paths(files ...string) []string

Paths returns the paths to a list of files in the temp directory.

func (*TempDir) Remove added in v0.12.0

func (h *TempDir) Remove(file string) *TempDir

Remove deletes a file from the temp directory.

func (*TempDir) Rename added in v0.25.0

func (h *TempDir) Rename(oldName, newName string) *TempDir

Rename renames a file from oldname to newname

func (*TempDir) Root added in v0.12.0

func (h *TempDir) Root() string

Root returns the temp directory.

func (h *TempDir) Symlink(dst, src string) *TempDir

Symlink creates a symlink.

func (*TempDir) Touch added in v0.33.0

func (h *TempDir) Touch(files ...string) *TempDir

Touch creates a list of empty files in the temp directory.

func (*TempDir) Write added in v0.12.0

func (h *TempDir) Write(file, content string) *TempDir

Write write content to a file in the temp directory.

func (*TempDir) WriteFiles added in v0.33.0

func (h *TempDir) WriteFiles(files map[string]string) *TempDir

WriteFiles write a list of files (path->content) in the temp directory.

Jump to

Keyboard shortcuts

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