framework

package
v0.0.0-...-146a38b Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: BSD-3-Clause, Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Poll defines how regularly to poll kubernetes resources.
	Poll = 2 * time.Second
	// DefaultTimeout is how long we wait for long-running operations in the
	// test suite before giving up.
	DefaultTimeout = 10 * time.Minute
)
View Source
const TestDBName = "testdb"

TestDBName is the name of database to use when executing test SQL queries.

Variables

This section is empty.

Functions

func AwaitPodReadyOrDie

func AwaitPodReadyOrDie(cs clientset.Interface, ns, name string, timeout time.Duration)

AwaitPodReadyOrDie polls the specified Pod until it is ready of a timeout

func ExecuteSQL

func ExecuteSQL(cluster *v1alpha1.Cluster, member, sql string) (string, error)

ExecuteSQL executes the given SQL statement(s) on a specified Cluster member via kubectl exec.

func ExpectNoError

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

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 Failf

func Failf(format string, args ...interface{})

func FailfWithOffset

func FailfWithOffset(offset int, format string, args ...interface{})

FailfWithOffset calls "Fail" and logs the error at "offset" levels above its caller (for example, for call chain f -> g -> FailfWithOffset(1, ...) error would be logged for "f").

func GetPodCondition

func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)

GetPodCondition extracts the provided condition from the given status and returns that. Returns nil and -1 if the condition is not present, and the index of the located condition.

func GetPodReadyCondition

func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition

Extracts the pod ready condition from the given status and returns that. Returns nil if the condition is not present.

func GetReadyPrimaryPodName

func GetReadyPrimaryPodName(cs clientset.Interface, namespace, clusterName string) string

GetReadyPrimaryPodName returns the name of the first ready primary Pod it finds in the given cluster.

func GetReadySecondaryPodName

func GetReadySecondaryPodName(cs clientset.Interface, namespace, clusterName string) string

GetReadySecondaryPodName returns the name of the first ready secondary pod it finds in the given cluster.

func IsPodAvailable

func IsPodAvailable(pod *v1.Pod, minReadySeconds int32, now metav1.Time) bool

IsPodAvailable returns true if a pod is available; false otherwise. Precondition for an available pod is that it must be ready. On top of that, there are two cases when a pod can be considered available: 1. minReadySeconds == 0, or 2. LastTransitionTime (is set) + minReadySeconds < current time

func IsPodReady

func IsPodReady(pod *v1.Pod) bool

IsPodReady returns true if a pod is ready; false otherwise.

func IsPodReadyConditionTrue

func IsPodReadyConditionTrue(status v1.PodStatus) bool

IsPodReady returns true if a pod is ready; false otherwise.

func KubectlCmd

func KubectlCmd(args ...string) *exec.Cmd

KubectlCmd runs the kubectl executable through the wrapper script.

func Logf

func Logf(format string, args ...interface{})

func NewKubectlCommand

func NewKubectlCommand(args ...string) *kubectlBuilder

func ReadSQLTest

func ReadSQLTest(cluster *v1alpha1.Cluster, member string) (string, error)

ReadSQLTest SELECTs v from testdb.foo where k=foo.

func RegisterFlags

func RegisterFlags()

RegisterFlags registers the test framework flags and populates TestContext.

func RemoveCleanupAction

func RemoveCleanupAction(p CleanupActionHandle)

RemoveCleanupAction removes a function that was installed by AddCleanupAction.

func RunCleanupActions

func RunCleanupActions()

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 RunHostCmd

func RunHostCmd(ns, name, container, cmd string) (string, error)

RunHostCmd runs the given cmd in the context of the given pod using `kubectl exec` inside of a shell.

func RunKubectl

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

RunKubectl is a convenience wrapper over kubectlBuilder

func RunKubectlWithRetries

func RunKubectlWithRetries(args ...string) (string, error)

RunKubectlWithRetries runs a kubectl command with 3 retries.

func WaitForPodCondition

func WaitForPodCondition(c clientset.Interface, ns, podName, desc string, timeout time.Duration, condition podCondition) error

WaitForPodCondition polls a pod until timeout has passed waiting for a pod to meet a given condition.

func WriteSQLTest

func WriteSQLTest(cluster *v1alpha1.Cluster, member string) (string, error)

WriteSQLTest creates a test table, inserts a row, and writes a uuid into it. It returns the generated UUID.

Types

type BackupTestJig

type BackupTestJig struct {
	ID     string
	Name   string
	Labels map[string]string

	MySQLClient mysqlclientset.Interface
	KubeClient  clientset.Interface
}

BackupTestJig is a jig to help Backup testing.

func NewBackupTestJig

func NewBackupTestJig(mysqlClient mysqlclientset.Interface, kubeClient clientset.Interface, name string) *BackupTestJig

NewBackupTestJig allocates and inits a new BackupTestJig.

func (*BackupTestJig) CreateAndAwaitBackupOrFail

func (j *BackupTestJig) CreateAndAwaitBackupOrFail(namespace, clusterName string, tweak func(backup *v1alpha1.Backup), timeout time.Duration) *v1alpha1.Backup

CreateAndAwaitBackupOrFail creates a new Backup based on the jig's defaults, waits for it to become ready. Callers can provide a function to tweak the Backup object before it is created.

func (*BackupTestJig) CreateAndAwaitMySQLDumpBackupOrFail

func (j *BackupTestJig) CreateAndAwaitMySQLDumpBackupOrFail(namespace, clusterName string, databases []v1alpha1.Database, tweak func(backup *v1alpha1.Backup), timeout time.Duration) *v1alpha1.Backup

CreateAndAwaitMySQLDumpBackupOrFail creates a new Backup based on the jig's defaults, waits for it to become ready. Callers can provide a function to tweak the Backup object before it is created.

func (*BackupTestJig) CreateBackupOrFail

func (j *BackupTestJig) CreateBackupOrFail(namespace, clusterName string, tweak func(backup *v1alpha1.Backup)) *v1alpha1.Backup

CreateBackupOrFail creates a new Backup based on the jig's defaults. Callers can provide a function to tweak the Backup object before it is created.

func (*BackupTestJig) CreateS3AuthSecret

func (j *BackupTestJig) CreateS3AuthSecret(namespace, name string) (*corev1.Secret, error)

CreateS3AuthSecret creates a secret containing the S3 (compat.) credentials for storing backups.

func (*BackupTestJig) WaitForbackupReadyOrFail

func (j *BackupTestJig) WaitForbackupReadyOrFail(namespace, name string, timeout time.Duration) *v1alpha1.Backup

WaitForbackupReadyOrFail waits up to a given timeout for a backup to be in the running phase.

type CleanupActionHandle

type CleanupActionHandle *int

func AddCleanupAction

func AddCleanupAction(fn func()) CleanupActionHandle

AddCleanupAction installs a function that will be called in the event of the whole test being terminated. This allows arbitrary pieces of the overall test to hook into SynchronizedAfterSuite().

type ClusterTestJig

type ClusterTestJig struct {
	ID     string
	Name   string
	Labels map[string]string

	MySQLClient mysqlclientset.Interface
	KubeClient  clientset.Interface
}

ClusterTestJig is a jig to help Cluster testing.

func NewClusterTestJig

func NewClusterTestJig(mysqlClient mysqlclientset.Interface, kubeClient clientset.Interface, name string) *ClusterTestJig

NewClusterTestJig allocates and inits a new ClusterTestJig.

func (*ClusterTestJig) CreateAndAwaitClusterOrFail

func (j *ClusterTestJig) CreateAndAwaitClusterOrFail(namespace string, members int32, tweak func(cluster *v1alpha1.Cluster), timeout time.Duration) *v1alpha1.Cluster

CreateAndAwaitClusterOrFail creates a new Cluster based on the jig's defaults, waits for it to become ready, and then sanity checks it and its dependant resources. Callers can provide a function to tweak the Cluster object before it is created.

func (*ClusterTestJig) CreateClusterOrFail

func (j *ClusterTestJig) CreateClusterOrFail(namespace string, members int32, tweak func(cluster *v1alpha1.Cluster)) *v1alpha1.Cluster

CreateClusterOrFail creates a new Cluster based on the jig's defaults. Callers can provide a function to tweak the Cluster object before it is created.

func (*ClusterTestJig) SanityCheckCluster

func (j *ClusterTestJig) SanityCheckCluster(cluster *v1alpha1.Cluster)

SanityCheckCluster checks basic properties of a given Cluster match our expectations.

func (*ClusterTestJig) WaitForClusterReadyOrFail

func (j *ClusterTestJig) WaitForClusterReadyOrFail(namespace, name string, timeout time.Duration) *v1alpha1.Cluster

WaitForClusterReadyOrFail waits up to a given timeout for a cluster to be in the running phase.

func (*ClusterTestJig) WaitForClusterUpgradedOrFail

func (j *ClusterTestJig) WaitForClusterUpgradedOrFail(namespace, name, version string, timeout time.Duration) *v1alpha1.Cluster

WaitForClusterUpgradedOrFail waits for a MySQL cluster to be upgraded to the given version or fails.

func (*ClusterTestJig) WaitForConditionOrFail

func (j *ClusterTestJig) WaitForConditionOrFail(namespace, name string, timeout time.Duration, message string, conditionFn func(*v1alpha1.Cluster) bool) *v1alpha1.Cluster

type Framework

type Framework struct {
	BaseName          string
	OperatorInstalled bool

	ClientSet      clientset.Interface
	MySQLClientSet mysqlclientset.Interface

	Namespace *v1.Namespace // Every test has at least one namespace unless creation is skipped
	// contains filtered or unexported fields
}

Framework is used in the execution of e2e tests.

func NewDefaultFramework

func NewDefaultFramework(baseName string) *Framework

NewDefaultFramework constructs a new e2e test Framework with default options.

func NewFramework

func NewFramework(baseName string, client clientset.Interface) *Framework

NewFramework constructs a new e2e test Framework.

func (*Framework) AfterEach

func (f *Framework) AfterEach()

AfterEach deletes the namespace(s).

func (*Framework) BeforeEach

func (f *Framework) BeforeEach()

BeforeEach gets a client and makes a namespace.

func (*Framework) CreateNamespace

func (f *Framework) CreateNamespace(baseName string, labels map[string]string) (*v1.Namespace, error)

CreateNamespace creates a e2e test namespace.

func (*Framework) DeleteNamespace

func (f *Framework) DeleteNamespace(namespace string, timeout time.Duration) error

DeleteNamespace deletes a given namespace and waits until its contents are deleted.

func (*Framework) InstallOperator

func (f *Framework) InstallOperator(namespace string) error

InstallOperator installs the MySQL operator into the given namespace via helm. NOTE: Requires that the MySQL operator CRDs have already been installed.

type RestoreTestJig

type RestoreTestJig struct {
	ID     string
	Name   string
	Labels map[string]string

	MySQLClient mysqlclientset.Interface
	KubeClient  clientset.Interface
}

RestoreTestJig is a jig to help Restore testing.

func NewRestoreTestJig

func NewRestoreTestJig(mysqlClient mysqlclientset.Interface, kubeClient clientset.Interface, name string) *RestoreTestJig

NewRestoreTestJig allocates and inits a new RestoreTestJig.

func (*RestoreTestJig) CreateAndAwaitRestoreOrFail

func (j *RestoreTestJig) CreateAndAwaitRestoreOrFail(namespace, clusterName, backupName string, tweak func(restore *v1alpha1.Restore), timeout time.Duration) *v1alpha1.Restore

CreateAndAwaitRestoreOrFail creates a new Restore based on the jig's defaults, waits for it to become ready. Callers can provide a function to tweak the Restore object before it is created.

func (*RestoreTestJig) CreateRestoreOrFail

func (j *RestoreTestJig) CreateRestoreOrFail(namespace, clusterName, backupName string, tweak func(restore *v1alpha1.Restore)) *v1alpha1.Restore

CreateRestoreOrFail creates a new Restore based on the jig's defaults. Callers can provide a function to tweak the Restore object before it is created.

func (*RestoreTestJig) CreateS3AuthSecret

func (j *RestoreTestJig) CreateS3AuthSecret(namespace, name string) (*corev1.Secret, error)

CreateS3AuthSecret creates a secret containing the S3 (compat.) credentials for storing backups.

func (*RestoreTestJig) WaitForRestoreCompleteOrFail

func (j *RestoreTestJig) WaitForRestoreCompleteOrFail(namespace, name string, timeout time.Duration) *v1alpha1.Restore

WaitForRestoreCompleteOrFail waits up to a given timeout for a Restore to enter the complete phase.

type TestContextType

type TestContextType struct {
	// OperatorVersion is the version of the MySQL operator under test.
	OperatorVersion string

	// RepoRoot is the root directory of the repository.
	RepoRoot string

	// KubeConfig is the path to the kubeconfig file.
	KubeConfig string

	// Namespace (if provided) is the namespace of an existing namespace to
	// use for test execution rather than creating a new namespace.
	Namespace string
	// DeleteNamespace controls whether or not to delete test namespaces
	DeleteNamespace bool
	// DeleteNamespaceOnFailure controls whether or not to delete test
	// namespaces when the test fails.
	DeleteNamespaceOnFailure bool

	// S3AccessKey is the S3 (compat.) access key for the bucket used in
	// backup / restore tests.
	S3AccessKey string
	// S3AccessKey is the S3 (compat.) secret key for the bucket used in
	// backup / restore tests.
	S3SecretKey string
}

TestContextType represents the co

var TestContext TestContextType

TestContext holds the context of the the test run.

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