e2e

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

README

E2E testing

$ source .ate-dev-env.sh
$ go test -v ./internal/e2e/suites/... -args -e2e

Principles

  • Keep it simple -- use go test for the harness.
  • e2e tests live under internal/e2e/suites/<suite>
  • Each suite should implement TestMain using e2e.RunTestMain()
    • e2e tests will be skipped for ordinary unit tests unless the -e2e flag is set e.g. go test ./internal/e2e/suites/... -args -e2e
  • Helper libraries live under internal/e2e
  • Setup and Teardown are on a per-component basis and the component's author's responsibility.

Preconditions

The e2e tests assume you have a cluster setup with hack/install.sh.

Creating a new test suite

Copy testmain_test.go from internal/e2e/suites/example into your new suite. It will look like this:

func run(m *testing.M) int {
	Setup()
	defer Teardown()
	// return allows the deferred Teardown to run.
	return e2e.RunTestMain(m)
}

func TestMain(m *testing.M) { os.Exit(run(m)) }

This will handle the standard flags and checks for running an e2e test suite.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RunE2E      bool
	KubeConfig  string
	KubeContext string
)
View Source
var (
	NoColor bool
)

noColor() disables colors for tests running in environments without colored output.

Functions

func CheckEnv

func CheckEnv(keys ...string) (map[string]string, error)

CheckEnv checks the list of env vars exist and returns their value. If any env var is not set, it returns an error.

func CleanupNamespaces

func CleanupNamespaces()

CleanupNamespaces deletes all registered namespaces using the K8s API. This should be called at the end of RunTestMain.

func Colorf

func Colorf(format string, a ...any) string

Colorf renders a formatted string with color directives:

"Example text: <green>this is green</green>".

Unterminated directives will be treated as literals.

func FColorf

func FColorf(f io.Writer, format string, a ...any) error

FColorf writes a formatted string with color directives to the given writer.

func FColorfln

func FColorfln(f io.Writer, format string, a ...any) error

FColorfln writes a formatted string with color directives to the given writer, followed by a newline.

func FindRepoRoot

func FindRepoRoot() (string, error)

FindRepoRoot traverses directories upward starting from the current working directory to locate the repository root containing the go.mod file.

func PreflightChecks

func PreflightChecks() error

PreflightChecks checks that the test environment is ready for the test suite.

func RunCmd

func RunCmd(t *testing.T, name string, args ...string)

RunCmd executes the given command with arguments, piping stdout and stderr to standard outputs, and fails the test if the command returns an error.

func RunCmdWithEnv

func RunCmdWithEnv(t *testing.T, env []string, name string, args ...string)

RunCmdWithEnv executes the given command with custom environment variables appended to the current process environment, and fails the test if it returns an error.

func RunTestMain

func RunTestMain(m *testing.M) int

RunTestMain should be used to run your e2e test suite.

Types

type Clients

type Clients struct {
	K8s          *kubernetes.Clientset
	CRD          *apiextensionsclientset.Clientset
	SubstrateK8s *versioned.Clientset
	SubstrateAPI *client.Client
}

func GetClients

func GetClients() *Clients

GetClients returns the shared E2E clients. It panics if the clients have not been initialized.

func NewClients

func NewClients(ctx context.Context) (*Clients, error)

func (*Clients) Close

func (c *Clients) Close()

type ColorWriter

type ColorWriter struct {
	W    io.Writer
	ANSI string
}

ColorWriter wraps an io.Writer and forces all writes to be colored with the given ANSI code. It respects noColor().

func (*ColorWriter) Write

func (cw *ColorWriter) Write(p []byte) (n int, err error)

Write writes p to the underlying writer, wrapped in the ANSI color code and reset code.

type IndentWriter

type IndentWriter struct {
	W   io.Writer
	Val string
	// contains filtered or unexported fields
}

IndentWriter wraps an io.Writer and indents each line of output.

func NewIndentWriter

func NewIndentWriter(w io.Writer, indent string) *IndentWriter

NewIndentWriter creates a new IndentWriter.

func (*IndentWriter) Write

func (iw *IndentWriter) Write(p []byte) (n int, err error)

Write writes p to the underlying writer, inserting the indent string at the start of each line.

type Namespace

type Namespace struct {
	Name string
}

func CreateNamespace

func CreateNamespace(t *testing.T) *Namespace

CreateNamespace creates a new namespace with a randomized name using the K8s API and registers it for cleanup at the end of the test.

func (*Namespace) Delete

func (ns *Namespace) Delete(t *testing.T)

Delete the namespace explicitly. This will fail the test if deletion fails.

Jump to

Keyboard shortcuts

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