testing

package
v1.1.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const TestEnvVar = "VAULT_ACC"

TestEnvVar must be set to a non-empty value for acceptance tests to run.

Variables

This section is empty.

Functions

func Test

func Test(tt TestT, c TestCase)

Test performs an acceptance test on a backend with the given test case.

Tests are not run unless an environmental variable "VAULT_ACC" is set to some non-empty value. This is to avoid test cases surprising a user by creating real resources.

Tests will fail unless the verbose flag (`go test -v`, or explicitly the "-test.v" flag) is set. Because some acceptance tests take quite long, we require the verbose flag so users are able to see progress output.

Types

type PreFlightFunc added in v0.5.1

type PreFlightFunc func(*logical.Request) error

PreFlightFunc is used to modify request parameters directly before execution in each TestStep.

type TestCase

type TestCase struct {
	// Precheck, if non-nil, will be called once before the test case
	// runs at all. This can be used for some validation prior to the
	// test running.
	PreCheck func()

	// LogicalBackend is the backend that will be mounted.
	LogicalBackend logical.Backend

	// LogicalFactory can be used instead of LogicalBackend if the
	// backend requires more construction
	LogicalFactory logical.Factory

	// CredentialBackend is the backend that will be mounted.
	CredentialBackend logical.Backend

	// CredentialFactory can be used instead of CredentialBackend if the
	// backend requires more construction
	CredentialFactory logical.Factory

	// Steps are the set of operations that are run for this test case.
	Steps []TestStep

	// Teardown will be called before the test case is over regardless
	// of if the test succeeded or failed. This should return an error
	// in the case that the test can't guarantee all resources were
	// properly cleaned up.
	Teardown TestTeardownFunc

	// AcceptanceTest, if set, the test case will be run only if
	// the environment variable VAULT_ACC is set. If not this test case
	// will be run as a unit test.
	AcceptanceTest bool
}

TestCase is a single set of tests to run for a backend. A TestCase should generally map 1:1 to each test method for your acceptance tests.

type TestCheckFunc

type TestCheckFunc func(*logical.Response) error

TestCheckFunc is the callback used for Check in TestStep.

func TestCheckAuth

func TestCheckAuth(policies []string) TestCheckFunc

TestCheckAuth is a helper to check that a request generated an auth token with the proper policies.

func TestCheckAuthDisplayName

func TestCheckAuthDisplayName(n string) TestCheckFunc

TestCheckAuthDisplayName is a helper to check that a request generated a valid display name.

func TestCheckError

func TestCheckError() TestCheckFunc

TestCheckError is a helper to check that a response is an error.

func TestCheckMulti

func TestCheckMulti(fs ...TestCheckFunc) TestCheckFunc

TestCheckMulti is a helper to have multiple checks.

type TestStep

type TestStep struct {
	// Operation is the operation to execute
	Operation logical.Operation

	// Path is the request path. The mount prefix will be automatically added.
	Path string

	// Arguments to pass in
	Data map[string]interface{}

	// Check is called after this step is executed in order to test that
	// the step executed successfully. If this is not set, then the next
	// step will be called
	Check TestCheckFunc

	// PreFlight is called directly before execution of the request, allowing
	// modification of the request parameters (e.g. Path) with dynamic values.
	PreFlight PreFlightFunc

	// ErrorOk, if true, will let erroneous responses through to the check
	ErrorOk bool

	// Unauthenticated, if true, will make the request unauthenticated.
	Unauthenticated bool

	// RemoteAddr, if set, will set the remote addr on the request.
	RemoteAddr string

	// ConnState, if set, will set the tls connection state
	ConnState *tls.ConnectionState
}

TestStep is a single step within a TestCase.

type TestT

type TestT interface {
	Error(args ...interface{})
	Fatal(args ...interface{})
	Skip(args ...interface{})
}

TestT is the interface used to handle the test lifecycle of a test.

Users should just use a *testing.T object, which implements this.

type TestTeardownFunc

type TestTeardownFunc func() error

TestTeardownFunc is the callback used for Teardown in TestCase.

Jump to

Keyboard shortcuts

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