kubetest

package
v0.0.0-...-61997fb Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package kubetest provides functionality to create local Kubernetes test clusters and run tests against them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInlineChart

func BuildInlineChart(t *testing.T, name, tmpl, values string) string

BuildInlineChart creates an inline chart string with the given name, template and values.

func DeploymentReady

func DeploymentReady(ctx context.Context, c client.Client, namespace, name string) error

DeploymentReady returns a condition func that checks whether all replicas of a deployment are available.

Types

type ClusterConfig

type ClusterConfig struct {
	Name string
}

type Config

type Config struct {
	// The clusters that are provisioned for the test environment.
	Clusters []ClusterConfig

	// Registration function for additional resource types to a scheme.
	SchemeFunc func(*k8sruntime.Scheme) error
}

type Environment

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

Environment encapsulates a set of clusters and can run tests against them.

func New

func New(t *testing.T, cfg Config) *Environment

New creates a new test environment.

func (*Environment) Client

func (e *Environment) Client(cluster string) client.Client

Client returns a new client for the cluster.

func (*Environment) Ctx

func (e *Environment) Ctx() context.Context

func (*Environment) InstallChartArchive

func (e *Environment) InstallChartArchive(cluster, name, namespace, path string, args map[string]string)

InstallChartArchive installs a Helm chart from a tarball on disk into a cluster. Arguments are provided as a map where the keys are JSON paths.

func (*Environment) New

func (env *Environment) New(testFn TestFunc) *Fixture

New creates a new Fixture for a test function.

func (*Environment) Run

func (e *Environment) Run(tests ...TestFunc)

Run takes a list of TestFuncs and executes them as subtests.

func (*Environment) Teardown

func (e *Environment) Teardown()

Teardown destroys all clusters that were created for the environment.

func (*Environment) Uniq

func (e *Environment) Uniq(s string) string

Uniq takes a string and makes it unique. It should be used to generate collision-free names for namespaces or cluster-wide resources from subtests.

type Fixture

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

Fixture provides functionality for a single test that is run against an environment.

func (*Fixture) ChartAssignmentHasStatus

func (f *Fixture) ChartAssignmentHasStatus(ca *crcapps.ChartAssignment, expected crcapps.ChartAssignmentPhase) func() error

ChartAssignmentHasStatus returns a condition func that checks if a given ChartAssignment has the expected status. Calls to the condition func update the ChartAssignment in place.

func (*Fixture) Client

func (f *Fixture) Client(cluster string) client.Client

Client returns a new client for the cluster.

func (*Fixture) Ctx

func (f *Fixture) Ctx() context.Context

func (*Fixture) FromYAML

func (f *Fixture) FromYAML(tmpl string, vals, dst interface{})

FromYAML expands a YAML template with the given vals and unmarshals it into dst. dst is typically of type *unstructured.Unstructured or a fully specified type for a Kubernetes resource.

func (*Fixture) ObjectKey

func (f *Fixture) ObjectKey(o client.Object) client.ObjectKey

ObjectKey extracts a namespace/name key from the given object.

func (*Fixture) Uniq

func (f *Fixture) Uniq(s string) string

Uniq takes a string and makes it unique. It should be used to generate collision-free names for namespaces or cluster-wide resources from subtests.

type TestFunc

type TestFunc func(*testing.T, *Fixture)

Jump to

Keyboard shortcuts

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