Documentation
¶
Overview ¶
Package testcontrol is the control of a pull request's Go tests, a step of the scenario control (.circleci/scenario-control.sh, docs/scenarios.md): the Test functions the pull request adds or changes in any _test.go run against its merge base's code with its test files applied, and at least one of them must fail there and pass on the pull request's own code. A fix whose regression test passes without the fix shows nothing; only the pull request's reasoning would support it.
Index ¶
Constants ¶
const ( // ChangeAdded is a test its package on the base does not have. ChangeAdded = "added" // ChangeChanged is a test whose code differs from the base's: its // doc comment, comments and blank lines do not count. ChangeChanged = "changed" // ChangeMoved is a test the pull request moves unchanged from another // package: it shows nothing new, so the control does not run it. ChangeMoved = "moved" )
How a test of the pull request stands to the merge base.
const ( SkipNoCode = "the pull request changes only tests: the merge base with its test files is its own tree" SkipOptedOut = "opted out" SkipNewPackage = "new package: the base has none of its code" SkipTags = "builds only with tags or on a platform CI does not test with" )
Why the control does not run a test of the pull request.
const ( // BaseEnv names a checkout of the pull request's merge base that the // control may change: it applies the pull request's test files there. BaseEnv = "BEEKEEPER_TEST_CONTROL_BASE" // HeadEnv names the pull request's checkout; without it, the // repository this package is in. HeadEnv = "BEEKEEPER_TEST_CONTROL_HEAD" // ReportEnv names a directory for report.txt, report.json and every // go test run's events, command and stderr. ReportEnv = "BEEKEEPER_TEST_CONTROL_REPORT" )
The environment of TestGoTestControl, which .circleci/scenario-control.sh sets.
const ( Fails = "fails" Passes = "passes" Skipped = "is skipped" NoBuild = "does not build" // Crashed is a package whose test binary fails before the test runs: // its TestMain or an init. Crashed = "fails before it runs" NotRun = "does not run" )
A test's run on a tree.
const DefaultTimeout = 3 * time.Minute
DefaultTimeout is go test's -timeout for each run: a test that hangs on the base fails there once it passes.
Variables ¶
var AllowedTags = []string{"scenario", "integration", "perf"}
AllowedTags are the build tags CI runs Go tests with: the scenarios', the loop workflow's and the performance suite's. A test that builds only with another tag (a live test) or on another platform is reported, not run.
Functions ¶
func Apply ¶
func Apply(overlay []FileChange, head, base string) error
Apply applies the pull request's test files and test data to the base: what it adds or modifies is copied from head, what it deletes is removed.
Types ¶
type Case ¶
type Case struct {
Name string `json:"name"`
File string `json:"file"`
Dir string `json:"dir"`
Change string `json:"change"`
// Tags are the build tags it runs with.
Tags []string `json:"tags,omitempty"`
// Skip says why the control does not run it; Reason is an opt-out's,
// Note explains a run.
Skip string `json:"skip,omitempty"`
Reason string `json:"reason,omitempty"`
Note string `json:"note,omitempty"`
// Base is its run on the merge base; Head, for one that fails there,
// its run on the pull request's code.
Base string `json:"base,omitempty"`
Head string `json:"head,omitempty"`
// Detail is the run's first failures or its build errors.
Detail string `json:"detail,omitempty"`
}
Case is one Test function the pull request adds or changes.
type FileChange ¶
type FileChange struct {
Status byte
// Path is a slash path relative to the tree's root.
Path string
}
FileChange is a file the pull request adds (A), modifies (M) or deletes (D); a change of its type is a modification.
func Diff ¶
func Diff(ctx context.Context, repo, base, head string) ([]FileChange, error)
Diff lists the files that differ between the commits base and head of the repository at repo.
func (FileChange) String ¶
func (c FileChange) String() string
type Options ¶
type Options struct {
// Head is the pull request's checkout, Base its merge base's, which
// the control changes.
Head, Base string
// Logs, when set, receives every go test run's events, command and
// stderr.
Logs string
// Timeout is go test's -timeout for each run; DefaultTimeout without.
Timeout time.Duration
}
Options are a control's trees.
type Plan ¶
type Plan struct {
// CodeChanged says whether the pull request changes anything beyond its
// test files and test data.
CodeChanged bool
// Overlay are the test files and test data the pull request changes,
// the ones the control applies to the base.
Overlay []FileChange
// Cases are the tests it adds, changes or moves, in file order.
Cases []*Case
// Problems are control lines the control cannot read.
Problems []string
}
Plan is the control of one pull request.
func PlanControl ¶
func PlanControl(changes []FileChange, head, base string) (*Plan, error)
PlanControl plans the control of the pull request whose files changes lists: head is its tree, base the merge base's, before the control applies the pull request's test files to it.
A test of the pull request is the base's of the same file and name, or else of the same directory and name; one that is the base's unchanged is no case. An opt-out holds for the change that writes it: a test whose control line is the base's runs when its code changes.
type Report ¶
type Report struct {
// Base and Head are the commits.
Base string `json:"base"`
Head string `json:"head"`
CodeChanged bool `json:"code_changed"`
Applied []string `json:"applied,omitempty"`
Cases []*Case `json:"cases"`
Problems []string `json:"problems,omitempty"`
OK bool `json:"ok"`
Summary string `json:"summary"`
}
Report is the control of one pull request.
type Test ¶
type Test struct {
// Name is the function's name; File is its file and Dir its package's
// directory, slash paths relative to the tree's root ("." for the
// root).
Name, File, Dir string
// Code is the declaration without its doc comment, its comments and
// its blank lines: two tests with the same Code test the same.
Code string
// Control is the doc comment's paragraph that starts with "control:",
// on one line; "" without one.
Control string
}
Test is a top-level Test function of a _test.go file.