test

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2019 License: Apache-2.0 Imports: 9 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 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 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 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