testing

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Overview

Package testing provides helpers for tests, like wrappers for kubectl and helm

Index

Constants

View Source
const (
	// QuarksHelmRelease is the default quarks-operator helm release name
	QuarksHelmRelease = "quarks"
)

Variables

This section is empty.

Functions

func Apply

func Apply(namespace string, yamlFilePath string) error

Apply updates the resource using kubectl command

func Create

func Create(namespace string, yamlFilePath string) error

Create creates the resource using kubectl command

func CreateNamespace

func CreateNamespace(name string) error

CreateNamespace create the namespace using kubectl command

func CreateSecretFromLiteral

func CreateSecretFromLiteral(namespace string, secretName string, literalValues map[string]string) error

CreateSecretFromLiteral creates a generic type secret using kubectl command

func Delete

func Delete(namespace string, yamlFilePath string) error

Delete creates the resource using kubectl command

func DeleteLabelFilter

func DeleteLabelFilter(namespace string, resourceName string, labelName string) error

DeleteLabelFilter deletes the resource based on label using kubectl command

func DeleteNamespace

func DeleteNamespace(ns string) error

DeleteNamespace removes existing ns

func DeleteResource

func DeleteResource(namespace string, resourceName string, name string) error

DeleteResource deletes the resource using kubectl command

func DeleteSecret

func DeleteSecret(namespace string, secretName string) error

DeleteSecret deletes the namespace using kubectl command

func DeleteWebhooks

func DeleteWebhooks(ns string, name string) error

DeleteWebhooks removes existing webhookconfiguration and validatingwebhookconfiguration

func GetData

func GetData(namespace string, resourceName string, name string, templatePath string) ([]byte, error)

GetData fetches the specified output by the given templatePath

func HelmBinaryVersion

func HelmBinaryVersion() (string, error)

HelmBinaryVersion executes helm version and return 2 or 3

func NewContext

func NewContext() context.Context

NewContext returns a non-nil empty context, for usage when it is unclear which context to use. Mostly used in tests.

func PatchNamespace

func PatchNamespace(name string, patch string) error

PatchNamespace patche the namespace resource using kubectl command

func RestartOperator

func RestartOperator(namespace string) error

RestartOperator restart Operator Deployment

func RunCommandWithOutput

func RunCommandWithOutput(namespace string, podName string, commandInPod string) (string, error)

RunCommandWithOutput runs the command specified in the container and returns output

func RunHelmBinaryWithCustomErr

func RunHelmBinaryWithCustomErr(args ...string) error

RunHelmBinaryWithCustomErr executes a desire binary

func SecretCheckData

func SecretCheckData(namespace string, secretName string, fieldPath string) error

SecretCheckData checks the field specified in the given field

func TriggerQJob

func TriggerQJob(namespace, qjob string) error

TriggerQJob triggers a qjob

Types

type BDPL

type BDPL struct {
	APIVersion string `json:"apiVersion" yaml:"apiVersion"`
	Kind       string `json:"kind" yaml:"kind"`
	Metadata   struct {
		Name string `json:"name" yaml:"name"`
	} `json:"metadata" yaml:"metadata"`
	Spec struct {
		Manifest map[string]string   `json:"manifest" yaml:"manifest"`
		Ops      []map[string]string `json:"ops" yaml:"ops"`
	} `json:"spec" yaml:"spec"`
}

BDPL defines a bdpl

type ClusterCrd

type ClusterCrd struct {
	Items []struct {
		APIVersion string `json:"apiVersion"`
		Kind       string `json:"kind"`
		Metadata   struct {
			Name string `json:"name"`
		} `json:"metadata"`
	} `json:"items"`
}

ClusterCrd defines a list of CRDs

func GetCRDs

func GetCRDs() (*ClusterCrd, error)

GetCRDs returns all CRDs

func (*ClusterCrd) ContainsElement

func (c *ClusterCrd) ContainsElement(element string) bool

ContainsElement verify if a CRD exist

type ConfigMap

type ConfigMap struct {
	APIVersion string `json:"apiVersion" yaml:"apiVersion"`
	Kind       string `json:"kind" yaml:"kind"`
	Metadata   struct {
		Name string `json:"name" yaml:"name"`
	} `json:"metadata" yaml:"metadata"`
	Data map[string]string `json:"data" yaml:"data"`
}

ConfigMap defines a kube ConfigMap

type CustomError

type CustomError struct {
	Msg    string
	StdOut string
	Err    error
}

CustomError containing stdOutput of a binary execution

func (*CustomError) Error

func (e *CustomError) Error() string

type Kubectl

type Kubectl struct {
	Log         *zap.SugaredLogger
	Namespace   string
	PollTimeout time.Duration
	// contains filtered or unexported fields
}

Kubectl is used as a command to test e2e tests

func NewKubectl

func NewKubectl() *Kubectl

NewKubectl returns a new CfOperatorkubectl command

func (*Kubectl) ApplyYAML

func (k *Kubectl) ApplyYAML(namespace string, name string, v interface{}) error

ApplyYAML applies arbitrary interfaces with kubectl.

func (*Kubectl) CreateRoleBinding

func (k *Kubectl) CreateRoleBinding(namespace string, clusterrole, serviceaccount, role string) error

CreateRoleBinding Create a new rolebinding in a namespace from a cluster role

func (*Kubectl) CreateServiceAccount

func (k *Kubectl) CreateServiceAccount(namespace string, serviceaccount string) error

CreateServiceAccount Create a new serviceaccount in a namespace

func (*Kubectl) Curl added in v0.0.2

func (k *Kubectl) Curl(namespace, url string) ([]byte, error)

Curl returns output if the service is accessible

func (*Kubectl) Delete

func (k *Kubectl) Delete(args ...string) error

Delete calls kubectl with the given arguments

func (*Kubectl) DeleteRoleBinding

func (k *Kubectl) DeleteRoleBinding(namespace string, role string) error

DeleteRoleBinding Deletes a rolebinding in a namespace

func (*Kubectl) DeleteServiceAccount

func (k *Kubectl) DeleteServiceAccount(namespace string, serviceaccount string) error

DeleteServiceAccount Deletes a serviceaccount in a namespace

func (*Kubectl) Exists

func (k *Kubectl) Exists(namespace, resource, name string) (bool, error)

Exists returns true if the resource by that name exists

func (*Kubectl) GetBoshDeployment

func (k *Kubectl) GetBoshDeployment(namespace string, name string) (BDPL, error)

GetBoshDeployment returns a BDPL

func (*Kubectl) GetConfigMap

func (k *Kubectl) GetConfigMap(namespace string, name string) (ConfigMap, error)

GetConfigMap blocks until the specified data is available. It fails after the timeout.

func (*Kubectl) GetPodNames

func (k *Kubectl) GetPodNames(namespace string, selector string) ([]string, error)

GetPodNames returns the names of the pods matching the selector

func (*Kubectl) PodExists

func (k *Kubectl) PodExists(namespace string, labelName string, podName string) (bool, error)

PodExists returns true if the pod by that label is present

func (*Kubectl) PodStatus

func (k *Kubectl) PodStatus(namespace string, podName string) (*v1.PodStatus, error)

PodStatus returns the status if the pod by that label is present

func (*Kubectl) RunCommandWithCheckString

func (k *Kubectl) RunCommandWithCheckString(namespace string, podName string, commandInPod string, result string) error

RunCommandWithCheckString runs the command specified helper in the container

func (*Kubectl) SecretExists

func (k *Kubectl) SecretExists(namespace string, secretName string) (bool, error)

SecretExists returns true if the pod by that name is in state running

func (*Kubectl) Service

func (k *Kubectl) Service(namespace string, serviceName string) (v1.Service, error)

Service returns the service if serviceName exists.

func (*Kubectl) ServiceExists

func (k *Kubectl) ServiceExists(namespace string, serviceName string) (bool, error)

ServiceExists returns true if the pod by that name is in state running

func (*Kubectl) ServiceWorks added in v0.0.2

func (k *Kubectl) ServiceWorks(namespace, serviceName string) (bool, error)

ServiceWorks returns true if the service is accessible

func (*Kubectl) Wait

func (k *Kubectl) Wait(namespace string, requiredStatus string, resourceName string, customTimeout time.Duration) error

Wait waits for the condition on the resource using kubectl command

func (*Kubectl) WaitForData

func (k *Kubectl) WaitForData(namespace string, resourceName string, name string, template string, expectation string) error

WaitForData blocks until the specified data is available. It fails after the timeout.

func (*Kubectl) WaitForPVC

func (k *Kubectl) WaitForPVC(namespace string, pvcName string) error

WaitForPVC blocks until the pvc is available. It fails after the timeout.

func (*Kubectl) WaitForPod

func (k *Kubectl) WaitForPod(namespace string, labelName string, podName string) error

WaitForPod blocks until the pod is available. It fails after the timeout.

func (*Kubectl) WaitForPodDelete

func (k *Kubectl) WaitForPodDelete(namespace string, podName string) error

WaitForPodDelete blocks until the pod is available. It fails after the timeout.

func (*Kubectl) WaitForSecret

func (k *Kubectl) WaitForSecret(namespace string, secretName string) error

WaitForSecret blocks until the secret is available. It fails after the timeout.

func (*Kubectl) WaitForService

func (k *Kubectl) WaitForService(namespace string, serviceName string) error

WaitForService blocks until the service is available. It fails after the timeout.

func (*Kubectl) WaitLabelFilter

func (k *Kubectl) WaitLabelFilter(namespace string, requiredStatus string, resourceName string, labelName string) error

WaitLabelFilter waits for the condition on the resource based on label using kubectl command

Directories

Path Synopsis
Package e2ehelper has common functionality for the end-to-end test suites
Package e2ehelper has common functionality for the end-to-end test suites
Package environment adds everything around mgr.Start() to run a local operator for the integration test suites
Package environment adds everything around mgr.Start() to run a local operator for the integration test suites
Package machine builds k8s resources for use in integration tests
Package machine builds k8s resources for use in integration tests
Package testhelper has common helpers for tests
Package testhelper has common helpers for tests

Jump to

Keyboard shortcuts

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