test

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 21 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddReadyNode added in v1.5.8

func AddReadyNode(t *testing.T, clientset *fake.Clientset, name, ip string)

AddReadyNode adds a new Node with status "Ready" and the given name and IP.

func AddSomeReadyNodes added in v1.5.8

func AddSomeReadyNodes(t *testing.T, clientset *fake.Clientset, count int)

AddSomeReadyNodes create a number of new, ready Nodes.

  • name from 0 to count-1
  • ip from 0.0.0.0 to <count-1>.<count-1>.<count-1>.<count-1>

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 labels under test contain the labels which all Rook pods should have. This can be used with labels for Kubernetes Deployments, DaemonSets, etc.

func FakeCustomisePodCreate added in v1.12.9

func FakeCustomisePodCreate(t *testing.T, clientset *fake.Clientset, name, ns string, label map[string]string)

func FakeOperatorPod added in v1.8.0

func FakeOperatorPod(ns string) *corev1.Pod

func FakeReplicaSet added in v1.8.0

func FakeReplicaSet(ns string) *appsv1.ReplicaSet

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

New creates a fake K8s cluster with some nodes added.

func NewComplexClientset added in v1.5.8

func NewComplexClientset(t *testing.T) *fake.Clientset

NewComplexClientset is a reusable clientset for Rook unit tests that adds some complex behavior to the clientset to mimic more of what K8s does in the real world.

  • Generate a name for resources that have 'generateName' set and 'name' unset.

func PrependComplexJobReactor added in v1.5.8

func PrependComplexJobReactor(t *testing.T, clientset *fake.Clientset, assignPodToNode bool)

PrependComplexJobReactor adds a Job reactor with the below behavior. If more or different functionality than this is needed for a test, either make a custom Job reactor or add more optional behavior to this reactor.

  • When a Job is created, create the Pod for the Job based on the Job's Pod template
  • Created pod.Name = "[job name]-[pod name in job template]"
  • When a Job is deleted, delete the Pod for the Job (Pod delete will not be handled by reactors)
  • Pod create/delete is done to the clientset tracker, so no Pod watch events will register.
  • Optionally look through the clientset Nodes to randomly assign created Pods to a node.

func PrependFailReactor added in v1.6.0

func PrependFailReactor(t *testing.T, clientset *fake.Clientset, verb, resource string)

PrependFailReactor adds a reactor with the desired verb and resource that will report a failure.

func SetFakeKubernetesVersion added in v1.5.8

func SetFakeKubernetesVersion(clientset *fake.Clientset, semver string)

SetFakeKubernetesVersion sets a fake K8s version on the clientset. Version must be in semver format with a preceding "v" (e.g., "v1.13.2").

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

func NewContainersSpecTester(t *testing.T, cc []v1.Container) *ContainersTester

NewContainersSpecTester creates a new tester for the given container spec.

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