test

package
v0.0.0-...-6f3db3d Latest Latest
Warning

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

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

Documentation

Overview

Package test provides common resources useful for testing many operators. This includes functions for creating fake/mock resources and functions for testing that resources match what is expected.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgumentsMatchExpected

func ArgumentsMatchExpected(actualArgs []string, expectedArgs [][]string) error

ArgumentsMatchExpected returns a descriptive error if any of the expected arguments do not exist. This supports arguments in which flags appear multiple times with different values but does not support multiple instances of the same flag-value. This test is designed to fail if the list of actual arguments contains extra arguments not specified in the expected args. The expected arguments are given as an array of string arrays. This is to support flags which may have multiple values. Examples:

expectedArgs := [][]string{
    {"-h"},                              // test for a short flag
    {"-vvv"},                            // test for a short flag with value(s) specified
    {"-d", "3"},                         // test for a short flag with a value specified
    {"--verbose"},                       // test for a --bool flag
    {"--name=alex"},                     // test for a --flag=value flag
    {"--name", "sam"},                   // test for a --flag with a value after a space
    {"--full-name", "sam", "goodhuman"}, // test for a --flag with 2 values separated by spaces
}

func AssertLabelsContainRookRequirements

func AssertLabelsContainRookRequirements(t *testing.T, labels map[string]string, appName string)

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

func CreateConfigDir

func CreateConfigDir(monCount int) *cephconfig.ClusterInfo

CreateConfigDir creates a test cluster

func GetEnv

func GetEnv(name string, envs []v1.EnvVar) (*v1.EnvVar, error)

GetEnv finds returns the env var with the given name from a list of env vars.

func HumanReadableVolume

func HumanReadableVolume(v *v1.Volume) string

HumanReadableVolume returns a string representation of a Kubernetes volume which is more compact and human readable than the default string go prints.

func HumanReadableVolumeMount

func HumanReadableVolumeMount(m *v1.VolumeMount) string

HumanReadableVolumeMount returns a string representation of a Kubernetes volume mount which is more compact and human readable than the default string go prints.

func HumanReadableVolumeMounts

func HumanReadableVolumeMounts(mounts []v1.VolumeMount) string

HumanReadableVolumeMounts returns a string representation of a list of Kubernetes volume mounts which is more compact and human readable than the default string go prints.

func HumanReadableVolumes

func HumanReadableVolumes(volumes []v1.Volume) string

HumanReadableVolumes returns a string representation of a list of Kubernetes volumes which is more compact and human readable than the default string go prints.

func New

func New(t *testing.T, nodes int) *fake.Clientset

New creates a fake K8s cluster

func VolumeExists

func VolumeExists(volumeName string, volumes []v1.Volume) error

VolumeExists returns a descriptive error if the volume does not exist.

func VolumeIsEmptyDir

func VolumeIsEmptyDir(volumeName string, volumes []v1.Volume) error

VolumeIsEmptyDir returns a descriptive error if the volume does not exist or is not an empty dir

func VolumeIsHostPath

func VolumeIsHostPath(volumeName, path string, volumes []v1.Volume) error

VolumeIsHostPath returns a descriptive error if the volume does not exist, is not a HostPath volume, or if the volume's path is not as expected.

func VolumeMountExists

func VolumeMountExists(mountName string, mounts []v1.VolumeMount) error

VolumeMountExists returns returns a descriptive error if the volume mount does not exist.

Types

type ContainersTester

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

A ContainersTester is a helper exposing methods for testing required Rook specifications common for all Rook 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) AssertResourceSpec

func (ct *ContainersTester) AssertResourceSpec(expectations ResourceLimitExpectations)

AssertResourceSpec asserts that the container under test's resource limits/requests match the given (in string format) resource limits/requests.

func (*ContainersTester) RunFullSuite

func (ct *ContainersTester) RunFullSuite(resourceExpectations ResourceLimitExpectations)

RunFullSuite runs all assertion tests for the Containers under test.

type MountsSpec

type MountsSpec struct {
	// Moniker is a name given to the list to help identify it
	Moniker string
	Mounts  []v1.VolumeMount
}

MountsSpec is a struct which includes a list of Kubernetes volume mounts as well as additional metadata about the volume mount list for better identification during tests.

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) AssertVolumesAndMountsMatch

func (ps *PodSpecTester) AssertVolumesAndMountsMatch()

AssertVolumesAndMountsMatch asserts that all of the volume mounts in the pod spec under test's containers have a volume which sources them. It also asserts that each volume is used at least once by any of the mounts in containers.

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(resourceExpectations ResourceLimitExpectations)

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 Rook specifications common for all Rook PodTemplateSpecs.

func NewPodTemplateSpecTester

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

NewPodTemplateSpecTester creates a new tester to test the given PodTemplateSpec

func (*PodTemplateSpecTester) AssertLabelsContainRookRequirements

func (pt *PodTemplateSpecTester) AssertLabelsContainRookRequirements(appName string)

AssertLabelsContainRookRequirements asserts that the PodTemplateSpec under test contains labels which all Rook pods should have.

func (*PodTemplateSpecTester) RunFullSuite

func (pt *PodTemplateSpecTester) RunFullSuite(
	appName string,
	resourceExpectations ResourceLimitExpectations,
)

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.

type ResourceLimitExpectations

type ResourceLimitExpectations struct {
	CPUResourceLimit      string
	CPUResourceRequest    string
	MemoryResourceLimit   string
	MemoryResourceRequest string
}

ResourceLimitExpectations allows a test to define expectations for resource limits on containers. If any field is left as an empty string, that field will not be tested.

type VolumesAndMountsTestDefinition

type VolumesAndMountsTestDefinition struct {
	VolumesSpec     *VolumesSpec
	MountsSpecItems []*MountsSpec
}

VolumesAndMountsTestDefinition defines which volumes and mounts to test and what those values should be. The test is intended to be defined with VolumesSpec defined as a pod's volumes, and the list of MountsSpec items defined as the volume mounts from every container in the pod.

func (*VolumesAndMountsTestDefinition) TestMountsMatchVolumes

func (d *VolumesAndMountsTestDefinition) TestMountsMatchVolumes(t *testing.T)

TestMountsMatchVolumes tests two things: (1) That each volume mount in each every MountsSpec has a corresponding volume to source it

in the VolumesSpec

(2) That there are no extraneous volumes defined in the VolumesSpec that do not have a

corresponding volume mount in any of the MountsSpec items

type VolumesSpec

type VolumesSpec struct {
	// Moniker is a name given to the list to help identify it
	Moniker string
	Volumes []v1.Volume
}

VolumesSpec is a struct which includes a list of Kubernetes volumes as well as additional metadata about the volume list for better identification during tests.

Jump to

Keyboard shortcuts

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