test

package
v0.0.0-...-3f1f3ec Latest Latest
Warning

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

Go to latest
Published: Feb 28, 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

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

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

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

func (ct *ContainersTester) AssertArgsContainCephRequirements()

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

func (*ContainersTester) AssertCephImagesMatch

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

func (ct *ContainersTester) AssertEnvVarsContainCephRequirements()

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

func (*ContainersTester) RequireAdditionalEnvVars

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

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

RunFullSuite runs all assertion tests for the Containers under test.

type PodSpecTester

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

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

NewPodSpecTester creates a new tester to test the given PodSpec.

func (*PodSpecTester) AssertChownContainer

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

func (ps *PodSpecTester) AssertPriorityClassNameMatch(name string)

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

func (*PodSpecTester) AssertRestartPolicyAlways

func (ps *PodSpecTester) AssertRestartPolicyAlways()

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

func (*PodSpecTester) AssertVolumesMeetCephRequirements

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

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

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

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

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

NewPodTemplateSpecTester creates a new tester to test the given PodTemplateSpec

func (*PodTemplateSpecTester) AssertLabelsContainCephRequirements

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

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

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