barrier

package module
v0.0.0-...-797aa23 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

README

barrier

barrier is a Golang based test runner library that allows to create integration tests easily.

Go's inbuilt testing go test is great for unit tests but when you need to test a process/micro-service one could benefit from a test runner library like this one.

This library can be used to create a test cli in a second and let you focus on writing simple tests.

Look at examples

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(t TestInfo, message string, actual interface{}, f func(interface{}, ...interface{}) string, expected ...interface{})

Assert can use goconvey function to perform an assertion.

func NewCommand

func NewCommand(
	name string,
	description string,
	version string,
	stash GenerateStash,
) *cobra.Command

NewCommand generates a new CLI

func RegisterTest

func RegisterTest(t Test)

RegisterTest register a test in the main suite.

func Step

func Step(t TestInfo, name string, step func() error)

Step runs a particular step.

Types

type Cleanup

type Cleanup func() error

Cleanup is a function type used for cleaning up.

type GenerateStash

type GenerateStash func(context.Context) interface{}

GenerateStash is a type of function that returns a generated stash.

type SetupFunction

type SetupFunction func(context.Context, TestInfo) (interface{}, TearDownFunction, error)

SetupFunction is the type of function that can be run a a test setup. The returned data will be available to the main test function using TestInfo.SetupInfo() function. The returned function will be run at the end of the test.

If SetupFunction returns an error, the entire suite of test is stopped.

type SetupSuiteFunction

type SetupSuiteFunction func(context.Context, SuiteInfo) (interface{}, TearDownFunction, error)

SetupSuiteFunction is the type of function that can be run from a suite setup. The returned data will be available to the main test function using TestInfo.SuiteSetupInfo() function. The returned function will be run at the end of the suite.

If SetupSuiteFunction returns an error, the entire suite of test is stopped.

type Suite

type Suite struct {
	Name        string
	Description string
	Setup       SetupSuiteFunction
}

Suite is a collection of tests

type SuiteInfo

type SuiteInfo interface {
	// Register a test into a suite
	RegisterTest(t Test)
	// Write performs a write
	Write(p []byte) (n int, err error)
}

SuiteInfo is the interface for the test writer

func RegisterSuite

func RegisterSuite(s Suite) SuiteInfo

RegisterSuite registers a test suite.

type TearDownFunction

type TearDownFunction func()

A TearDownFunction is the type of function returned by a SetupFunction or SetupSuiteFunction.

type Test

type Test struct {
	Name        string
	Description string
	Author      string
	Tags        []string
	Setup       SetupFunction
	Function    TestFunction
	SuiteName   string
	// contains filtered or unexported fields
}

A Test represents an actual test.

func (Test) String

func (t Test) String() string

type TestFunction

type TestFunction func(context.Context, TestInfo) error

A TestFunction is the type of a function that is run by a Test.

type TestInfo

type TestInfo struct {
	// contains filtered or unexported fields
}

A TestInfo contains various information about a test.

func (TestInfo) Iteration

func (t TestInfo) Iteration() int

Iteration returns the test iteration number.

func (TestInfo) SetupInfo

func (t TestInfo) SetupInfo() interface{}

SetupInfo returns the eventual object stored by the Setup function.

func (TestInfo) Stash

func (t TestInfo) Stash() interface{}

Stash provides the callers data that may store configs/runtime they need

func (TestInfo) SuiteSetupInfo

func (t TestInfo) SuiteSetupInfo() interface{}

SuiteSetupInfo returns the eventual object stored by the Suite Setup function.

func (TestInfo) TestID

func (t TestInfo) TestID() string

TestID returns the test ID

func (TestInfo) TimeSinceLastStep

func (t TestInfo) TimeSinceLastStep() string

TimeSinceLastStep provides the time since last step or assertion

func (TestInfo) Timeout

func (t TestInfo) Timeout() time.Duration

Timeout provides the duration before the test timeout.

func (TestInfo) Write

func (t TestInfo) Write(p []byte) (n int, err error)

Write performs a write

func (TestInfo) WriteHeader

func (t TestInfo) WriteHeader(p []byte) (n int, err error)

WriteHeader performs a write at the header

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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