framework

package
v0.0.0-...-c3f992c Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NamespaceCleanupTimeout = 2 * time.Minute
)
View Source
const (
	// Poll is how often to Poll pods
	Poll = 2 * time.Second
)

Variables

View Source
var (
	RetryInterval        = time.Second * 5
	Timeout              = time.Second * 600
	CleanupRetryInterval = time.Second * 1
	CleanupTimeout       = time.Second * 5
	GVR                  = groupName + "/" + apiVersion
)
View Source
var (
	RunID = uuid.NewUUID()
)

Functions

func AfterReadingAllFlags

func AfterReadingAllFlags(t *TestContextType)

AfterReadingAllFlags makes changes to the context after all flags have been read.

func ContainsAll

func ContainsAll(model, target []interface{}) bool

ContainsAll can be used to compare two sorted slices and validate both are not nil and all elements from given model are present on the target instance.

func DeleteNamespaces

func DeleteNamespaces(c clientset.Interface, deleteFilter, skipFilter []string) ([]string, error)

DeleteNamespaces deletes all namespaces that match the given delete and skip filters. Filter is by simple strings.Contains; first skip filter, then delete filter. Returns the list of deleted namespaces or an error.

func ExpectError

func ExpectError(err error, explain ...interface{})

ExpectError expects an error happens, otherwise an exception raises

func ExpectNoError

func ExpectNoError(err error, explain ...interface{})

ExpectNoError checks if "err" is set, and if so, fails assertion while logging the error.

func ExpectNoErrorWithOffset

func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{})

ExpectNoErrorWithOffset checks if "err" is set, and if so, fails assertion while logging the error at "offset" levels above its caller (for example, for call chain f -> g -> ExpectNoErrorWithOffset(1, ...) error would be logged for "f").

func ExpectNoErrorWithRetries

func ExpectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interface{})

ExpectNoErrorWithRetries checks if an error occurs with the given retry count.

func FromInts

func FromInts(m []int) []interface{}

FromInts returns an interface array with sorted elements from int array

func FromStrings

func FromStrings(m []string) []interface{}

FromStrings returns an interface array with sorted elements from string array

func GetPorts

func GetPorts(service corev1.Service) []int

GetPorts returns an int slice with all ports exposed by the provided corev1.Service object

func HandleFlags

func HandleFlags()

HandleFlags sets up all flags and parses the command line.

func KubectlCmd

func KubectlCmd(ctxData ContextData, args ...string) *exec.Cmd

KubectlCmd runs the kubectl executable through the wrapper script.

func LoadClientset

func LoadClientset() (*clientset.Clientset, error)

LoadClientset returns clientset for connecting to kubernetes clusters.

func LoadConfig

func LoadConfig() (*restclient.Config, error)

LoadConfig returns a config for a rest client.

func LookForRegexp

func LookForRegexp(expectedRegexp string, timeout time.Duration, fn func() string) (result string, err error)

LookForRegexp looks for the given regexp in results from given "func() string"

func LookForRegexpInLog

func LookForRegexpInLog(ctxData ContextData, podName, container, expectedRegexp string, timeout time.Duration) (result string, err error)

LookForRegexpInLog looks for the given regexp in the log of a specific pod container

func LookForString

func LookForString(expectedString string, timeout time.Duration, fn func() string) (result string, err error)

LookForString looks for the given string in the output of fn, repeatedly calling fn until the timeout is reached or the string is found. Returns last log and possibly error if the string was not found. TODO(alejandrox1): move to pod/ subpkg once kubectl methods are refactored.

func LookForStringInLog

func LookForStringInLog(ctxData ContextData, podName, container, expectedString string, timeout time.Duration) (result string, err error)

LookForStringInLog looks for the given string in the log of a specific pod container

func RegisterFlags

func RegisterFlags()

RegisterFlags registers flags for e2e test suites.

func RemoveCleanupAction

func RemoveCleanupAction(action ActionType, p CleanupActionHandle)

RemoveCleanupAction removes a function that was installed by AddCleanupAction.

func RestclientConfig

func RestclientConfig(kubeContext string) (*clientcmdapi.Config, error)

RestclientConfig returns a config holds the information needed to build connection to kubernetes clusters.

func RunCleanupActions

func RunCleanupActions(action ActionType)

RunCleanupActions runs all functions installed by AddCleanupAction. It does not remove them (see RemoveCleanupAction) but it does run unlocked, so they may remove themselves.

func RunKubectl

func RunKubectl(ctxData ContextData, args ...string) (string, error)

RunKubectl is a convenience wrapper over kubectlBuilder

func RunKubectlOrDie

func RunKubectlOrDie(ctxData ContextData, args ...string) string

RunKubectlOrDie is a convenience wrapper over kubectlBuilder

func WaitForDaemonSet

func WaitForDaemonSet(kubeclient kubernetes.Interface, namespace, name string, count int, retryInterval, timeout time.Duration) error

func WaitForDeletion

func WaitForDeletion(t *testing.T, dynclient client.Client, obj runtime.Object, retryInterval, timeout time.Duration) error

func WaitForDeployment

func WaitForDeployment(kubeclient kubernetes.Interface, namespace, name string, replicas int, retryInterval, timeout time.Duration) error

func WaitForNamespacesDeleted

func WaitForNamespacesDeleted(c clientset.Interface, namespaces []string, timeout time.Duration) error

WaitForNamespacesDeleted waits for the namespaces to be deleted.

Types

type ActionType

type ActionType int

Action type to be enqueued

const (
	AfterEach ActionType = iota
	AfterSuite
)

type CleanupActionHandle

type CleanupActionHandle *int

CleanupActionHandle is an integer pointer type for handling cleanup action

func AddCleanupAction

func AddCleanupAction(action ActionType, fn func()) CleanupActionHandle

AddCleanupAction installs a function that will be called in the event of completion of a test Spec or a test Suite. This allows arbitrary pieces of the overall test to hook into AfterEach() and SynchronizedAfterSuite().

type ClientSet

type ClientSet struct {
	KubeClient clientset.Interface
	ExtClient  apiextension.Interface
	QdrClient  qdrclient.Interface
}

type ContextData

type ContextData struct {
	Id        string
	Clients   ClientSet
	Namespace string

	// Set together with creating the ClientSet and the namespace.
	// Guaranteed to be unique in the cluster even when running the same
	// test multiple times in parallel.
	UniqueName         string
	CertManagerPresent bool // if crd is detected
	// contains filtered or unexported fields
}

ContextData holds clients and data related with namespaces

created within

func (*ContextData) AddNamespacesToDelete

func (c *ContextData) AddNamespacesToDelete(namespaces ...*corev1.Namespace)

func (*ContextData) CreateInterconnect

func (c *ContextData) CreateInterconnect(namespace string, size int32, fn ...InterconnectCustomizer) (*v1alpha1.Interconnect, error)

CreateInterconnect creates an interconnect resource

func (*ContextData) CreateInterconnectFromSpec

func (c *ContextData) CreateInterconnectFromSpec(size int32, name string, spec v1alpha1.InterconnectSpec) (*v1alpha1.Interconnect, error)

CreateInterconnectFromSpec creates an Interconnect resource using the provided InterconnectSpec

func (*ContextData) CreateNamespace

func (c *ContextData) CreateNamespace(clientSet *clientset.Clientset,
	baseName string, labels map[string]string) *corev1.Namespace

CreateNamespace creates a namespace for e2e testing.

func (*ContextData) DeleteInterconnect

func (c *ContextData) DeleteInterconnect(interconnect *v1alpha1.Interconnect) error

func (*ContextData) DeleteNamespace

func (c *ContextData) DeleteNamespace(ns *corev1.Namespace) []error

func (*ContextData) GenerateNamespace

func (c *ContextData) GenerateNamespace() (*corev1.Namespace, error)

GenerateNamespace creates a namespace with a random name.

func (*ContextData) GetDaemonSet

func (c *ContextData) GetDaemonSet(name string) (*appsv1.DaemonSet, error)

func (*ContextData) GetDeployment

func (c *ContextData) GetDeployment(name string) (*appsv1.Deployment, error)

func (*ContextData) GetInterconnect

func (c *ContextData) GetInterconnect(name string) (*v1alpha1.Interconnect, error)

func (*ContextData) GetSecret

func (c *ContextData) GetSecret(name string) (*corev1.Secret, error)

func (*ContextData) GetService

func (c *ContextData) GetService(name string) (*corev1.Service, error)

func (*ContextData) ListPodsForDeployment

func (c *ContextData) ListPodsForDeployment(deployment *appsv1.Deployment) (*corev1.PodList, error)

func (*ContextData) ListPodsForDeploymentName

func (c *ContextData) ListPodsForDeploymentName(name string) (*corev1.PodList, error)

func (*ContextData) UpdateInterconnect

func (c *ContextData) UpdateInterconnect(interconnect *v1alpha1.Interconnect) (*v1alpha1.Interconnect, error)

type Framework

type Framework struct {
	BaseName string

	// Map that ties clients and namespaces for each available context
	ContextMap map[string]*ContextData

	SkipNamespaceCreation bool // Whether to skip creating a namespace
	// contains filtered or unexported fields
}

func NewFramework

func NewFramework(baseName string, contexts ...string) *Framework

NewFramework creates a test framework

func (*Framework) AfterEach

func (f *Framework) AfterEach()

AfterEach deletes the namespace, after reading its events.

func (*Framework) AfterSuite

func (f *Framework) AfterSuite()

AfterSuite deletes the cluster level resources

func (*Framework) BeforeEach

func (f *Framework) BeforeEach(contexts ...string)

BeforeEach gets clients and makes a namespace

func (*Framework) GetFirstContext

func (f *Framework) GetFirstContext() *ContextData

GetFirstContext returns the first entry in the ContextMap or nil if none

func (*Framework) Setup

func (f *Framework) Setup() error

func (*Framework) TeardownEach

func (f *Framework) TeardownEach() error

func (*Framework) TeardownSuite

func (f *Framework) TeardownSuite() error

type InterconnectCustomizer

type InterconnectCustomizer func(interconnect *v1alpha1.Interconnect)

InterconnectCustomizer represents a function that allows for customizing an Interconnect resource before it is created.

type KubectlBuilder

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

KubectlBuilder is used to build, customize and execute a kubectl Command. Add more functions to customize the builder as needed.

func NewKubectlCommand

func NewKubectlCommand(ctxData ContextData, args ...string) *KubectlBuilder

NewKubectlCommand returns a KubectlBuilder for running kubectl.

func NewKubectlCommandTimeout

func NewKubectlCommandTimeout(ctxData ContextData, timeout time.Duration, args ...string) *KubectlBuilder

NewKubectlCommandTimeout returns a KubectlBuilder with a timeout defined, for running kubectl.

func NewKubectlExecCommand

func NewKubectlExecCommand(ctxData ContextData, pod string, timeout time.Duration, commandArgs ...string) *KubectlBuilder

NewKubectlExecCommand returns a KubectlBuilder prepared to execute a given command in a running pod.

func (KubectlBuilder) Exec

func (b KubectlBuilder) Exec() (string, error)

Exec runs the kubectl executable.

func (KubectlBuilder) ExecOrDie

func (b KubectlBuilder) ExecOrDie() string

ExecOrDie runs the kubectl executable or dies if error occurs.

type TestContextType

type TestContextType struct {
	KubeConfig               string
	KubeContexts             contextNames
	CertDir                  string
	Host                     string
	RepoRoot                 string
	KubectlPath              string
	OutputDir                string
	ReportDir                string
	ReportPrefix             string
	Prefix                   string
	QdrImage                 string
	OperatorImage            string
	DeleteNamespace          bool
	DeleteNamespaceOnFailure bool
	CleanStart               bool
}

TestContextType contains test settings and global state.

var TestContext TestContextType

TestContext should be used by all tests to access validation context data.

func (TestContextType) ContextsAvailable

func (t TestContextType) ContextsAvailable() int

ContextsAvailable returns the number of contexts available after parsing command line arguments.

func (TestContextType) GetContexts

func (t TestContextType) GetContexts() []string

GetContexts returns a list of contexts from provided flags or the current-context if none. If KubeConfig not provided or not generated, it returns nil.

Directories

Path Synopsis
Package ginkgowrapper wraps Ginkgo Fail and Skip functions to panic with structured data instead of a constant string.
Package ginkgowrapper wraps Ginkgo Fail and Skip functions to panic with structured data instead of a constant string.

Jump to

Keyboard shortcuts

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