testutils

package
v1.16.0-beta9 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 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"

	// 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"

	// EnvoyBinary is used in e2e tests to specify the path to the envoy binary to use for the tests
	EnvoyBinary = "ENVOY_BINARY"

	// ConsulBinary is used in e2e tests to specify the path to the consul binary to use for the tests
	ConsulBinary = "CONSUL_BINARY"

	// VaultBinary is used in e2e tests to specify the path to the vault binary to use for the tests
	VaultBinary = "VAULT_BINARY"

	// ServiceLogLevel is used to set the log level for the test services. See services/logging.go for more details
	ServiceLogLevel = "SERVICE_LOG_LEVEL"

	// GithubAction is used by Github Actions and is the name of the currently running action or ID of a step
	// https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
	GithubAction = "GITHUB_ACTION"

	// GcloudBuildId is used by Cloudbuild to identify the build id
	// This is set when running tests in Cloudbuild
	GcloudBuildId = "GCLOUD_BUILD_ID"

	// ReleasedVersion can be used when running KubeE2E tests to have the test suite use a previously released version of Gloo Edge
	// If set to 'LATEST', the most recently released version will be used
	// If set to another value, the test suite will use that version (ie '1.15.0-beta1')
	// This is an optional value, so if it is not set, the test suite will use the locally built version of Gloo Edge
	ReleasedVersion = "RELEASED_VERSION"
)

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. Since http.Client caches TCP connections, it is advised to create a new client via DefaultClientBuilder().Build() each time while testing any feature that operates at L4 to avoid TCP connection caching issues.

Functions

func IsEnvDefined added in v1.15.0

func IsEnvDefined(envVarName string) bool

IsEnvDefined returns true if a given environment variable has any value

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 IsRunningInCloudbuild added in v1.15.0

func IsRunningInCloudbuild() bool

IsRunningInCloudbuild returns true if tests are running in Cloudbuild

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 Since http.Client caches TCP connections, it is advised to create a new client each time while testing any feature that operates at L4.

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) WithRawHeader added in v1.15.0

func (h *HttpRequestBuilder) WithRawHeader(key string, values ...string) *HttpRequestBuilder

WithRawHeader accepts multiple header values for a key. Unlike WithHeader, it does not split the value by a headerDelimiter (,) and instead allows for N values to be set as-is.

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 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