testutils

package
v0.0.0-...-2c16969 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: Apache-2.0 Imports: 24 Imported by: 7

Documentation

Index

Constants

View Source
const GO_MOD = "go.mod"

Variables

This section is empty.

Functions

func AsString

func AsString(actual interface{}) (string, error)

func AsStructure

func AsStructure(actual interface{}, substs ...substutils.Substitution) (interface{}, error)

func Calling

func Calling[T any](o T, err error) result[T]

func Close

func Close(c io.Closer, msg ...interface{})

func DeepEqual

func DeepEqual(expected interface{}) types.GomegaMatcher

DeepEqual compares two objects and shows diff on failure.

func Defer

func Defer(f func() error, msg ...interface{})

func DeferWithOffset

func DeferWithOffset(o int, f func() error, msg ...interface{})

func ErrorFrom

func ErrorFrom(args ...interface{}) error

func ExpectError

func ExpectError(values ...interface{}) types.Assertion

func GetModuleName

func GetModuleName() (string, error)

GetModuleName returns a go modules module name by finding and parsing the go.mod file.

func GetPackagePathFromProjectRoot

func GetPackagePathFromProjectRoot(i ...interface{}) (string, error)

func GetRelativePathToProjectRoot

func GetRelativePathToProjectRoot(i ...int) (string, error)

GetRelativePathToProjectRoot calculates the relative path to a go projects root directory. It therefore assumes that the project root is the directory containing the go.mod file. The optional parameter i determines how many directories the function will step up through, attempting to find a go.mod file. If it cannot find a directory with a go.mod file within i iterations, the function throws an error.

func MergeSubst deprecated

Deprecated: use substutils.MergeMapSubstitution.

func Must

func Must[T any](o T, err error) T

func Must2

func Must2[T any, V any](a T, b V, err error) (T, V)

func Must3

func Must3[T, U, V any](a T, b U, c V, err error) (T, U, V)

func MustBeNonNil

func MustBeNonNil[T any](o T) T

func MustBeSuccessful

func MustBeSuccessful(actual ...interface{})

func MustBeSuccessfulWithOffset

func MustBeSuccessfulWithOffset(offset int, err error)

func MustFailWithMessage

func MustFailWithMessage(err error, msg string)

func MustWithOffset

func MustWithOffset[T any](offset int, res result[T]) T

func NotNil

func NotNil[T any](o T, extra ...interface{}) T

func PingTCPServer

func PingTCPServer(address string, dur time.Duration) error

func R

func R[T any](o T, err error) result[T]

func StringEqualTrimmedWithContext

func StringEqualTrimmedWithContext(expected string, subst ...substutils.Substitution) types.GomegaMatcher

StringEqualTrimmedWithContext compares two trimmed strings and provides the complete actual value as error context. If value mappings are given, the expected string is evaluated by envsubst, first. It is an error for actual to be nil. Use BeNil() instead.

func StringEqualWithContext

func StringEqualWithContext(expected string, subst ...substutils.Substitution) types.GomegaMatcher

StringEqualWithContext compares two strings and provides the complete actual value as error context. If value mappings are given, the expected string is evaluated by envsubst, first. It is an error for actual to be nil. Use BeNil() instead.

func StringMatchTrimmedWithContext

func StringMatchTrimmedWithContext(expected string, subst ...substutils.Substitution) types.GomegaMatcher

StringMatchTrimmedWithContext matches a trimmed string by a regular expression and provides the complete actual value as error context. If value mappings are given, the expected string is evaluated by envsubst, first. It is an error for actual to be nil. Use BeNil() instead.

func StringMatchWithContext

func StringMatchWithContext(expected string, subst ...substutils.Substitution) types.GomegaMatcher

StringMatchWithContext matches a string by a regular expression and provides the complete actual value as error context. If value mappings are given, the expected string is evaluated by envsubst, first. It is an error for actual to be nil. Use BeNil() instead.

func YAMLEqual

func YAMLEqual(expected interface{}, subst ...substutils.Substitution) types.GomegaMatcher

YAMLEqual compares two yaml structures. If value mappings are given, the expected string is evaluated by envsubst, first. It is an error for actual to be nil. Use BeNil() instead.

Types

type DeepEqualMatcher

type DeepEqualMatcher struct {
	Expected interface{}
}

func (*DeepEqualMatcher) FailureMessage

func (matcher *DeepEqualMatcher) FailureMessage(actual interface{}) (message string)

func (*DeepEqualMatcher) Match

func (matcher *DeepEqualMatcher) Match(actual interface{}) (success bool, err error)

func (*DeepEqualMatcher) NegatedFailureMessage

func (matcher *DeepEqualMatcher) NegatedFailureMessage(actual interface{}) (message string)

type DirContent

type DirContent interface {
	Copy(path string) error
}

func WithDirContent

func WithDirContent(src string, dst ...string) DirContent

WithDirContent populates the temporary directory with some content provided by a directory. Optionally a target path can be given. The target path MUST be a path in the temporary directory. If an absolute path is given it is used relative to the temporary directory.

func WithFileContent

func WithFileContent(src string, dst ...string) DirContent

WithFileContent populates the temporary directory with some file. The name of the given file is preserved. Optionally a target path can be given. The target path MUST be a path in the temporary directory. If an absolute path is given it is used relative to the temporary directory.

type StringEqualMatcher

type StringEqualMatcher struct {
	Expected string
	Trim     bool
	Regex    bool
}

func (*StringEqualMatcher) FailureMessage

func (matcher *StringEqualMatcher) FailureMessage(actual interface{}) (message string)

func (*StringEqualMatcher) Match

func (matcher *StringEqualMatcher) Match(actual interface{}) (success bool, err error)

func (*StringEqualMatcher) NegatedFailureMessage

func (matcher *StringEqualMatcher) NegatedFailureMessage(actual interface{}) (message string)

type Substitutions

type Substitutions = substutils.SubstitutionMap

func SubstFrom

func SubstFrom(v interface{}, prefix ...string) Substitutions

func SubstList deprecated

func SubstList(values ...string) Substitutions

Deprecated: use substutils.SubstList.

type TempDir

type TempDir interface {
	Path() string
	Cleanup() error
}

TempDir is the representation of a temporary directory in the OS filesystem, which has a Cleanup method used to remove the directory, again, after a test.

func NewTempDir

func NewTempDir(content ...DirContent) (TempDir, error)

NewTempDir creates a new temporary directory with some initial content.

type YAMLEqualMatcher

type YAMLEqualMatcher struct {
	Expected interface{}
}

func (*YAMLEqualMatcher) FailureMessage

func (matcher *YAMLEqualMatcher) FailureMessage(actual interface{}) (message string)

func (*YAMLEqualMatcher) Match

func (matcher *YAMLEqualMatcher) Match(actual interface{}) (success bool, err error)

func (*YAMLEqualMatcher) NegatedFailureMessage

func (matcher *YAMLEqualMatcher) NegatedFailureMessage(actual interface{}) (message string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳