testenv

package
v0.0.0-...-0527fad Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package testenv contains test environment utilities

Index

Constants

View Source
const (
	PersistStubEnvironment testEnv = iota // key to a bool flag telling if the environment is persisted
	RestoreStubEnvironment                // key to a bool flag telling if the environment is restored
	NoColors                              // key to a bool flag telling if the colors should be used in output
	TestingT                              // key to the *testing.T instance in Context

	RekorImpl // key to a implementation of the Rekor interface, used to prevent import cycles
	Scenario  // key to a the *godog.Scenario of the current scenario, used to prevent import cycles
	TestUtil  // key to a test utility struct

)

Keys we use to look up the state in the Context

Variables

This section is empty.

Functions

func CLIVersion

func CLIVersion(ctx context.Context) (string, error)

CLIVersion returns the version of the CLI, useful for matching in snapshots

func FetchState

func FetchState[S WithState](ctx context.Context) *S

FetchState fetches the state from the Context stored under S.Key()

func HasState

func HasState[S WithState](ctx context.Context) bool

HasState returns true if the state for the provided type is present in the context

func NoColorOutput

func NoColorOutput(ctx context.Context) bool

NoColorOutput returns true if the output produced should not contain colors, which is useful when a terminal or medium can't interpret ANSI colors

func Persist

func Persist(ctx context.Context) (bool, error)

Persist persists the environment stored in context in a ".persisted" file as JSON

func Persisted

func Persisted(ctx context.Context) bool

Persisted returns true if the test environment persists after the test has finished

func Restored

func Restored(ctx context.Context) bool

Restored returns true if the test environment is restored from the last persisted environment

func SetupState

func SetupState[S WithState](ctx context.Context, state **S) (context.Context, error)

SetupState initializes the given state S and stores it in Context under S.Key(), if invoked twice for the same S.Key() the state will be set to the existing value from Context. If the test environment is being restored, values from the persisted file will be loaded.

func TempDir

func TempDir(ctx context.Context) (context.Context, string)

func TestContainersRequest

func TestContainersRequest(ctx context.Context, req testcontainers.ContainerRequest) testcontainers.ContainerRequest

TestContainersRequest modifies the req to keep the container running after the test if PersistStubEnvironment is set to true in the ctx

func Testing

func Testing(ctx context.Context) *testing.T

Types

type Initializing

type Initializing interface {
	Initialize()
}

type WithState

type WithState interface {
	Key() any
}

WithState marks a struct that holds some state under a specific key

Jump to

Keyboard shortcuts

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