Documentation
¶
Overview ¶
Package testing provides support for automated testing for import plugins.
Index ¶
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func Clean()
- func ImportPath(dir string) (string, error)
- func MustAsset(name string) []byte
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- func TestImport(t testing.T, c TestImportCase)
- type TestImportCase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/
foo.txt
img/
a.png
b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func Clean ¶
func Clean()
Clean cleans any temporary files created. This should always be called at the end of any set of import tests.
func ImportPath ¶
ImportPath attempts to infer the import path based on the GOPATH environment variable and the directory.
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
func TestImport ¶
func TestImport(t testing.T, c TestImportCase)
TestImport tests that a sdk.Import implementation works as expected.
Types ¶
type TestImportCase ¶
type TestImportCase struct {
// Source is a policy to execute. This should be a full program ending
// in `main = ` and an assignment. For example `main = subject.foo`.
Source string
// This is the configuration that will be sent to the plugin. This
// must serialize to JSON since the JSON will be used to pass the
// configuration.
Config map[string]interface{}
// This is extra data to inject into the global scope of the policy
// execution
Global map[string]interface{}
// Mock is mocked import data
Mock map[string]map[string]interface{}
// ImportPath is the path to a Go package on your GOPATH containing
// the import to test. If this is blank, the test case uses heuristics
// to extract the GOPATH and use the current package for testing.
// This package is expected to expose a "New" function which adheres to
// the sdk/rpc.ImportFunc signature.
//
// This should usually be blank. This maximizes portability of the
// import if it were to be forked or moved.
//
// For a given import path, the test binary will be built exactly once
// per test run.
ImportPath string
}
TestImportCase is a single test case for configuring TestImport.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package testimport contains a test import that the testing package uses for unit tests.
|
Package testimport contains a test import that the testing package uses for unit tests. |