unittest

package
v2.4.1-0...-eb90050 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProviderFlavors = []string{capiFlavor, vintageFlavor}

Functions

func EquateErrors

func EquateErrors() cmp.Option

EquateErrors returns true if the supplied errors are of the same type and produce identical strings. This mirrors the error comparison behaviour of https://github.com/go-test/deep,

This differs from cmpopts.EquateErrors, which does not test for error strings and instead returns whether one error 'is' (in the errors.Is sense) the other.

func IsExecution

func IsExecution(err error) bool

IsExecution asserts executionError.

func ProjectRoot

func ProjectRoot() string

ProjectRoot returns absolute path to prometheus-meta-operator root directory. This comes in handy when you need to access files in this repository from a test.

Types

type Config

type Config struct {
	OutputDir            string
	T                    *testing.T
	Marshaller           Marshaller
	TestFunc             TestFunc
	TestFuncReturnsBytes bool
	Update               bool
	Flavor               string
}

type Marshaller

type Marshaller func(o interface{}) ([]byte, error)

type Runner

type Runner struct {
	OutputDir            string
	T                    *testing.T
	Marshaller           Marshaller
	TestFunc             TestFunc
	TestFuncReturnsBytes bool
	Update               bool
	// contains filtered or unexported fields
}

Runner is used to run unit test for a specific resource. It does so by running TestFunc with different input and compare the result with expected outputs.

TestFunc is a function which takes the observed kubernetes object as input (e.g. Cluster) and returns another kubernetes object (e.g. Service).

OutputDir holds yaml files, representing the yaml version of the object returned by TestFunc. Files are mapped 1 to 1 from input to output directory. e.g. when a file called `foo` is placed in the input directory, a corresponding file named `foo` must be placed in the output directory.

Input directory is harcoded as the input directory in this package.

func NewRunner

func NewRunner(config Config) (*Runner, error)

NewRunner creates a new Runner given a Config.

func (*Runner) Run

func (r *Runner) Run() error

Run execute all the test using testing/T.Run function.

type TestFunc

type TestFunc func(interface{}) (interface{}, error)

type Value

type Value struct {
	Name   string
	Input  pkgruntime.Object
	Output []byte
}

Value represents a test case. Name is the name of the test case. Input is the input kubernetes object. Output is the expected output.

Jump to

Keyboard shortcuts

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