Documentation ¶
Overview ¶
Package k8sctx is used to manage the lifecycle of a Kubernetes test or benchmark running in one or more Kubernetes clusters. It is used to control the behavior of Kubernetes-based tests and benchmarks at runtime and to abstract away how the Kubernetes test clusters are created and managed from the test code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetContextConstructor ¶
func SetContextConstructor(fn func(context.Context) (KubernetesContext, error))
SetContextConstructor sets the global Kubernetes context constructor.
Types ¶
type KubernetesContext ¶
type KubernetesContext interface { // TestMain should be called inside tests' `TestMain` function, after having // registered all tests with `RegisterTest`. TestMain(m *testing.M) // RegisterTest registers a test. // It should be called for every `Test*(*testing.T)` function in the test. // Note that the `k8sctx.TestMain` helper function below will call this for // you given a map of tests. RegisterTest(name string, fn TestFunc) // AcquireCluster returns a single cluster for the test or benchmark to use. // The cluster is guaranteed to not be in use by other tests or benchmarks // until the `ReleaseCluster` method is called. // This method should block if there are no available clusters. AcquireCluster(ctx context.Context, t *testing.T) *testcluster.TestCluster // ReleaseCluster unlocks the given cluster for use by other tests or // benchmarks. ReleaseCluster(ctx context.Context, t *testing.T, cluster *testcluster.TestCluster) // ForEachCluster reserves as many test clusters as are available, calls // `fn` on each of them, and releases each of them when `fn` finishes. ForEachCluster(ctx context.Context, t *testing.T, fn func(cluster *testcluster.TestCluster)) // ResolveImage resolves a container image name (possibly with a label) // to a fully-qualified image name. It can also return an `image:label` // string if the Kubernetes cluster the test runs in will resolve it on // its own. ResolveImage(ctx context.Context, imageName string) (string, error) }
KubernetesContext represents the Kubernetes execution context. It is used to keep track of available Kubernetes clusters to test on. Tests are expected to call `RegisterTest` for every of their test function, then `TestMain`.
Click to show internal directories.
Click to hide internal directories.