test

package
v7.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 25 Imported by: 0

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.

Index

Constants

This section is empty.

Variables

View Source
var Debug = false

Debug indicates whether test code should log output of console commands.

Functions

func CallScriptArgs

func CallScriptArgs(toolPath string) (cmd string, args []string)

CallScriptArgs provides the command and arguments to call the given script on Windows.

func CopyDirectory

func CopyDirectory(src, dst string) error

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

func CreateInputTool(toolPath string) error

CreateInputTool creates a tool that reads two inputs from STDIN and prints them back to the user.

func CreateLsTool

func CreateLsTool(toolPath string) error

CreateLsTool creates a tool in the given folder that lists all files in its current folder.

func CreateTempDir

func CreateTempDir(t *testing.T) string

CreateTempDir creates a new empty directory in the system's temp directory and provides the path to it.

func DefaultCommit

func DefaultCommit() git.Commit

DefaultCommit provides a new Commit instance populated with the default values used in the absence of value specified by the test.

func FromGherkinTable

func FromGherkinTable(table *messages.PickleStepArgument_PickleTable) ([]git.Commit, error)

FromGherkinTable provides a Commit collection representing the data in the given Gherkin table.

func RenderTable

func RenderTable(table *messages.PickleStepArgument_PickleTable) string

RenderTable provides the textual Gherkin representation of the given Gherkin table.

func ScriptName

func ScriptName(command string) string

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 {
	Cells [][]string // contains table data organized as rows and columns
}

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) AddRow

func (table *DataTable) AddRow(elements ...string)

AddRow adds the given row of table data to this table.

func (*DataTable) EqualDataTable

func (table *DataTable) EqualDataTable(other DataTable) (diff string, errorCount int)

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

func (table *DataTable) Expand(localRepo *Repo, remoteRepo *Repo) (DataTable, error)

Expand returns a new DataTable instance with the placeholders in this datatable replaced with the given values.

func (*DataTable) RemoveText

func (table *DataTable) RemoveText(text string)

RemoveText deletes the given text from each cell.

func (*DataTable) Sort added in v7.8.0

func (table *DataTable) Sort()

Sorted provides a new DataTable that contains the content of this DataTable sorted by the first column.

func (*DataTable) String

func (table *DataTable) String() string

String provides the data in this DataTable instance formatted in Gherkin table format.

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 *Repo

	// DevRepo is the Git repository that is locally checked out at the developer machine.
	DevRepo Repo

	// DevShell provides a reference to the MockingShell instance used in the DeveloperRepo.
	DevShell MockingShell

	// 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 *Repo

	// 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 *Repo

	// UpstreamRepo is the optional Git repository that contains the upstream for this environment.
	UpstreamRepo *Repo
}

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 added in v7.8.0

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 MockingShell

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

MockingShell 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 NewMockingShell

func NewMockingShell(workingDir string, homeDir string, binDir string) MockingShell

NewMockingShell provides a new MockingShell instance that executes in the given directory.

func (*MockingShell) MockBrokenCommand

func (ms *MockingShell) MockBrokenCommand(name string) error

MockBrokenCommand adds a mock for the given command that returns an error.

func (*MockingShell) MockCommand

func (ms *MockingShell) MockCommand(name string) error

MockCommand adds a mock for the command with the given name.

func (*MockingShell) MockCommitMessage

func (ms *MockingShell) MockCommitMessage(message string) error

MockCommitMessage sets up this shell with an editor that enters the given commit message.

func (*MockingShell) MockGit

func (ms *MockingShell) MockGit(version string) error

MockGit pretends that this repo has Git in the given version installed.

func (*MockingShell) MockNoCommandsInstalled

func (ms *MockingShell) MockNoCommandsInstalled() error

MockNoCommandsInstalled pretends that no commands are installed.

func (*MockingShell) Run

func (ms *MockingShell) Run(name string, arguments ...string) (*run.Result, error)

Run runs the given command with the given arguments in this ShellRunner's directory. Shell overrides will be used and removed when done.

func (*MockingShell) RunMany

func (ms *MockingShell) RunMany(commands [][]string) error

RunMany runs all given commands in current directory. Commands are provided as a list of argv-style strings. Shell overrides apply for the first command only. Failed commands abort immediately with the encountered error.

func (*MockingShell) RunString

func (ms *MockingShell) RunString(fullCmd string) (*run.Result, error)

RunString runs the given command (including possible arguments) in this ShellRunner's directory. Shell overrides will be used and removed when done.

func (*MockingShell) RunStringWith

func (ms *MockingShell) RunStringWith(fullCmd string, opts run.Options) (*run.Result, error)

RunStringWith runs the given command (including possible arguments) in this ShellRunner's directory using the given options. opts.Dir is a relative path inside the working directory of this ShellRunner. Shell overrides will be used and removed when done.

func (*MockingShell) RunWith

func (ms *MockingShell) RunWith(opts run.Options, cmd string, args ...string) (*run.Result, error)

RunWith runs the given command with the given options in this ShellRunner's directory.

func (*MockingShell) SetTestOrigin

func (ms *MockingShell) SetTestOrigin(content string)

SetTestOrigin adds the given environment variable to subsequent runs of commands.

func (*MockingShell) WorkingDir

func (ms *MockingShell) WorkingDir() string

WorkingDir provides the directory this MockingShell operates in.

type Repo

type Repo struct {
	git.Runner // the git.Runner instance to use
	// contains filtered or unexported fields
}

Repo is a Git Repo in test code.

func CreateRepo

func CreateRepo(t *testing.T) Repo

CreateRepo creates TestRepo instances.

func CreateTestGitTownRepo

func CreateTestGitTownRepo(t *testing.T) Repo

CreateTestGitTownRepo creates a GitRepo for use in tests, with a main branch and initial git town configuration.

func InitRepo

func InitRepo(workingDir, homeDir, binDir string) (Repo, error)

InitRepo creates a fully functioning test.Repo in the given working directory, including necessary Git configuration to make commits. Creates missing folders as needed.

func NewRepo

func NewRepo(workingDir, homeDir, binDir string) Repo

NewRepo provides a new Repo instance working in the given directory. The directory must contain an existing Git repo.

func (*Repo) BranchHierarchyTable added in v7.8.0

func (repo *Repo) BranchHierarchyTable() DataTable

BranchHierarchyTable provides the currently configured branch hierarchy information as a DataTable.

func (*Repo) Clone

func (repo *Repo) Clone(targetDir string) (Repo, error)

Clone creates a clone of this Repo into the given directory. The cloned repo uses the same homeDir and binDir as its origin.

func (*Repo) FilesInBranches

func (repo *Repo) FilesInBranches() (DataTable, error)

FilesInBranches provides a data table of files and their content in all branches.

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 added in v7.8.0

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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