Documentation ¶
Overview ¶
Package test provides the infrastructure for the end-to-end tests. End-to-end tests are written in Cucumber for Go (https://github.com/cucumber/godog). The main file running the tests is main_test.go. Each test scenario gets a fully working local Git repository. A good starting point for learning how the end-to-end test framework provisions these repository is GitManager.
Package envvars provides helper functions to work with lists of environment variables as provided by `os.Environ`.
Index ¶
- func CallScriptArgs(toolPath string) (cmd string, args []string)
- func CopyDirectory(src, dst string) error
- func CreateInputTool(toolPath string) error
- func CreateLsTool(toolPath string) error
- func DefaultCommit(filenameSuffix string) git.Commit
- func FromGherkinTable(table *messages.PickleStepArgument_PickleTable) ([]git.Commit, error)
- func PrependEnvPath(envVars []string, directory string) []string
- func RenderTable(table *messages.PickleStepArgument_PickleTable) string
- func ReplaceEnvVar(envVars []string, key string, value string) []string
- func ScriptName(command string) string
- func Steps(suite *godog.Suite, state *ScenarioState)
- type CommitTableBuilder
- type DataTable
- func (table *DataTable) AddRow(elements ...string)
- func (table *DataTable) EqualDataTable(other DataTable) (diff string, errorCount int)
- func (table *DataTable) EqualGherkin(other *messages.PickleStepArgument_PickleTable) (diff string, errorCount int)
- func (table *DataTable) Expand(localRepo *Runner, remoteRepo *Runner) (DataTable, error)
- func (table *DataTable) RemoveText(text string)
- func (table *DataTable) Sort()
- func (table *DataTable) String() string
- type ExecutedGitCommand
- type GitEnvironment
- func (env *GitEnvironment) AddCoworkerRepo() error
- func (env *GitEnvironment) AddSubmoduleRepo() error
- func (env *GitEnvironment) AddUpstream() error
- func (env *GitEnvironment) Branches() (DataTable, error)
- func (env GitEnvironment) CommitTable(fields []string) (DataTable, error)
- func (env *GitEnvironment) CreateCommits(commits []git.Commit) error
- func (env GitEnvironment) CreateOriginBranch(name, parent string) error
- func (env GitEnvironment) CreateTags(table *messages.PickleStepArgument_PickleTable) error
- func (env GitEnvironment) Remove() error
- func (env GitEnvironment) TagTable() (DataTable, error)
- type GitManager
- type MockingRunner
- func (r *MockingRunner) MockBrokenCommand(name string) error
- func (r *MockingRunner) MockCommand(name string) error
- func (r *MockingRunner) MockCommitMessage(message string) error
- func (r *MockingRunner) MockGit(version string) error
- func (r *MockingRunner) MockNoCommandsInstalled() error
- func (r *MockingRunner) Run(name string, arguments ...string) (string, error)
- func (r *MockingRunner) RunMany(commands [][]string) error
- func (r *MockingRunner) RunString(fullCmd string) (string, error)
- func (r *MockingRunner) RunStringWith(fullCmd string, opts *Options) (string, error)
- func (r *MockingRunner) RunWith(opts *Options, cmd string, args ...string) (string, error)
- func (r *MockingRunner) SetTestOrigin(content string)
- func (r *MockingRunner) WorkingDir() string
- type Options
- type Runner
- func (r *Runner) AddRemote(name, url string) error
- func (r *Runner) AddSubmodule(url string) error
- func (r *Runner) BranchHierarchyTable() DataTable
- func (r *Runner) CheckoutBranch(name string) error
- func (r *Runner) Clone(targetDir string) (Runner, error)
- func (r *Runner) CommitStagedChanges(message string) error
- func (r *Runner) Commits(fields []string, mainBranch string) ([]git.Commit, error)
- func (r *Runner) CommitsInBranch(branch string, fields []string) ([]git.Commit, error)
- func (r *Runner) ConnectTrackingBranch(name string) error
- func (r *Runner) CreateBranch(name, parent string) error
- func (r *Runner) CreateChildFeatureBranch(name string, parent string) error
- func (r *Runner) CreateCommit(commit git.Commit) error
- func (r *Runner) CreateFile(name, content string) error
- func (r *Runner) CreatePerennialBranches(names ...string) error
- func (r *Runner) CreateStandaloneTag(name string) error
- func (r *Runner) CreateTag(name string) error
- func (r *Runner) DeleteMainBranchConfiguration() error
- func (r *Runner) Fetch() error
- func (r *Runner) FileContent(filename string) (string, error)
- func (r *Runner) FileContentInCommit(sha string, filename string) (string, error)
- func (r *Runner) FilesInBranch(branch string) ([]string, error)
- func (r *Runner) FilesInBranches(mainBranch string) (DataTable, error)
- func (r *Runner) FilesInCommit(sha string) ([]string, error)
- func (r *Runner) HasBranchesOutOfSync() (bool, error)
- func (r *Runner) HasFile(name, content string) (bool, error)
- func (r *Runner) HasGitTownConfigNow() bool
- func (r *Runner) PushBranch() error
- func (r *Runner) PushBranchToRemote(branch, remote string) error
- func (r *Runner) RemoveBranch(name string) error
- func (r *Runner) RemoveRemote(name string) error
- func (r *Runner) RemoveUnnecessaryFiles() error
- func (r *Runner) ShaForCommit(name string) (string, error)
- func (r *Runner) StageFiles(names ...string) error
- func (r *Runner) StashSize() (int, error)
- func (r *Runner) Tags() ([]string, error)
- func (r *Runner) UncommittedFiles() ([]string, error)
- type ScenarioState
- type TagTableBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallScriptArgs ¶
CallScriptArgs provides the command and arguments to call the given script on Windows.
func CopyDirectory ¶
CopyDirectory copies all files in the given src directory into the given dst directory. Both the source and the destination directory must exist.
func CreateInputTool ¶
CreateInputTool creates a tool that reads two inputs from STDIN and prints them back to the user.
func CreateLsTool ¶
CreateLsTool creates a tool in the given folder that lists all files in its current folder.
func DefaultCommit ¶
DefaultCommit provides a new Commit instance populated with the default values used in the absence of value specified by the test.
func FromGherkinTable ¶
FromGherkinTable provides a Commit collection representing the data in the given Gherkin table.
func PrependEnvPath ¶
PrependPath provides a new envvars with the given directory appended to the PATH entry of the given envvars. This function assumes there is only one PATH entry.
func RenderTable ¶
func RenderTable(table *messages.PickleStepArgument_PickleTable) string
RenderTable provides the textual Gherkin representation of the given Gherkin table.
func ReplaceEnvVar ¶
Replace provides a new envvars in which the entry with the given key contains the given value instead of its original value. If no entry with the given key exists, appends one at the end. This function assumes that keys are unique, i.e. no duplicate keys exist.
func ScriptName ¶
ScriptName provides the name of the given script file on the Windows.
func Steps ¶
func Steps(suite *godog.Suite, state *ScenarioState)
Steps defines Cucumber step implementations around Git workspace management.
Types ¶
type CommitTableBuilder ¶
type CommitTableBuilder struct {
// contains filtered or unexported fields
}
CommitTableBuilder collects data about commits in Git repositories in the same way that our Gherkin tables describing commits in repos are organized.
func NewCommitTableBuilder ¶
func NewCommitTableBuilder() CommitTableBuilder
NewCommitTableBuilder provides a fully initialized instance of CommitTableBuilder.
func (*CommitTableBuilder) Add ¶
func (builder *CommitTableBuilder) Add(commit git.Commit, location string)
Add registers the given commit from the given location into this table.
func (*CommitTableBuilder) AddMany ¶
func (builder *CommitTableBuilder) AddMany(commits []git.Commit, location string)
AddMany registers the given commits from the given location into this table.
func (*CommitTableBuilder) Table ¶
func (builder *CommitTableBuilder) Table(fields []string) DataTable
Table provides the data accumulated by this CommitTableBuilder as a DataTable.
type DataTable ¶
type DataTable struct { // table data organized as rows and columns Cells [][]string `exhaustruct:"optional"` }
DataTable allows comparing user-generated data with Gherkin tables. The zero value is an empty DataTable.
func FromGherkin ¶
func FromGherkin(table *messages.PickleStepArgument_PickleTable) DataTable
FromGherkin provides a DataTable instance populated with data from the given Gherkin table.
func RenderExecutedGitCommands ¶
func RenderExecutedGitCommands(commands []ExecutedGitCommand, table *messages.PickleStepArgument_PickleTable) DataTable
RenderExecutedGitCommands provides the textual Gherkin table representation of the given executed Git commands. The DataTable table matches the structure of the given Gherkin table.
func (*DataTable) EqualDataTable ¶
EqualDataTable compares this DataTable instance to the given DataTable. If both are equal it returns an empty string, otherwise a diff printable on the console.
func (*DataTable) EqualGherkin ¶
func (table *DataTable) EqualGherkin(other *messages.PickleStepArgument_PickleTable) (diff string, errorCount int)
EqualGherkin compares this DataTable instance to the given Gherkin table. If both are equal it returns an empty string, otherwise a diff printable on the console.
func (*DataTable) Expand ¶
Expand returns a new DataTable instance with the placeholders in this datatable replaced with the given values.
func (*DataTable) RemoveText ¶
RemoveText deletes the given text from each cell.
type ExecutedGitCommand ¶
type ExecutedGitCommand struct { // Branch contains the branch in which this command ran. Branch string // Command contains the command executed. Command string }
ExecutedGitCommand describes a Git command that was executed by Git Town during testing.
func GitCommandsInGitTownOutput ¶
func GitCommandsInGitTownOutput(output string) []ExecutedGitCommand
GitCommandsInGitTownOutput provides the Git commands mentioned in the given Git Town output.
type GitEnvironment ¶
type GitEnvironment struct { // Dir defines the local folder in which this GitEnvironment is stored. // This folder also acts as the HOME directory for tests using this GitEnvironment. // It contains the global Git configuration to use in this test. Dir string // CoworkerRepo is the optional Git repository that is locally checked out at the coworker machine. CoworkerRepo *Runner `exhaustruct:"optional"` // DevRepo is the Git repository that is locally checked out at the developer machine. DevRepo Runner `exhaustruct:"optional"` // OriginRepo is the Git repository that simulates the origin repo (on GitHub). // If this value is nil, the current test setup has no origin. OriginRepo *Runner `exhaustruct:"optional"` // SubmoduleRepo is the Git repository that simulates an external repo used as a submodule. // If this value is nil, the current test setup uses no submodules. SubmoduleRepo *Runner `exhaustruct:"optional"` // UpstreamRepo is the optional Git repository that contains the upstream for this environment. UpstreamRepo *Runner `exhaustruct:"optional"` }
GitEnvironment is a complete Git environment for a Cucumber scenario.
func CloneGitEnvironment ¶
func CloneGitEnvironment(original GitEnvironment, dir string) (GitEnvironment, error)
CloneGitEnvironment provides a GitEnvironment instance in the given directory, containing a copy of the given GitEnvironment.
func NewStandardGitEnvironment ¶
func NewStandardGitEnvironment(dir string) (GitEnvironment, error)
NewStandardGitEnvironment provides a GitEnvironment in the given directory, fully populated as a standardized setup for scenarios.
The origin repo has the initial branch checked out. Git repos cannot receive pushes of the currently checked out branch because that will change files in the current workspace. The tests don't use the initial branch.
func (*GitEnvironment) AddCoworkerRepo ¶
func (env *GitEnvironment) AddCoworkerRepo() error
AddCoworkerRepo adds a coworker repository.
func (*GitEnvironment) AddSubmoduleRepo ¶
func (env *GitEnvironment) AddSubmoduleRepo() error
AddSubmodule adds a submodule repository.
func (*GitEnvironment) AddUpstream ¶
func (env *GitEnvironment) AddUpstream() error
AddUpstream adds an upstream repository.
func (*GitEnvironment) Branches ¶
func (env *GitEnvironment) Branches() (DataTable, error)
Branches provides a tabular list of all branches in this GitEnvironment.
func (GitEnvironment) CommitTable ¶
func (env GitEnvironment) CommitTable(fields []string) (DataTable, error)
CommitTable provides a table for all commits in this Git environment containing only the given fields.
func (*GitEnvironment) CreateCommits ¶
func (env *GitEnvironment) CreateCommits(commits []git.Commit) error
CreateCommits creates the commits described by the given Gherkin table in this Git repository.
func (GitEnvironment) CreateOriginBranch ¶
func (env GitEnvironment) CreateOriginBranch(name, parent string) error
CreateOriginBranch creates a branch with the given name only in the origin directory.
func (GitEnvironment) CreateTags ¶
func (env GitEnvironment) CreateTags(table *messages.PickleStepArgument_PickleTable) error
CreateTags creates tags from the given gherkin table.
func (GitEnvironment) Remove ¶
func (env GitEnvironment) Remove() error
Remove deletes all files used by this GitEnvironment from disk.
func (GitEnvironment) TagTable ¶
func (env GitEnvironment) TagTable() (DataTable, error)
TagTable provides a table for all tags in this Git environment.
type GitManager ¶
type GitManager struct {
// contains filtered or unexported fields
}
GitManager manages the Git setup for the entire test suite. For each scenario, it provides a standardized, empty GitEnvironment consisting of a local and remote Git repository.
Setting up a GitEnvironment is an expensive operation and has to be done for every scenario. As a performance optimization, GitManager creates a fully set up GitEnvironment (including the main branch and configuration) (the "memoized" environment) at the beginning of the test suite and makes copies of it for each scenario. Making copies of a fully set up Git repo is much faster than creating it from scratch. End-to-end tests run multi-threaded, all threads share a global GitManager instance.
func NewGitManager ¶
func NewGitManager(dir string) (GitManager, error)
NewGitManager provides a new GitManager instance operating in the given directory.
func (*GitManager) CreateScenarioEnvironment ¶
func (manager *GitManager) CreateScenarioEnvironment(scenarioName string) (GitEnvironment, error)
CreateScenarioEnvironment provides a new GitEnvironment for the scenario with the given name.
type MockingRunner ¶
type MockingRunner struct { // whether to log the output of subshell commands Debug bool `exhaustruct:"optional"` // contains filtered or unexported fields }
MockingRunner runs shell commands using a customizable environment. This is useful in tests. Possible customizations:
- overide environment variables
- Temporarily override certain shell commands with mock implementations. Temporary mocks are only valid for the next command being run.
func (*MockingRunner) MockBrokenCommand ¶
func (r *MockingRunner) MockBrokenCommand(name string) error
MockBrokenCommand adds a mock for the given command that returns an error.
func (*MockingRunner) MockCommand ¶
func (r *MockingRunner) MockCommand(name string) error
MockCommand adds a mock for the command with the given name.
func (*MockingRunner) MockCommitMessage ¶
func (r *MockingRunner) MockCommitMessage(message string) error
MockCommitMessage sets up this runner with an editor that enters the given commit message.
func (*MockingRunner) MockGit ¶
func (r *MockingRunner) MockGit(version string) error
MockGit pretends that this repo has Git in the given version installed.
func (*MockingRunner) MockNoCommandsInstalled ¶
func (r *MockingRunner) MockNoCommandsInstalled() error
MockNoCommandsInstalled pretends that no commands are installed.
func (*MockingRunner) Run ¶
func (r *MockingRunner) Run(name string, arguments ...string) (string, error)
Run runs the given command with the given arguments. Overrides will be used and removed when done.
func (*MockingRunner) RunMany ¶
func (r *MockingRunner) RunMany(commands [][]string) error
RunMany runs all given commands. Commands are provided as a list of argv-style strings. Overrides apply for the first command only. Failed commands abort immediately with the encountered error.
func (*MockingRunner) RunString ¶
func (r *MockingRunner) RunString(fullCmd string) (string, error)
RunString runs the given command (including possible arguments). Overrides will be used and removed when done.
func (*MockingRunner) RunStringWith ¶
func (r *MockingRunner) RunStringWith(fullCmd string, opts *Options) (string, error)
RunStringWith runs the given command (including possible arguments) using the given options. opts.Dir is a relative path inside the working directory of this ShellRunner. Overrides will be used and removed when done.
func (*MockingRunner) RunWith ¶
RunWith runs the given command with the given options in this ShellRunner's directory.
func (*MockingRunner) SetTestOrigin ¶
func (r *MockingRunner) SetTestOrigin(content string)
SetTestOrigin adds the given environment variable to subsequent runs of commands.
func (*MockingRunner) WorkingDir ¶
func (r *MockingRunner) WorkingDir() string
WorkingDir provides the directory this MockingRunner operates in.
type Options ¶
type Options struct { // Dir contains the directory in which to execute the command. // If empty, runs in the current directory. Dir string // Env allows to override the environment variables to use in the subshell, in the format provided by os.Environ() // If empty, uses the environment variables of this process. Env []string // Input contains the user input to enter into the running command. // It is written to the subprocess one element at a time, with a delay defined by command.InputDelay in between. Input []string // input into the subprocess }
Options defines optional arguments for ShellRunner.RunWith().
type Runner ¶
type Runner struct { Backend git.BackendCommands // contains filtered or unexported fields }
Runner provides Git functionality for test code (unit and end-to-end tests).
func CreateRunner ¶
CreateRunner creates test.Runner instances.
func CreateTestGitTownRunner ¶
CreateTestGitTownRunner creates a test.Runner for use in tests, with a main branch and initial git town configuration.
func (*Runner) AddRemote ¶
AddRemote adds a Git remote with the given name and URL to this repository.
func (*Runner) AddSubmodule ¶
AddSubmodule adds a Git submodule with the given URL to this repository.
func (*Runner) BranchHierarchyTable ¶
func (r *Runner) BranchHierarchyTable() DataTable
BranchHierarchyTable provides the currently configured branch hierarchy information as a DataTable.
func (*Runner) CheckoutBranch ¶
CheckoutBranch checks out the Git branch with the given name in this repo.
func (*Runner) Clone ¶
Clone creates a clone of the repository managed by this test.Runner into the given directory. The cloned repo uses the same homeDir and binDir as its origin.
func (*Runner) CommitStagedChanges ¶
CommitStagedChanges commits the currently staged changes.
func (*Runner) Commits ¶
Commits provides a list of the commits in this Git repository with the given fields.
func (*Runner) CommitsInBranch ¶
CommitsInBranch provides all commits in the given Git branch.
func (*Runner) ConnectTrackingBranch ¶
ConnectTrackingBranch connects the branch with the given name to its counterpart at origin. The branch must exist.
func (*Runner) CreateBranch ¶
CreateBranch creates a new branch with the given name. The created branch is a normal branch. To create feature branches, use CreateFeatureBranch.
func (*Runner) CreateChildFeatureBranch ¶
CreateChildFeatureBranch creates a branch with the given name and parent in this repository. The parent branch must already exist.
func (*Runner) CreateCommit ¶
CreateCommit creates a commit with the given properties in this Git repo.
func (*Runner) CreateFile ¶
CreateFile creates a file with the given name and content in this repository.
func (*Runner) CreatePerennialBranches ¶
CreatePerennialBranches creates perennial branches with the given names in this repository.
func (*Runner) CreateStandaloneTag ¶
CreateStandaloneTag creates a tag not on a branch.
func (*Runner) DeleteMainBranchConfiguration ¶
func (r *Runner) DeleteMainBranchConfiguration() error
DeleteMainBranchConfiguration removes the configuration for which branch is the main branch.
func (*Runner) Fetch ¶
func (r *Runner) Fetch() error
Fetch retrieves the updates from the origin repo.
func (*Runner) FileContent ¶
FileContent provides the current content of a file.
func (*Runner) FileContentInCommit ¶
FileContentInCommit provides the content of the file with the given name in the commit with the given SHA.
func (*Runner) FilesInBranch ¶
FilesInBranch provides the list of the files present in the given branch.
func (*Runner) FilesInBranches ¶
FilesInBranches provides a data table of files and their content in all branches.
func (*Runner) FilesInCommit ¶
FilesInCommit provides the names of the files that the commit with the given SHA changes.
func (*Runner) HasBranchesOutOfSync ¶
HasBranchesOutOfSync indicates whether one or more local branches are out of sync with their tracking branch.
func (*Runner) HasFile ¶
HasFile indicates whether this repository contains a file with the given name and content.
func (*Runner) HasGitTownConfigNow ¶
func (r *Runner) HasGitTownConfigNow() bool
HasGitTownConfigNow indicates whether this repository contain Git Town specific configuration.
func (*Runner) PushBranch ¶
func (r *Runner) PushBranch() error
func (*Runner) PushBranchToRemote ¶
func (*Runner) RemoveBranch ¶
RemoveBranch deletes the branch with the given name from this repo.
func (*Runner) RemoveRemote ¶
RemoveRemote deletes the Git remote with the given name.
func (*Runner) RemoveUnnecessaryFiles ¶
func (r *Runner) RemoveUnnecessaryFiles() error
RemoveUnnecessaryFiles trims all files that aren't necessary in this repo.
func (*Runner) ShaForCommit ¶
ShaForCommit provides the SHA for the commit with the given name.
func (*Runner) StageFiles ¶
StageFiles adds the file with the given name to the Git index.
func (*Runner) UncommittedFiles ¶
UncommittedFiles provides the names of the files not committed into Git.
type ScenarioState ¶
type ScenarioState struct {
// contains filtered or unexported fields
}
ScenarioState constains the state that is shared by all steps within a scenario.
func (*ScenarioState) InitialBranches ¶
func (state *ScenarioState) InitialBranches() DataTable
InitialBranches provides the branches in this Scenario before the WHEN steps ran.
func (*ScenarioState) Reset ¶
func (state *ScenarioState) Reset(gitEnv GitEnvironment)
Reset restores the null value of this ScenarioState.
type TagTableBuilder ¶
type TagTableBuilder struct {
// contains filtered or unexported fields
}
TagTableBuilder collects data about tags in Git repositories in the same way that our Gherkin tables describing tags in repos are organized.
func NewTagTableBuilder ¶
func NewTagTableBuilder() TagTableBuilder
NewTagTableBuilder provides a fully initialized instance of TagTableBuilder.
func (*TagTableBuilder) Add ¶
func (builder *TagTableBuilder) Add(tag, location string)
Add registers the given tag from the given location into this table.
func (*TagTableBuilder) AddMany ¶
func (builder *TagTableBuilder) AddMany(tags []string, location string)
AddMany registers the given tags from the given location into this table.
func (*TagTableBuilder) Table ¶
func (builder *TagTableBuilder) Table() DataTable
Table provides the data accumulated by this TagTableBuilder as a DataTable.