unittest

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsExecution added in v1.3.0

func IsExecution(err error) bool

IsExecution asserts executionError.

func ProjectRoot added in v1.10.0

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
}

type Marshaller added in v1.7.0

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. AWSConfig) 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 added in v1.3.0

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