testutils

package
v0.82.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package testutils provides utility functions for testing. It also allows recording tests, both their input and expected output. The recorded test is then saved to a JSON file which is provided by the NOBL9_SDK_TEST_RECORD_FILE environment variable. The env variable should be an absolute path, otherwise every package will have a separate file created.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContainsErrors

func AssertContainsErrors(
	t *testing.T,
	object interface{},
	objErr *v1alpha.ObjectError,
	expectedErrorsCount int,
	expectedErrors ...ExpectedError,
)

AssertContainsErrors asserts that the given object has: - the expected number of errors - at least one error which matches ExpectedError

ExpectedError and actual error are considered equal if they point at the same property and either: - validation.ErrorCode are equal - error messages re equal - ExpectedError.ContainsMessage is contained in actual error message

nolint: gocognit

func AssertNoError

func AssertNoError(t *testing.T, object interface{}, objErr *v1alpha.ObjectError)

AssertNoError asserts that the provided v1alpha.ObjectError is nil.

func FindModuleRoot added in v0.82.0

func FindModuleRoot() string

FindModuleRoot returns the absolute path to the modules root.

Types

type ExpectedError

type ExpectedError struct {
	Prop            string `json:"property"`
	Code            string `json:"code,omitempty"`
	Message         string `json:"message,omitempty"`
	ContainsMessage string `json:"containsMessage,omitempty"`
	IsKeyError      bool   `json:"isKeyError,omitempty"`
}

func PrependPropertyPath

func PrependPropertyPath(errs []ExpectedError, path string) []ExpectedError

Jump to

Keyboard shortcuts

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