framework

package
v0.0.0-...-c2ba8ab Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: Apache-2.0 Imports: 31 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 *v1.MySQLCluster, member, sql string) (string, error)

ExecuteSQLOrDie executes the given SQL statement(s) on a specified MySQLCluster 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 *v1.MySQLCluster, 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 *v1.MySQLCluster, 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 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 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 MySQLBackupTestJig

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

	MySQLClient mysqlclientset.Interface
	KubeClient  clientset.Interface
}

MySQLBackupTestJig is a jig to help MySQLBackup testing.

func NewMySQLBackupTestJig

func NewMySQLBackupTestJig(mysqlClient mysqlclientset.Interface, kubeClient clientset.Interface, name string) *MySQLBackupTestJig

NewMySQLBackupTestJig allocates and inits a new MySQLBackupTestJig.

func (*MySQLBackupTestJig) CreateAndAwaitMySQLBackupOrFail

func (j *MySQLBackupTestJig) CreateAndAwaitMySQLBackupOrFail(namespace, clusterName string, tweak func(backup *v1.MySQLBackup), timeout time.Duration) *v1.MySQLBackup

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

func (*MySQLBackupTestJig) CreateAndAwaitMySQLDumpBackupOrFail

func (j *MySQLBackupTestJig) CreateAndAwaitMySQLDumpBackupOrFail(namespace, clusterName string, databases []string, tweak func(backup *v1.MySQLBackup), timeout time.Duration) *v1.MySQLBackup

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

func (*MySQLBackupTestJig) CreateMySQLBackupOrFail

func (j *MySQLBackupTestJig) CreateMySQLBackupOrFail(namespace, clusterName string, tweak func(backup *v1.MySQLBackup)) *v1.MySQLBackup

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

func (*MySQLBackupTestJig) CreateS3AuthSecret

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

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

func (*MySQLBackupTestJig) WaitForbackupReadyOrFail

func (j *MySQLBackupTestJig) WaitForbackupReadyOrFail(namespace, name string, timeout time.Duration) *v1.MySQLBackup

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

type MySQLClusterTestJig

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

	MySQLClient mysqlclientset.Interface
	KubeClient  clientset.Interface
}

MySQLClusterTestJig is a jig to help MySQLCluster testing.

func NewMySQLClusterTestJig

func NewMySQLClusterTestJig(mysqlClient mysqlclientset.Interface, kubeClient clientset.Interface, name string) *MySQLClusterTestJig

NewMySQLClusterTestJig allocates and inits a new MySQLClusterTestJig.

func (*MySQLClusterTestJig) CreateAndAwaitMySQLClusterOrFail

func (j *MySQLClusterTestJig) CreateAndAwaitMySQLClusterOrFail(namespace string, replicas int32, tweak func(cluster *v1.MySQLCluster), timeout time.Duration) *v1.MySQLCluster

CreateAndAwaitMySQLClusterOrFail creates a new MySQLCluster 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 MySQLCluster object before it is created.

func (*MySQLClusterTestJig) CreateMySQLClusterOrFail

func (j *MySQLClusterTestJig) CreateMySQLClusterOrFail(namespace string, replicas int32, tweak func(cluster *v1.MySQLCluster)) *v1.MySQLCluster

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

func (*MySQLClusterTestJig) SanityCheckMySQLCluster

func (j *MySQLClusterTestJig) SanityCheckMySQLCluster(cluster *v1.MySQLCluster)

SanityCheckMySQLCluster checks basic properties of a given MySQLCluster match our expectations.

func (*MySQLClusterTestJig) WaitForClusterReadyOrFail

func (j *MySQLClusterTestJig) WaitForClusterReadyOrFail(namespace, name string, timeout time.Duration) *v1.MySQLCluster

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

type MySQLRestoreTestJig

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

	MySQLClient mysqlclientset.Interface
	KubeClient  clientset.Interface
}

MySQLRestoreTestJig is a jig to help MySQLRestore testing.

func NewMySQLRestoreTestJig

func NewMySQLRestoreTestJig(mysqlClient mysqlclientset.Interface, kubeClient clientset.Interface, name string) *MySQLRestoreTestJig

NewMySQLRestoreTestJig allocates and inits a new MySQLRestoreTestJig.

func (*MySQLRestoreTestJig) CreateAndAwaitMySQLRestoreOrFail

func (j *MySQLRestoreTestJig) CreateAndAwaitMySQLRestoreOrFail(namespace, clusterName, backupName string, tweak func(restore *v1.MySQLRestore), timeout time.Duration) *v1.MySQLRestore

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

func (*MySQLRestoreTestJig) CreateMySQLRestoreOrFail

func (j *MySQLRestoreTestJig) CreateMySQLRestoreOrFail(namespace, clusterName, backupName string, tweak func(restore *v1.MySQLRestore)) *v1.MySQLRestore

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

func (*MySQLRestoreTestJig) CreateS3AuthSecret

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

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

func (*MySQLRestoreTestJig) WaitForRestoreCompleteOrFail

func (j *MySQLRestoreTestJig) WaitForRestoreCompleteOrFail(namespace, name string, timeout time.Duration) *v1.MySQLRestore

WaitForRestoreCompleteOrFail waits up to a given timeout for a MySQLRestore 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