testutils

package
v0.0.0-...-06fe44a Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package testutils implements helper functions for frequently needed functionality in tests.

Index

Constants

View Source
const (
	// UpdateGoldenFilesEnv is the environment variable used to indicate go test that
	// the golden files should be overwritten with the current test results.
	UpdateGoldenFilesEnv = `TESTS_UPDATE_GOLDEN`
)

Variables

This section is empty.

Functions

func GenerateTempCertificate

func GenerateTempCertificate(t *testing.T, path string)

GenerateTempCertificate generates a self-signed certificate valid for one hour. Both the certificate and the private key are stored in the specified path.

func LoadWithUpdateFromGolden

func LoadWithUpdateFromGolden(t *testing.T, data string, opts ...Option) string

LoadWithUpdateFromGolden loads the element from a plaintext golden file. It will update the file if the update flag is used prior to loading it.

func LoadWithUpdateFromGoldenYAML

func LoadWithUpdateFromGoldenYAML[E any](t *testing.T, got E, opts ...Option) E

LoadWithUpdateFromGoldenYAML load the generic element from a YAML serialized golden file. It will update the file if the update flag is used prior to deserializing it.

func Path

func Path(t *testing.T) string

Path returns the golden path for the provided test.

func ReplaceFileWithDir

func ReplaceFileWithDir(t *testing.T, path string, msg string, args ...any)

ReplaceFileWithDir removes a file and creates a directory with the same path. Useful to break file reads and assert on the errors.

func TestFamilyPath

func TestFamilyPath(t *testing.T) string

TestFamilyPath returns the path of the dir for storing fixtures and other files related to the test.

func TestFixturePath

func TestFixturePath(t *testing.T) string

TestFixturePath returns the path of the dir or file for storing fixture specific to the subtest name.

func UpdateEnabled

func UpdateEnabled() bool

UpdateEnabled is a getter for the update flag.

Types

type Option

type Option func(*goldenOptions)

Option is a supported option reference to change the golden files comparison.

func WithGoldenPath

func WithGoldenPath(path string) Option

WithGoldenPath overrides the default path for golden files used.

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set is a simple thread-safe implementation of an unordered set. Useful for testing.

func NewSet

func NewSet[T comparable]() *Set[T]

NewSet creates a new set.

func (*Set[T]) Has

func (s *Set[T]) Has(v T) bool

Has returns true if the set contains the specified entry.

func (*Set[T]) Len

func (s *Set[T]) Len() int

Len returns the count of items in the set.

func (*Set[T]) Set

func (s *Set[T]) Set(v T)

Set adds an entry to the set.

func (*Set[T]) Unset

func (s *Set[T]) Unset(v T)

Unset removes an entry from the set.

Jump to

Keyboard shortcuts

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