testutil

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const AdminToken = "123e4567-e89b-12d3-a456-426614174000"

Variables

This section is empty.

Functions

func AuthMethodInit added in v0.5.0

func AuthMethodInit(t *testing.T, consulClient *api.Client, expectedServiceName, authMethodName string) *httptest.Server

AuthMethodInit sets up necessary pieces for the IAM auth method:

  • Start a fake AWS server. This responds with an IAM role tagged with expectedServiceName.
  • Configures an auth method + binding rule that uses the tagged service name from the IAM role for the service identity.
  • Sets the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to dummy values.

When using this, you will also need to point the login command at the fake AWS server, for example:

fakeAws := authMethodInit(...)
consulLogin.ExtraLoginFlags = []string{"-aws-sts-endpoint", fakeAws.URL + "/sts"}

func BoolPtr added in v0.7.0

func BoolPtr(v bool) *bool

func ConsulACLConfigFn

func ConsulACLConfigFn(c *testutil.TestServerConfig)

ConsulACLConfigFn configures a Consul test server with ACLs.

func ConsulServer

func ConsulServer(t *testing.T, cb ServerConfigCallback) (*testutil.TestServer, *api.Config)

ConsulServer initializes a Consul test server and returns Consul client config and the configured test server

func EnterpriseFlag added in v0.5.0

func EnterpriseFlag() bool

EnterpriseFlag indicates whether or not the test was invoked with the -enterprise command line argument.

func GetHostAndPortFromAddress added in v0.7.0

func GetHostAndPortFromAddress(address string) (string, int)

func SetECSConfigEnvVar

func SetECSConfigEnvVar(t *testing.T, val interface{})

SetECSConfigEnvVar the CONSUL_ECS_CONFIG_JSON environment variable to the JSON string of the provided value, with a test cleanup.

func TaskMetaHandler

func TaskMetaHandler(t *testing.T, resp string) http.Handler

TaskMetaHandler returns an http.Handler that always responds with the given string for the 'GET /task' request of the ECS Task Metadata server.

func TaskMetaHandlerFn

func TaskMetaHandlerFn(t *testing.T, respFn func() string) http.Handler

TaskMetaHandler wraps the respFn in an http.Handler for the ECS Task Metadata server. respFn should return a response to the 'GET /task' request.

func TaskMetaServer

func TaskMetaServer(t *testing.T, handler http.Handler)

TaskMetaServer starts a local HTTP server to mimic the ECS Task Metadata server. This sets ECS_CONTAINER_METADATA_URI_V4 and configures a test cleanup. Because of the environment variable, this is unsafe for running tests in parallel.

func TempDir

func TempDir(t *testing.T) string

TempDir creates a temporary directory. A test cleanup removes the directory and its contents.

Types

type FakeCommand added in v0.5.0

type FakeCommand struct {
	// The command to run.
	Command string
	// Check this file exists to check the command is ready.
	ReadyFile string
}

FakeCommand is a command/script to be run by tests for "entrypoint" commands. Each command touches a "ready file" after the command has started and completed setup. This enables the tests to ensure the command has started in order to avoid race conditions. For example, certain tests should not proceed until signal handling has been set up.

func FakeCommandWithTraps added in v0.5.0

func FakeCommandWithTraps(t *testing.T, sleep int) FakeCommand

FakeCommandWithTraps is a script used to validate our "entrypoint" commands. This script does the following: * When a sigint is received, it exits with code 42 * When a sigterm is received, it exits with code 55 * It sleeps for 120 seconds (long enough for tests, but not so long that it holds up CI)

Why not just a simple 'sleep 120'? * Bash actually ignores SIGINT by default (note: CTRL-C sends SIGINT to the process group, not just the parent) * Tests can be run in different places, so /bin/sh could be any shell with different behavior. Why a background process + wait? Why not just a trap + sleep? * The sleep blocks the trap. Traps are not executed until the current command completes, except for `wait`.

func SimpleFakeCommand added in v0.5.0

func SimpleFakeCommand(t *testing.T, sleep int) FakeCommand

SimpleFakeCommand sleeps for a given number of seconds.

type ServerConfigCallback added in v0.5.0

type ServerConfigCallback = testutil.ServerConfigCallback

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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