testhelper

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OnlyDiff = flag.Bool(
	"onlyDiff",
	false,
	"only show diff where possible -- skip printing out actual/expected",
)

OnlyDiff is a bool flag that indicates if the test fail output should only include the diff where possible.

View Source
var SkipCleanup = flag.Bool(
	"skipCleanup",
	false,
	"skip cleaning up namespaces",
)

SkipCleanup is a bool flag that indicates if the e2e tests should skip clean up or not, by default this is *false* (as in we clean things up).

View Source
var Update = flag.Bool("update", false, "update the golden files") //nolint: gochecknoglobals

Update is the flag indicating if golden files should be updated when running tests.

Functions

func Execute added in v0.0.17

func Execute(t *testing.T, cmd *exec.Cmd) []byte

Execute executes a command in the context of a test.

func FailOutput

func FailOutput(t *testing.T, actual, expected any)

FailOutput is a simple func to nicely print actual vs expected output when a test fails.

func Flags

func Flags()

Flags handles parsing clabernetes test flags.

func HelmCommand added in v0.0.17

func HelmCommand(t *testing.T, chartsDir string, args ...string) []byte

HelmCommand executes helm with the given arguments.

func HelmTest added in v0.0.17

func HelmTest(t *testing.T, chartName, testName, namespace, valuesFileName, chartsDir string)

HelmTest executes a test against a helm chart -- this is a very simple/dumb test meant only to ensure that we don't accidentally screw up charts. We do this by storing the "golden" output of a rendered chart (and subcharts if applicable) with a given values file.

func KubectlCreateNamespace added in v0.0.17

func KubectlCreateNamespace(t *testing.T, namespace string)

KubectlCreateNamespace execs a kubectl create namespace.

func KubectlDeleteNamespace added in v0.0.17

func KubectlDeleteNamespace(t *testing.T, namespace string)

KubectlDeleteNamespace execs a kubectl delete namespace.

func KubectlFileOp added in v0.0.17

func KubectlFileOp(t *testing.T, operation Operation, namespace, fileName string)

KubectlFileOp execs a kubectl operation on a file (i.e. apply/delete).

func KubectlGetOp added in v0.0.17

func KubectlGetOp(t *testing.T, kind, namespace, name string) []byte

KubectlGetOp runs get on the given object, returning the yaml output.

func MarshaledEqual added in v0.0.17

func MarshaledEqual(t *testing.T, a, b any)

MarshaledEqual marshals (json marshal) a and b and bytes.Equal compares them. If they are not equal FailOutput is called.

func NewTestNamespace added in v0.0.17

func NewTestNamespace(testName string) string

NewTestNamespace generates a namespace for a test.

func NormalizeConnectivity added in v0.0.30

func NormalizeConnectivity(t *testing.T, objectData []byte) []byte

NormalizeConnectivity normalizes a connectivity cr between ci and local or other folks machines/clusters -- so we can compare results more easily. For now this is just replacing the namespace in the destinations since those will be random(ish) per test run.

func NormalizeDeployment added in v0.0.30

func NormalizeDeployment(t *testing.T, objectData []byte) []byte

NormalizeDeployment normalizes a deployment by removing fields that may change between ci and local or other folks machines/clusters (like image/registry)-- so we can compare results more easily.

func NormalizeExposeService added in v0.0.19

func NormalizeExposeService(t *testing.T, objectData []byte) []byte

NormalizeExposeService normalizes a service cr by removing fields that may change between ci and local or other folks machines/clusters -- so we can compare results more easily.

func NormalizeFabricService added in v0.0.30

func NormalizeFabricService(t *testing.T, objectData []byte) []byte

NormalizeFabricService normalizes a (fabric) service cr by removing fields that may change between ci and local or other folks machines/clusters -- so we can compare results more easily.

func NormalizeKubernetesObject added in v0.0.17

func NormalizeKubernetesObject(t *testing.T, object []byte) []byte

NormalizeKubernetesObject does some janky regex replace to remove controller generated fields we don't want to compare.

func NormalizeTopology added in v0.0.19

func NormalizeTopology(t *testing.T, objectData []byte) []byte

NormalizeTopology normalizes a clabernetes topology cr by removing fields that may change between ci and local or other folks machines/clusters -- so we can compare results more easily.

func ReadAllRenderedTemplates added in v0.0.17

func ReadAllRenderedTemplates(t *testing.T, rootRenderDir string) map[string][]byte

ReadAllRenderedTemplates loads all rendered template content into a map -- sub-charts are loaded with a "_subchart-<CHARTNAME>-" prefix.

func ReadTestFile added in v0.0.16

func ReadTestFile(t *testing.T, f string) []byte

ReadTestFile is a helper to read a (usually) golden file in the context of a test (hence testing.T).

func ReadTestFixtureFile added in v0.0.16

func ReadTestFixtureFile(t *testing.T, f string) []byte

ReadTestFixtureFile is a helper to read a test fixture file.

func WriteTestFile added in v0.0.16

func WriteTestFile(t *testing.T, f string, b []byte)

WriteTestFile is a helper to write json to the specified file in the context of a test.

func WriteTestFixtureFile added in v0.0.16

func WriteTestFixtureFile(t *testing.T, f string, b []byte)

WriteTestFixtureFile is a helper to write out a test fixture file.

func WriteTestFixtureJSON added in v0.0.16

func WriteTestFixtureJSON(t *testing.T, f string, o interface{})

WriteTestFixtureJSON is a helper to write JSON into a test fixture file.

func WriteTestJSON added in v0.0.16

func WriteTestJSON(t *testing.T, f string, o interface{})

WriteTestJSON is a helper to write JSON to the specified file in the context of a test.

func YQCommand added in v0.0.17

func YQCommand(t *testing.T, content []byte, yqPattern string) []byte

YQCommand accepts some yaml content and returns it after executing the given yqPattern against it.

Types

type Operation added in v0.0.17

type Operation string

Operation represents a kubectl operation type, i.e. apply or delete.

const (
	// Apply is the apply kubectl operation.
	Apply Operation = "apply"
	// Delete is the delete kubectl operation.
	Delete Operation = "delete"
	// Create is the create kubectl operation.
	Create Operation = "create"
	// Get is the get kubectl operation.
	Get Operation = "get"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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