test

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 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 added in v0.9.0

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 added in v1.1.0

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 added in v0.6.0

func CreateConfigDir(monCount int) *cephconfig.ClusterInfo

CreateConfigDir creates a test cluster

func GetEnv added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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(nodes int) *fake.Clientset

New creates a fake K8s cluster

func VolumeExists added in v0.9.0

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

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

func VolumeIsEmptyDir added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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

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

Types

type ContainersTester added in v1.1.0

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 added in v1.1.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) AssertResourceSpec added in v1.1.0

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 added in v1.1.0

func (ct *ContainersTester) RunFullSuite(resourceExpectations ResourceLimitExpectations)

RunFullSuite runs all assertion tests for the Containers under test.

type MountsSpec added in v0.9.0

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 added in v1.1.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.1.0

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

NewPodSpecTester creates a new tester to test the given PodSpec.

func (*PodSpecTester) AssertVolumesAndMountsMatch added in v1.1.0

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 added in v1.1.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.1.0

func (ps *PodSpecTester) RunFullSuite(resourceExpectations ResourceLimitExpectations)

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

type PodTemplateSpecTester added in v1.1.0

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 added in v1.1.0

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

NewPodTemplateSpecTester creates a new tester to test the given PodTemplateSpec

func (*PodTemplateSpecTester) AssertLabelsContainRookRequirements added in v1.1.0

func (pt *PodTemplateSpecTester) AssertLabelsContainRookRequirements(appName string)

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

func (*PodTemplateSpecTester) RunFullSuite added in v1.1.0

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 added in v1.1.0

Spec creates a PodSpecTester from a parent PodTemplateSpecTester.

type ResourceLimitExpectations added in v1.1.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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