testfiles

package
v1.13.1-beta.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package testfiles provides a wrapper around various optional ways of retrieving additional files needed during a test run: - builtin bindata - filesystem access

Because it is a is self-contained package, it can be used by test/e2e/framework and test/e2e/manifest without creating a circular dependency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFileSource

func AddFileSource(filesource FileSource)

AddFileSource registers another provider for files that may be needed at runtime. Should be called during initialization of a test binary.

func Exists

func Exists(filePath string, fail Fail) bool

Exists checks whether a file could be read. Unexpected errors are handled by calling the fail function, which then should abort the current test.

func Read

func Read(filePath string) ([]byte, error)

Read tries to retrieve the desired file content from one of the registered file sources.

func ReadOrDie

func ReadOrDie(filePath string, fail Fail) []byte

ReadOrDie tries to retrieve the desired file content from one of the registered file sources. In contrast to FileSource, it will either return a valid slice or abort the test by calling the fatal function, i.e. the caller doesn't have to implement error checking.

Types

type BindataFileSource

type BindataFileSource struct {
	Asset      func(string) ([]byte, error)
	AssetNames func() []string
}

BindataFileSource handles files stored in a package generated with bindata.

func (BindataFileSource) DescribeFiles

func (b BindataFileSource) DescribeFiles() string

DescribeFiles explains about gobindata and then lists all available files.

func (BindataFileSource) ReadTestFile

func (b BindataFileSource) ReadTestFile(filePath string) ([]byte, error)

ReadTestFile looks for an asset with the given path.

type Fail

type Fail func(failure string, callerSkip ...int)

Fail is an error handler function with the same prototype and semantic as ginkgo.Fail. Typically ginkgo.Fail is what callers of ReadOrDie and Exists will pass. This way this package avoids depending on Ginkgo.

type FileSource

type FileSource interface {
	// ReadTestFile retrieves the content of a file that gets maintained
	// alongside a test's source code. Files are identified by the
	// relative path inside the repository containing the tests, for
	// example "cluster/gce/upgrade.sh" inside kubernetes/kubernetes.
	//
	// When the file is not found, a nil slice is returned. An error is
	// returned for all fatal errors.
	ReadTestFile(filePath string) ([]byte, error)

	// DescribeFiles returns a multi-line description of which
	// files are available via this source. It is meant to be
	// used as part of the error message when a file cannot be
	// found.
	DescribeFiles() string
}

FileSource implements one way of retrieving test file content. For example, one file source could read from the original source code file tree, another from bindata compiled into a test executable.

type RootFileSource

type RootFileSource struct {
	Root string
}

RootFileSource looks for files relative to a root directory.

func (RootFileSource) DescribeFiles

func (r RootFileSource) DescribeFiles() string

DescribeFiles explains that it looks for files inside a certain root directory.

func (RootFileSource) ReadTestFile

func (r RootFileSource) ReadTestFile(filePath string) ([]byte, error)

ReadTestFile looks for the file relative to the configured root directory.

Jump to

Keyboard shortcuts

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