testtools

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckFiles

func CheckFiles(t *testing.T, dir string, files []FileSpec)

CheckFiles checks that files in "dir" exist and have the content specified in "files". Files not listed in "files" are not tested, so extra files are allowed.

func CreateFiles

func CreateFiles(t *testing.T, files []FileSpec) (dir string, cleanup func())

CreateFiles creates a directory of test files. This is a more compact alternative to testdata directories. CreateFiles returns a canonical path to the directory and a function to call to clean up the directory after the test.

func NewTestConfig

func NewTestConfig(t *testing.T, cexts []config.Configurer, langs []language.Language, args []string) *config.Config

NewTestConfig returns a Config used for tests in any language extension. cexts is a list of configuration extensions to use. langs is a list of language extensions to use (languages are also configuration extensions, but it may be convenient to keep them separate). args is a list of command line arguments to apply. NewTestConfig calls t.Fatal if any error is encountered while processing flags.

func TestGazelleGenerationOnPath added in v0.25.0

func TestGazelleGenerationOnPath(t *testing.T, args *TestGazelleGenerationArgs)

TestGazelleGenerationOnPath runs a full gazelle binary on a testdata directory. With a test data directory of the form: └── <testDataPath>

└── some_test
    ├── WORKSPACE
    ├── README.md --> README describing what the test does.
    ├── arguments.txt --> newline delimited list of arguments to pass in (ignored if empty).
    ├── expectedStdout.txt --> Expected stdout for this test.
    ├── expectedStderr.txt --> Expected stderr for this test.
    ├── expectedExitCode.txt --> Expected exit code for this test.
    └── app
        └── sourceFile.foo
        └── BUILD.in --> BUILD file prior to running gazelle.
        └── BUILD.out --> BUILD file expected after running gazelle.

Types

type FileSpec

type FileSpec struct {
	// Path is a slash-separated path relative to the test directory. If Path
	// ends with a slash, it indicates a directory should be created
	// instead of a file.
	Path string

	// Symlink is a slash-separated path relative to the test directory. If set,
	// it indicates a symbolic link should be created with this path instead of a
	// file.
	Symlink string

	// Content is the content of the test file.
	Content string

	// NotExist asserts that no file at this path exists.
	// It is only valid in CheckFiles.
	NotExist bool
}

FileSpec specifies the content of a test file.

type TestGazelleGenerationArgs added in v0.25.0

type TestGazelleGenerationArgs struct {
	// Name is the name of the test.
	Name string
	// TestDataPathAbsolute is the absolute path to the test data directory.
	// For example, /home/user/workspace/path/to/test_data/my_testcase.
	TestDataPathAbsolute string
	// TestDataPathRealtive is the workspace relative path to the test data directory.
	// For example, path/to/test_data/my_testcase.
	TestDataPathRelative string
	// GazelleBinaryPath is the workspace relative path to the location of the gazelle binary
	// we want to test.
	GazelleBinaryPath string

	// BuildInSuffix is the suffix for all test input build files. Includes the ".".
	// Default: ".in", so input BUILD files should be named BUILD.in.
	BuildInSuffix string

	// BuildOutSuffix is the suffix for all test output build files. Includes the ".".
	// Default: ".out", so out BUILD files should be named BUILD.out.
	BuildOutSuffix string

	// Timeout is the duration after which the generation process will be killed.
	Timeout time.Duration
}

Jump to

Keyboard shortcuts

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