testlib

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package testlib contains test helpers for kmdo tests.

Index

Constants

This section is empty.

Variables

View Source
var GoVersion = strings.TrimPrefix(runtime.Version(), "go")

GoVersion is the current Go version, without the "go" prefix.

Functions

func AssertSkipped

func AssertSkipped(t *testing.T, err error)

AssertSkipped asserts that a pipe was skipped.

func CatFileFromBareRepository

func CatFileFromBareRepository(tb testing.TB, url, name string) []byte

func CatFileFromBareRepositoryOnBranch

func CatFileFromBareRepositoryOnBranch(tb testing.TB, url, branch, name string) []byte

func CheckDocker

func CheckDocker(tb testing.TB)

CheckDocker skips the test if docker is not running.

func CheckPath

func CheckPath(tb testing.TB, cmd string)

CheckPath skips the test if the binary is not in the PATH, or if CI is true.

func Echo

func Echo(s string) string

Echo returns a `echo s` command, handling it on windows.

func Exit

func Exit(status int) string

Exit returns a command that exits the given status, handling windows.

func GetFileFromArchive

func GetFileFromArchive(tb testing.TB, path, format, filename string) []byte

GetFileFromArchive returns the contents of filename inside the given archive path.

func GitAdd

func GitAdd(tb testing.TB)

GitAdd adds all files to stage.

func GitAnnotatedTag

func GitAnnotatedTag(tb testing.TB, tag, message string)

GitAnnotatedTag creates an annotated tag.

func GitBranch

func GitBranch(tb testing.TB, branch string)

GitBranch creates a git branch.

func GitCheckoutBranch

func GitCheckoutBranch(tb testing.TB, name string)

GitCheckoutBranch allows us to change the active branch that we're using.

func GitCommit

func GitCommit(tb testing.TB, msg string)

GitCommit creates a git commits.

func GitInit

func GitInit(tb testing.TB)

GitInit inits a new git project.

func GitMakeBareRepository

func GitMakeBareRepository(tb testing.TB) string

func GitRemoteAdd

func GitRemoteAdd(tb testing.TB, url string)

GitRemoteAdd adds the given url as remote.

func GitRemoteAddWithName

func GitRemoteAddWithName(tb testing.TB, remote, url string)

GitRemoteAddWithName adds the given url as remote with given name.

func GitTag

func GitTag(tb testing.TB, tag string)

GitTag creates a git tag.

func InPath

func InPath(cmd string) bool

InPath returns true if the given cmd is in the PATH, or if CI is true.

func IsCI

func IsCI() bool

IsCI returns true if we have the "CI" environment variable set to true.

func IsDockerRunning

func IsDockerRunning(ctx context.Context) bool

IsDockerRunning executes a `docker ps` and returns true if it succeeds.

func IsWindows

func IsWindows() bool

IsWindows returns true if current OS is Windows.

func LsArchive

func LsArchive(tb testing.TB, path, format string) []string

LsArchive return the file list of a given archive in a given formatkj

func MakeNewSSHKey

func MakeNewSSHKey(tb testing.TB, pass string) string

func MakeNewSSHKeyType

func MakeNewSSHKeyType(tb testing.TB, pass string, algo keygen.KeyType) string

func Mktmp

func Mktmp(tb testing.TB) string

Mktmp creates a new tempdir, cd into it and automatically cd back when the test finishes.

func MustDockerPool

func MustDockerPool(f Fataler) *dockertest.Pool

MustDockerPool gets a single dockertet.Pool.

func MustKillContainer

func MustKillContainer(f Fataler, name string)

MustKillContainer kills the given container by name if it exists in the current dockertest.Pool.

func RequireEqualArtifacts

func RequireEqualArtifacts(tb testing.TB, expected, got []*artifact.Artifact)

func RequireNoExtraField

func RequireNoExtraField(tb testing.TB, a *artifact.Artifact, key string)

func RequireTemplateError

func RequireTemplateError(tb testing.TB, err error)

RequireTemplateError requires thqt an error happens and that it is a template error.

func ShC

func ShC(cmd string) string

ShC returns the command line for the given cmd wrapped into a `sh -c` in linux/mac, and the cmd.exe command in windows.

func SkipIfWindows

func SkipIfWindows(tb testing.TB, args ...any)

SkipIfWindows skips the test if runtime OS is windows.

func StartRegistry

func StartRegistry(tb testing.TB, name, port string)

StartRegistry starts a registry with the given name in the given port, and sets up its deletion on test.Cleanup.

func Touch

func Touch(name string) string

Touch returns a `touch name` command, handling it on windows.

Types

type Fataler

type Fataler interface {
	Fatal(args ...any)
}

Fataler interface, can be a log.Default() or testing.TB, for example.

Jump to

Keyboard shortcuts

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