Documentation
¶
Overview ¶
Package testhelper provides helper functions for tests. These are used across packages
Index ¶
- Constants
- func AddCrate(t *testing.T, location, name string)
- func CloneRepository(t *testing.T, remoteDir string)
- func CloneRepositoryBranch(t *testing.T, remoteDir, branch string)
- func ContinueInNewGitRepository(t *testing.T, tmpDir string)
- func RequireCommand(t *testing.T, cmd string)
- func Setup(t *testing.T, opts SetupOptions)
- func SetupForVersionBump(t *testing.T, wantTag string)
- func SetupRepo(t *testing.T) string
- func SetupRepoWithChange(t *testing.T, wantTag string) string
- type SetupOptions
Constants ¶
const ( // InitialCargoContents defines the initial content for a Cargo.toml file. InitialCargoContents = `# Example Cargo file [package] name = "%s" version = "1.0.0" ` // NewLibRsContents defines new content for a lib.rs file for testing changes. NewLibRsContents = `pub fn hello() -> &'static str { "Hello World" }` // ReadmeFile is the local file path for the README.md file initialized in // the test repo. ReadmeFile = "README.md" // ReadmeContents is the contents of the [ReadmeFile] initialized in the // test repo. ReadmeContents = "# Empty Repo" // TestRemote is the name of a remote source for the test repository. TestRemote = "test" )
Variables ¶
This section is empty.
Functions ¶
func CloneRepository ¶
CloneRepository clones the remote repository into a new temporary directory and changes the current working directory to the cloned repository.
func CloneRepositoryBranch ¶
CloneRepositoryBranch clones the repository at the specified branch into a temporary directory and changes the current working directory to the cloned repository.
func ContinueInNewGitRepository ¶
ContinueInNewGitRepository initializes a new git repository in a temporary directory and changes the current working directory to it.
func RequireCommand ¶
RequireCommand skips the test if the specified command is not found in PATH. Use this to skip tests that depend on external tools like protoc, cargo, or taplo, so that `go test ./...` will always pass on a fresh clone of the repo.
func Setup ¶
func Setup(t *testing.T, opts SetupOptions)
Setup is a configurable test setup function that starts by creating a fresh test repository via SetupRepo, to which it then applies the configured SetupOptions.
func SetupForVersionBump ¶
SetupForVersionBump sets up a git repository for testing version bumping scenarios.
Types ¶
type SetupOptions ¶
type SetupOptions struct {
// Clone is the branch that [Setup] should clone into after all setup is
// complete. Must not be set in PreviewOptions.
Clone string
// Config is the [config.Config] to write to librarian.yaml in the root
// of the repo created.
Config *config.Config
// Dirty indicates if the cloned repository should be left in a dirty state,
// with uncommitted files. Primarily used for error testing.
Dirty bool
// PreviewOptions indicate the creation of a 'preview' branch in the repo
// using the provided SetupOptions.
PreviewOptions *SetupOptions
// Tags is the list of tags that will be applied once all initial file set up is
// complete.
Tags []string
// WithChanges is a list of file paths that should show as changed and be
// committed after Tag has been applied.
WithChanges []string
// contains filtered or unexported fields
}
SetupOptions include the various options for configuring test setup.