test

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2017 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProjectRoot string = "src/github.com/golang/notexist"
)

Variables

View Source
var (
	ExeSuffix string // ".exe" on Windows

	PrintLogs *bool = flag.Bool("logs", false, "log stdin/stdout of test commands")
)
View Source
var (
	UpdateGolden *bool = flag.Bool("update", false, "update golden files")
)

Functions

func NeedsExternalNetwork

func NeedsExternalNetwork(t *testing.T)

NeedsExternalNetwork makes sure the tests needing external network will not be run when executing tests in short mode.

func NeedsGit

func NeedsGit(t *testing.T)

NeedsGit will make sure the tests that require git will be skipped if the git binary is not available.

Types

type Helper

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

Helper with utilities for testing.

func NewHelper

func NewHelper(t *testing.T) *Helper

NewHelper initializes a new helper for testing.

func (*Helper) Cd

func (h *Helper) Cd(dir string)

Cd changes the current directory to the named directory. Note that using this means that the test must not be run in parallel with any other tests.

func (*Helper) Cleanup

func (h *Helper) Cleanup()

Cleanup cleans up a test that runs testgo.

func (*Helper) DoRun

func (h *Helper) DoRun(args []string) error

DoRun runs the test go command, recording stdout and stderr and returning exit status.

func (*Helper) Exist

func (h *Helper) Exist(path string) bool

Exist returns whether or not a path exists

func (*Helper) GetCommit

func (h *Helper) GetCommit(repo string) string

func (*Helper) GetFile

func (h *Helper) GetFile(path string) io.ReadCloser

GetTestFile reads a file into memory

func (*Helper) GetTestFile

func (h *Helper) GetTestFile(src string) io.ReadCloser

GetTestFile reads a file from the testdata directory into memory. src is relative to ./testdata.

func (*Helper) GetTestFileString

func (h *Helper) GetTestFileString(src string) string

GetTestFileString reads a file from the testdata directory into memory. src is relative to ./testdata.

func (*Helper) Must

func (h *Helper) Must(err error)

Must gives a fatal error if err is not nil.

func (*Helper) MustExist

func (h *Helper) MustExist(path string)

MustExist fails if path does not exist.

func (*Helper) MustNotExist

func (h *Helper) MustNotExist(path string)

MustNotExist fails if path exists.

func (*Helper) Parallel

func (h *Helper) Parallel()

Parallel runs the test in parallel by calling t.Parallel.

func (*Helper) Path

func (h *Helper) Path(name string) string

Path returns the absolute pathname to file with the temporary directory.

func (*Helper) ReadLock

func (h *Helper) ReadLock() string

ReadLock returns the lock in the current directory.

func (*Helper) ReadManifest

func (h *Helper) ReadManifest() string

ReadManifest returns the manifest in the current directory.

func (*Helper) Run

func (h *Helper) Run(args ...string)

run runs the test go command, and expects it to succeed.

func (*Helper) RunGit

func (h *Helper) RunGit(dir string, args ...string)

RunGit runs a git command, and expects it to succeed.

func (*Helper) RunGo

func (h *Helper) RunGo(args ...string)

RunGo runs a go command, and expects it to succeed.

func (*Helper) Setenv

func (h *Helper) Setenv(name, val string)

Setenv sets an environment variable to use when running the test go command.

func (*Helper) ShouldExist

func (h *Helper) ShouldExist(path string) error

ShouldExist returns an error if path does not exist.

func (*Helper) ShouldNotExist

func (h *Helper) ShouldNotExist(path string) error

ShouldNotExist returns an error if path exists.

func (*Helper) TempCopy

func (h *Helper) TempCopy(dest, src string)

TempCopy copies a temporary file from testdata into the temporary directory. dest is relative to the temp directory location, and src is relative to ./testdata.

func (*Helper) TempDir

func (h *Helper) TempDir(path string)

TempDir adds a temporary directory for a run of testgo.

func (*Helper) TempFile

func (h *Helper) TempFile(path, contents string)

TempFile adds a temporary file for a run of testgo.

func (*Helper) WriteTestFile

func (h *Helper) WriteTestFile(src string, content string) error

WriteTestFile writes a file to the testdata directory from memory. src is relative to ./testdata.

type IntegrationTestCase

type IntegrationTestCase struct {
	Commands      [][]string        `json:"commands"`
	ErrorExpected string            `json:"error-expected"`
	GopathInitial map[string]string `json:"gopath-initial"`
	VendorInitial map[string]string `json:"vendor-initial"`
	VendorFinal   []string          `json:"vendor-final"`
	InitPath      string            `json:"init-path"`
	// contains filtered or unexported fields
}

IntegrationTestCase manages a test case directory structure and content

func NewTestCase

func NewTestCase(t *testing.T, dir, name string) *IntegrationTestCase

NewTestCase creates a new IntegrationTestCase.

func (*IntegrationTestCase) CompareError

func (tc *IntegrationTestCase) CompareError(err error, stderr string)

CompareError compares exected and actual error

func (*IntegrationTestCase) CompareFile

func (tc *IntegrationTestCase) CompareFile(goldenPath, working string)

CompareFile compares the golden file with the working result.

func (*IntegrationTestCase) CompareOutput

func (tc *IntegrationTestCase) CompareOutput(stdout string)

CompareError compares expected and actual stdout output

func (*IntegrationTestCase) CompareVendorPaths

func (tc *IntegrationTestCase) CompareVendorPaths(gotVendorPaths []string)

func (*IntegrationTestCase) InitialPath

func (tc *IntegrationTestCase) InitialPath() string

func (*IntegrationTestCase) UpdateFile added in v0.2.0

func (tc *IntegrationTestCase) UpdateFile(goldenPath, workingPath string)

UpdateFile updates the golden file with the working result.

func (*IntegrationTestCase) WriteFile

func (tc *IntegrationTestCase) WriteFile(src string, content string) error

type IntegrationTestProject

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

IntegrationTestProject manages the "virtual" test project directory structure and content

func NewTestProject

func NewTestProject(t *testing.T, initPath, wd string, externalProc bool, run RunFunc) *IntegrationTestProject

func (*IntegrationTestProject) Cleanup

func (p *IntegrationTestProject) Cleanup()

func (*IntegrationTestProject) CompareImportPaths

func (p *IntegrationTestProject) CompareImportPaths()

Compare import paths before and after commands

func (*IntegrationTestProject) CopyTree

func (p *IntegrationTestProject) CopyTree(src string)

func (*IntegrationTestProject) DoRun

func (p *IntegrationTestProject) DoRun(args []string) error

func (*IntegrationTestProject) GetImportPaths

func (p *IntegrationTestProject) GetImportPaths() []string

Collect final vendor paths at a depth of three levels

func (*IntegrationTestProject) GetStderr

func (p *IntegrationTestProject) GetStderr() string

GetStderr gets the Stderr output from test run

func (*IntegrationTestProject) GetStdout

func (p *IntegrationTestProject) GetStdout() string

GetStdout gets the Stdout output from test run

func (*IntegrationTestProject) GetVendorGit

func (p *IntegrationTestProject) GetVendorGit(ip string)

func (*IntegrationTestProject) GetVendorPaths

func (p *IntegrationTestProject) GetVendorPaths() []string

Collect final vendor paths at a depth of three levels

func (*IntegrationTestProject) Must

func (p *IntegrationTestProject) Must(err error)

Must gives a fatal error if err is not nil.

func (*IntegrationTestProject) Path

func (p *IntegrationTestProject) Path(args ...string) string

func (*IntegrationTestProject) ProjPath

func (p *IntegrationTestProject) ProjPath(args ...string) string

func (*IntegrationTestProject) RecordImportPaths

func (p *IntegrationTestProject) RecordImportPaths()

Take a snapshot of the import paths before test is run

func (*IntegrationTestProject) RunGit

func (p *IntegrationTestProject) RunGit(dir string, args ...string)

func (*IntegrationTestProject) RunGo

func (p *IntegrationTestProject) RunGo(args ...string)

func (*IntegrationTestProject) Setenv

func (p *IntegrationTestProject) Setenv(name, val string)

Setenv sets an environment variable to use when running the test go command.

func (*IntegrationTestProject) TempDir

func (p *IntegrationTestProject) TempDir(args ...string)

func (*IntegrationTestProject) TempProjDir

func (p *IntegrationTestProject) TempProjDir(args ...string)

func (*IntegrationTestProject) VendorPath

func (p *IntegrationTestProject) VendorPath(args ...string) string

type RunFunc

type RunFunc func(prog string, newargs []string, outW, errW io.Writer, dir string, env []string) error

Jump to

Keyboard shortcuts

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