testutils

package
v1.15.0-beta3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// TearDown is used to TearDown assets after a test completes. This is used in kube2e tests to uninstall
	// Gloo after a test suite completes
	TearDown = "TEAR_DOWN"

	// SkipInstall can be used when running Kube suites consecutively, and you didnt tear down the Gloo
	// installation from a previous run
	SkipInstall = "SKIP_INSTALL"

	// KubeTestType is used to indicate which kube2e suite should be run while executing regression tests
	KubeTestType = "KUBE2E_TESTS"

	// InvalidTestReqsEnvVar is used to define the behavior for running tests locally when the provided requirements
	// are not met. See ValidateRequirementsAndNotifyGinkgo for a detail of available behaviors
	InvalidTestReqsEnvVar = "INVALID_TEST_REQS"

	// RunKubeTests is used to enable any tests which depend on Kubernetes. NOTE: Kubernetes back tests should
	// be written into the kube2e suites, and those don't require this guard.
	RunKubeTests = "RUN_KUBE_TESTS"

	// RunVaultTests is used to enable any tests which depend on Vault.
	RunVaultTests = "RUN_VAULT_TESTS"

	// RunConsulTests is used to enable any tests which depend on Consul.
	RunConsulTests = "RUN_CONSUL_TESTS"

	// WaitOnFail is used to halt execution of a failed test to give the developer a chance to inspect
	// any assets before they are cleaned up when the test completes
	// This functionality is defined: https://github.com/solo-io/solo-kit/blob/main/test/helpers/fail_handler.go
	// and for it to be available, a test must have registered the custom fail handler using `RegisterCommonFailHandlers`
	WaitOnFail = "WAIT_ON_FAIL"

	// SkipTempDisabledTests is used to temporarily disable tests in CI
	// This should be used sparingly, and if you disable a test, you should create a Github issue
	// to track re-enabling the test
	SkipTempDisabledTests = "SKIP_TEMP_DISABLED"

	// EnvoyImageTag is used in e2e tests to specify the tag of the docker image to use for the tests
	// If a tag is not provided, the tests dynamically identify the latest released tag to use
	EnvoyImageTag = "ENVOY_IMAGE_TAG"
)

Variables

View Source
var DefaultHttpClient = &http.Client{
	Timeout: time.Second * 2,
}

DefaultHttpClient should be used in tests because it configures a timeout which the http.DefaultClient does not have

Please note that when the server response time exceeds the client timeout, you may hit the following error:

"Client.Timeout exceeded while awaiting headers"

The solution would be to increase the client timeout defined below. We chose 2 seconds as a reasonable default which allows tests to pass consistently.

Functions

func IsEnvTruthy

func IsEnvTruthy(envVarName string) bool

IsEnvTruthy returns true if a given environment variable has a truthy value Examples of truthy values are: "1", "t", "T", "true", "TRUE", "True". Anything else is considered false.

func ShouldRunKubeTests

func ShouldRunKubeTests() bool

ShouldRunKubeTests returns true if any tests which require a Kubernetes cluster should be executed This may guard tests which are run using our old CloudBuilder infrastructure. In the future, all kube tests should be written in our Kube2e suites, which are run with a kubernetes cluster

func ShouldSkipInstall

func ShouldSkipInstall() bool

ShouldSkipInstall returns true if any assets that need to be created before a test (for example Gloo being installed) should be skipped. This is typically used in tandem with ShouldTearDown when running consecutive tests and skipping both the tear down and install of Gloo Edge.

func ShouldSkipTempDisabledTests

func ShouldSkipTempDisabledTests() bool

ShouldSkipTempDisabledTests returns true if temporarily disabled tests should be skipped

func ShouldTearDown

func ShouldTearDown() bool

ShouldTearDown returns true if any assets that were created before a test (for example Gloo being installed) should be torn down after the test.

func ValidateRequirements

func ValidateRequirements(requirements []Requirement) error

ValidateRequirements returns an error if any of the Requirements are not met

func ValidateRequirementsAndNotifyGinkgo

func ValidateRequirementsAndNotifyGinkgo(requirements ...Requirement)

ValidateRequirementsAndNotifyGinkgo validates that the provided Requirements are met, and if they are not, uses the InvalidTestReqsEnvVar to determine how to proceed: Options are:

  • `run`: Ignore any invalid requirements and execute the tests
  • `skip`: Notify Ginkgo that the current spec was skipped
  • `fail`: Notify Ginkgo that the current spec has failed [DEFAULT]

Types

type HttpClientBuilder

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

HttpClientBuilder simplifies the process of generating an http client in tests

func DefaultClientBuilder

func DefaultClientBuilder() *HttpClientBuilder

DefaultClientBuilder returns an HttpClientBuilder with some default values

func (*HttpClientBuilder) Build

func (c *HttpClientBuilder) Build() *http.Client

func (*HttpClientBuilder) Clone

func (*HttpClientBuilder) WithProxyProtocolBytes

func (c *HttpClientBuilder) WithProxyProtocolBytes(bytes []byte) *HttpClientBuilder

func (*HttpClientBuilder) WithTLSRootCa

func (c *HttpClientBuilder) WithTLSRootCa(rootCaCert string) *HttpClientBuilder

func (*HttpClientBuilder) WithTLSServerName

func (c *HttpClientBuilder) WithTLSServerName(serverName string) *HttpClientBuilder

func (*HttpClientBuilder) WithTimeout

func (c *HttpClientBuilder) WithTimeout(timeout time.Duration) *HttpClientBuilder

type HttpRequestBuilder

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

HttpRequestBuilder simplifies the process of generating http requests in tests

func DefaultRequestBuilder

func DefaultRequestBuilder() *HttpRequestBuilder

DefaultRequestBuilder returns an HttpRequestBuilder with some default values

func (*HttpRequestBuilder) Build

func (h *HttpRequestBuilder) Build() *http.Request

func (*HttpRequestBuilder) Clone

func (*HttpRequestBuilder) WithAcceptEncoding

func (h *HttpRequestBuilder) WithAcceptEncoding(acceptEncoding string) *HttpRequestBuilder

func (*HttpRequestBuilder) WithBody

func (h *HttpRequestBuilder) WithBody(body string) *HttpRequestBuilder

func (*HttpRequestBuilder) WithContentType

func (h *HttpRequestBuilder) WithContentType(contentType string) *HttpRequestBuilder

func (*HttpRequestBuilder) WithContext

func (*HttpRequestBuilder) WithHeader

func (h *HttpRequestBuilder) WithHeader(key, value string) *HttpRequestBuilder

WithHeader accepts a list of header values, separated by the headerDelimiter To set a single value for a header, call:

WithHeader(`headerName`, `value1`)

To set multiple values for a header, call:

WithHeader(`headerName`, `value1,value2`)

func (*HttpRequestBuilder) WithHost

func (h *HttpRequestBuilder) WithHost(host string) *HttpRequestBuilder

func (*HttpRequestBuilder) WithHostname

func (h *HttpRequestBuilder) WithHostname(hostname string) *HttpRequestBuilder

func (*HttpRequestBuilder) WithOptionsMethod

func (h *HttpRequestBuilder) WithOptionsMethod() *HttpRequestBuilder

func (*HttpRequestBuilder) WithPath

func (h *HttpRequestBuilder) WithPath(path string) *HttpRequestBuilder

func (*HttpRequestBuilder) WithPort

func (h *HttpRequestBuilder) WithPort(port uint32) *HttpRequestBuilder

func (*HttpRequestBuilder) WithPostBody

func (h *HttpRequestBuilder) WithPostBody(body string) *HttpRequestBuilder

WithPostBody is syntactic sugar for updating the Method and Body for a POST request simultaneously

func (*HttpRequestBuilder) WithPostMethod

func (h *HttpRequestBuilder) WithPostMethod() *HttpRequestBuilder

func (*HttpRequestBuilder) WithScheme

func (h *HttpRequestBuilder) WithScheme(scheme string) *HttpRequestBuilder

type RequiredConfiguration

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

func (RequiredConfiguration) Validate

func (r RequiredConfiguration) Validate() error

Validate returns an error is the RequiredConfiguration is not met

type Requirement

type Requirement func(configuration *RequiredConfiguration)

Requirement represents a required property for tests.

func AwsCredentials

func AwsCredentials() Requirement

AwsCredentials returns a Requirement that expects tests to require Aws credentials

func Consul

func Consul() Requirement

Consul returns a Requirement that expects tests to require a Consul instance

func DefinedEnv

func DefinedEnv(env string) Requirement

DefinedEnv returns a Requirement that expects tests to have the injected environment variable defined

func Kubernetes

func Kubernetes(reason string) Requirement

Kubernetes returns a Requirement that expects tests to require Kubernetes configuration

func LinuxOnly

func LinuxOnly(reason string) Requirement

LinuxOnly returns a Requirement that expects tests to only run on Linux

func TruthyEnv

func TruthyEnv(env string) Requirement

TruthyEnv returns a Requirement that expects tests to have the injected environment variable set to a truthy value

func Vault

func Vault() Requirement

Vault returns a Requirement that expects tests to require a Vault instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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