test

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package test provides common resources useful for testing many Ceph daemons. This includes functions for testing that resources match what is expected.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertLabelsContainCephRequirements added in v1.0.0

func AssertLabelsContainCephRequirements(
	t *testing.T, labels map[string]string,
	daemonType config.DaemonType, daemonID, appName, namespace string,
)

AssertLabelsContainCephRequirements asserts that the the labels under test contain the labels which all Ceph pods should have. This can be used with labels for Kubernetes Deployments, DaemonSets, etc.

func VerifyAppLabels

func VerifyAppLabels(appName, namespace string, labels map[string]string) error

VerifyAppLabels returns a descriptive error if app labels are not present or not as expected.

func VerifyPodLabels

func VerifyPodLabels(appName, namespace, daemonType, daemonID string, labels map[string]string) error

VerifyPodLabels returns a descriptive error if pod labels are not present or not as expected.

Types

type ContainerTestDefinition

type ContainerTestDefinition struct {
	// Image is the name of the container image
	Image *string
	// Command is the container command
	Command []string
	// Args is a list of expected arguments in the same format as the expected arguments from
	// the ArgumentsMatchExpected() function.
	Args [][]string
	// InOrderArgs is a map of argument position (int) to the argument itself (string). If the
	// "third" arg must be exactly the third argument this should be: InOrderArgs[2]="third"
	InOrderArgs map[int]string
	// VolumeMountNames is a list of volume mount names which must be mounted in the container
	VolumeMountNames []string
	// EnvCount is the number of 'Env' variables the container should define
	EnvCount *int
	// Ports is a list of ports the container must define. This list is in order, and each port's
	// 'ContainerPort' and 'Protocol' are tested for equality.
	// Note: port's in general aren't order-dependent, but there is not yet a method to test for
	//       the existence of a port in a list of ports without caring about order.
	Ports []v1.ContainerPort
	// IsPrivileged tests if the container is privileged (true) or unprivileged (false)
	IsPrivileged *bool
}

ContainerTestDefinition defines which k8s container values to test and what those values should be. Any definition item may be nil, and a nil value will prevent the item from being tested in the container test.

func (*ContainerTestDefinition) TestContainer

func (d *ContainerTestDefinition) TestContainer(
	t *testing.T,
	moniker string,
	cont *v1.Container,
	logger *capnslog.PackageLogger,
)

TestContainer tests that a container matches the container test definition. Moniker is a name given to the container for identifying it in tests. Cont is the container to be tested. Logger is the logger to output logs to.

type ContainersTester added in v1.0.0

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

A ContainersTester is a helper exposing methods for testing required Ceph specifications common for all Ceph containers.

func (*ContainersTester) AssertArgReferencesMatchEnvVars added in v1.0.0

func (ct *ContainersTester) AssertArgReferencesMatchEnvVars()

AssertArgReferencesMatchEnvVars asserts that for each container under test, any references to Kubernetes environment variables (e.g., $(POD_NAME)), have an environment variable set to source the value.

func (*ContainersTester) AssertArgsContainCephRequirements added in v1.0.0

func (ct *ContainersTester) AssertArgsContainCephRequirements()

AssertArgsContainCephRequirements asserts that all Ceph containers under test have the flags required for all Ceph containers.

func (*ContainersTester) AssertCephImagesMatch added in v1.0.0

func (ct *ContainersTester) AssertCephImagesMatch(image string)

AssertCephImagesMatch asserts that for all Ceph containers under test, the Ceph image used is the expected image.

func (*ContainersTester) AssertEnvVarsContainCephRequirements added in v1.0.0

func (ct *ContainersTester) AssertEnvVarsContainCephRequirements()

AssertEnvVarsContainCephRequirements asserts that all Ceph containers under test have the environment variables required for all Ceph containers.

func (*ContainersTester) RequireAdditionalEnvVars added in v1.0.0

func (*ContainersTester) RequireAdditionalEnvVars(varNames ...string)

RequireAdditionalEnvVars adds a list of environment variable names to the list of required variables for a single unit test (it does not persist between different tests). Usage: myPodTemplateSpecTester.Spec().Containers().RequireAdditionalEnvVars("I_AM", "REQUIRED")

func (*ContainersTester) RunFullSuite added in v1.0.0

func (ct *ContainersTester) RunFullSuite(cephImage, cpuResourceLimit, cpuResourceRequest, memoryResourceLimit, memoryResourceRequest string)

RunFullSuite runs all assertion tests for the Containers under test.

type PodSpecTester added in v1.0.0

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

A PodSpecTester is a helper exposing methods for testing required Ceph specifications common for all Ceph PodSpecs.

func NewPodSpecTester added in v1.0.0

func NewPodSpecTester(t *testing.T, spec *v1.PodSpec) *PodSpecTester

NewPodSpecTester creates a new tester to test the given PodSpec.

func (*PodSpecTester) AssertChownContainer added in v1.2.0

func (ps *PodSpecTester) AssertChownContainer(daemonType config.DaemonType)

AssertChownContainer ensures that the init container to chown the Ceph data dir is present for Ceph daemons.

func (*PodSpecTester) AssertPriorityClassNameMatch added in v1.2.0

func (ps *PodSpecTester) AssertPriorityClassNameMatch(name string)

AssertPriorityClassNameMatch asserts that the pod spec has priorityClassName set to be the same

func (*PodSpecTester) AssertRestartPolicyAlways added in v1.0.0

func (ps *PodSpecTester) AssertRestartPolicyAlways()

AssertRestartPolicyAlways asserts that the pod spec is set to always restart on failure.

func (*PodSpecTester) AssertVolumesMeetCephRequirements added in v1.0.0

func (ps *PodSpecTester) AssertVolumesMeetCephRequirements(
	daemonType config.DaemonType, daemonID string,
)

AssertVolumesMeetCephRequirements asserts that all the required Ceph volumes exist in the pod spec under test, Volumes list.

func (*PodSpecTester) Containers added in v1.0.0

func (ps *PodSpecTester) Containers() *ContainersTester

Containers creates a ContainersTester from a parent PodSpecTester. Because ContainersTester is intended to test the full list of containers (both init and run containers) in a PodSpec, this method is the only way of creating a ContainersTester.

func (*PodSpecTester) RunFullSuite added in v1.0.0

func (ps *PodSpecTester) RunFullSuite(
	daemonType config.DaemonType, resourceName, cephImage,
	cpuResourceLimit, cpuResourceRequest, memoryResourceLimit, memoryResourceRequest string, priorityClassName string,
)

RunFullSuite runs all assertion tests for the PodSpec under test and its sub-resources.

type PodTemplateSpecTester added in v1.0.0

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

A PodTemplateSpecTester is a helper exposing methods for testing required Ceph specifications common for all Ceph PodTemplateSpecs.

func NewPodTemplateSpecTester added in v1.0.0

func NewPodTemplateSpecTester(t *testing.T, template *v1.PodTemplateSpec) *PodTemplateSpecTester

NewPodTemplateSpecTester creates a new tester to test the given PodTemplateSpec

func (*PodTemplateSpecTester) AssertLabelsContainCephRequirements added in v1.0.0

func (pt *PodTemplateSpecTester) AssertLabelsContainCephRequirements(
	daemonType config.DaemonType, daemonID, appName, namespace string,
)

AssertLabelsContainCephRequirements asserts that the PodTemplateSpec under test contains labels which all Ceph pods should have.

func (*PodTemplateSpecTester) RunFullSuite added in v1.0.0

func (pt *PodTemplateSpecTester) RunFullSuite(
	daemonType config.DaemonType,
	daemonID, appName, namespace, cephImage,
	cpuResourceLimit, cpuResourceRequest,
	memoryResourceLimit, memoryResourceRequest string,
	priorityClassName string,
)

RunFullSuite runs all assertion tests for the PodTemplateSpec under test and its sub-resources.

func (*PodTemplateSpecTester) Spec added in v1.0.0

Spec creates a PodSpecTester from a parent PodTemplateSpecTester.

Jump to

Keyboard shortcuts

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