testutil

package
v2.0.0-beta.21 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package testutil contains common testing tasks like running dockerd.

Index

Constants

This section is empty.

Variables

View Source
var DevZero io.Reader = devZero{}

DevZero acts like /dev/zero but in an OS-independent fashion.

Functions

func CheckNotParallel

func CheckNotParallel(t testing.TB)

CheckNotParallel checks if t.Parallel() was not called on the current test. There's no public method to check this, so we use reflection to check the internal field set by t.Parallel() https://github.com/golang/go/blob/8e658eee9c7a67a8a79a8308695920ac9917566c/src/testing/testing.go#L1449

Since this is not a public API, it might change at any time.

func CleanupContext

func CleanupContext(t *testing.T)

func ConfigureTracing

func ConfigureTracing() func(context.Context)

ConfigureTracing sets up an OTLP tracing exporter for use in tests.

func GetContext

func GetContext(t TestingT) context.Context

func RandomAlpha

func RandomAlpha(n int) string

RandomAlpha generates a lowercase alphabetical random string with length n.

func RunCommand

func RunCommand(ctx context.Context, cmd string, args ...string) *icmd.Result

func SetContext

func SetContext(t TestingT, ctx context.Context)

func StartSpan

func StartSpan(ctx context.Context, t TestingT) context.Context

StartSpan starts a span for the given test.

func TempDir

func TempDir(t *testing.T) string

TempDir returns a temporary directory for use in tests. t.TempDir() can't be used as the temporary directory returned by that function cannot be accessed by the fake-root user for rootless Docker. It creates a nested hierarchy of directories where the outermost has permission 0700.

func UncompressedTarDigest

func UncompressedTarDigest(compressedTar io.Reader) (digest.Digest, error)

UncompressedTarDigest returns the canonical digest of the uncompressed tar stream.

Types

type HelperT

type HelperT interface {
	Helper()
}

HelperT is a subset of testing.T that implements the Helper function

type Logger

type Logger interface {
	Logf(format string, args ...any)
}

Logger is used to log non-fatal messages during tests.

type TestingT

type TestingT interface {
	Name() string
	Cleanup(func())
	Log(...any)
	Failed() bool
}

TestingT is an interface wrapper around *testing.T and *testing.B.

Directories

Path Synopsis
Package daemon launches dockerd for testing purposes.
Package daemon launches dockerd for testing purposes.
fixtures
plugin/basic command

Jump to

Keyboard shortcuts

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