testhelper

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package testhelper provides helper functions for tests. These are used across packages

Index

Constants

View Source
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 AddCrate

func AddCrate(t *testing.T, location, name string)

AddCrate creates a new Rust crate at the specified location with the given name.

func CloneRepository

func CloneRepository(t *testing.T, remoteDir string)

CloneRepository clones the remote repository into a new temporary directory and changes the current working directory to the cloned repository.

func CloneRepositoryBranch

func CloneRepositoryBranch(t *testing.T, remoteDir, branch string)

CloneRepositoryBranch clones the repository at the specified branch into a temporary directory and changes the current working directory to the cloned repository.

func ContinueInNewGitRepository

func ContinueInNewGitRepository(t *testing.T, tmpDir string)

ContinueInNewGitRepository initializes a new git repository in a temporary directory and changes the current working directory to it.

func RequireCommand

func RequireCommand(t *testing.T, cmd string)

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

func SetupForVersionBump(t *testing.T, wantTag string)

SetupForVersionBump sets up a git repository for testing version bumping scenarios.

func SetupRepo

func SetupRepo(t *testing.T) string

SetupRepo creates a git repository for testing with some initial content. It returns the path of the remote repository.

func SetupRepoWithChange

func SetupRepoWithChange(t *testing.T, wantTag string) string

SetupRepoWithChange creates a git repository for testing publish scenarios, including initial content, a tag, and a committed change. It returns the path to the remote repository.

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

	// Tag is the tag that will be applied once all initial file set up is
	// complete.
	Tag 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.

Jump to

Keyboard shortcuts

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