acctest

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2020 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package acctest provides a small testing framework for Sherpa

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildBaseTaskGroup

func BuildBaseTaskGroup(group, task string) *nomad.TaskGroup

func BuildBaseTestJob

func BuildBaseTestJob(name string) *nomad.Job

func CheckErrEqual

func CheckErrEqual(expected string) func(error) bool

CheckErrEqual is a CheckErr func to test if an error message is as expected

func CheckJobReachesStatus

func CheckJobReachesStatus(s *TestState, status string) error

CheckJobReachesStatus performs a check, with a timeout that the test job reaches to desired status.

func CleanupPurgeJob

func CleanupPurgeJob(s *TestState) error

CleanupPurgeJob is a cleanup func to purge the TestCase job from Nomad

func CleanupSherpaPolicy

func CleanupSherpaPolicy(s *TestState) error

CleanupSherpaPolicy is a CleanupFunc to remove a single job policy

func IntToPointer

func IntToPointer(i int) *int

func StringToPointer

func StringToPointer(s string) *string

func Test

func Test(t *testing.T, c TestCase)

Test executes a single TestCase

Tests will be skipped if SHERPA_ACC is empty

Types

type TestCase

type TestCase struct {
	// Steps are ran in order stopping on failure
	Steps []TestStep

	// CleanupFuncs is called at the end of the TestCase if set
	CleanupFuncs []TestStateFunc
}

TestCase is a single test of Sherpa

type TestState

type TestState struct {
	// JobName is a concatenation of "sherpa" and the test function name
	JobName string

	Sherpa *api.Client
	Nomad  *nomad.Client
}

TestState is the configuration for the TestCase

type TestStateFunc

type TestStateFunc func(*TestState) error

TestStateFunc provides a TestStep with access to the test state

func CheckDeploymentStatus

func CheckDeploymentStatus(status string) TestStateFunc

CheckDeploymentStatus is a TestStateFunc to check if the latest deployment of the TestCase job in Nomad matches the desired status

func CheckTaskGroupCount

func CheckTaskGroupCount(groupName string, count int) TestStateFunc

CheckTaskGroupCount is a TestStateFunc to check a TaskGroup count matches the expected count

func ComposeTestStateFunc

func ComposeTestStateFunc(f ...TestStateFunc) TestStateFunc

ComposeTestStateFunc combines multiple TestStateFuncs into one

type TestStep

type TestStep struct {
	// Runner is used to execute the step
	Runner TestStateFunc

	// ExpectErr allows Runner to fail, use CheckErr to confirm error is correct
	ExpectErr bool

	// CheckErr is called if Runner fails and ExpectErr is true
	CheckErr func(error) bool
}

TestStep is a single step within a TestCase

Jump to

Keyboard shortcuts

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