Documentation ¶
Overview ¶
Package testhelpers holds reusable functions that make it easier to write testintegration and end-to-end tests.
Index ¶
- Constants
- func BuildAuthProxyWorkload(key types.NamespacedName, connectionString string) *v1alpha1.AuthProxyWorkload
- func BuildCronJob(name types.NamespacedName, appLabel string) *batchv1.CronJob
- func BuildDaemonSet(name types.NamespacedName, appLabel string) *appsv1.DaemonSet
- func BuildDeployment(name types.NamespacedName, appLabel string) *appsv1.Deployment
- func BuildJob(name types.NamespacedName, appLabel string) *batchv1.Job
- func BuildStatefulSet(name types.NamespacedName, appLabel string) *appsv1.StatefulSet
- func GetConditionStatus(conditions []*metav1.Condition, condType string) metav1.ConditionStatus
- func ListPods(ctx context.Context, c client.Client, ns string, ...) (*corev1.PodList, error)
- func NewNamespaceName(prefix string) string
- func RetryUntilSuccess(attempts int, d time.Duration, f func() error) (err error)
- type TestCaseClient
- func (cc *TestCaseClient) CreateAuthProxyWorkload(ctx context.Context, key types.NamespacedName, appLabel string, ...) error
- func (cc *TestCaseClient) CreateBusyboxDeployment(ctx context.Context, name types.NamespacedName, appLabel string) (*appsv1.Deployment, error)
- func (cc *TestCaseClient) CreateDeploymentReplicaSetAndPods(ctx context.Context, d *appsv1.Deployment) (*appsv1.ReplicaSet, []*corev1.Pod, error)
- func (cc *TestCaseClient) CreateOrPatchNamespace(ctx context.Context) error
- func (cc *TestCaseClient) CreateResource(ctx context.Context) (*cloudsqlapi.AuthProxyWorkload, error)
- func (cc *TestCaseClient) CreateWorkload(ctx context.Context, o client.Object) error
- func (cc *TestCaseClient) DeleteNamespace(ctx context.Context) error
- func (cc *TestCaseClient) DeleteResourceAndWait(ctx context.Context, res *cloudsqlapi.AuthProxyWorkload) error
- func (cc *TestCaseClient) ExpectContainerCount(ctx context.Context, key types.NamespacedName, count int) error
- func (cc *TestCaseClient) ExpectPodContainerCount(ctx context.Context, podSelector *metav1.LabelSelector, count int, ...) error
- func (cc *TestCaseClient) GetAuthProxyWorkloadAfterReconcile(ctx context.Context, key types.NamespacedName) (*v1alpha1.AuthProxyWorkload, error)
- func (cc *TestCaseClient) WaitForFinalizerOnResource(ctx context.Context, res *cloudsqlapi.AuthProxyWorkload) error
Constants ¶
const DefaultRetryInterval = 5 * time.Second
Variables ¶
This section is empty.
Functions ¶
func BuildAuthProxyWorkload ¶
func BuildAuthProxyWorkload(key types.NamespacedName, connectionString string) *v1alpha1.AuthProxyWorkload
func BuildCronJob ¶
func BuildCronJob(name types.NamespacedName, appLabel string) *batchv1.CronJob
func BuildDaemonSet ¶
func BuildDaemonSet(name types.NamespacedName, appLabel string) *appsv1.DaemonSet
func BuildDeployment ¶
func BuildDeployment(name types.NamespacedName, appLabel string) *appsv1.Deployment
func BuildStatefulSet ¶
func BuildStatefulSet(name types.NamespacedName, appLabel string) *appsv1.StatefulSet
func GetConditionStatus ¶
func GetConditionStatus(conditions []*metav1.Condition, condType string) metav1.ConditionStatus
GetConditionStatus finds a condition where Condition.Type == condType and returns the status, or "" if no condition was found.
func ListPods ¶
func ListPods(ctx context.Context, c client.Client, ns string, selector *metav1.LabelSelector) (*corev1.PodList, error)
ListPods lists all the pods in a particular deployment.
func NewNamespaceName ¶
func RetryUntilSuccess ¶
RetryUntilSuccess runs `f` until it no longer returns an error, or it has returned an error `attempts` number of times. It sleeps duration `d` between failed attempts. It returns the error from the last attempt.
Types ¶
type TestCaseClient ¶
type TestCaseClient struct { Client client.Client Namespace string ConnectionString string ProxyImageURL string }
func (*TestCaseClient) CreateAuthProxyWorkload ¶
func (cc *TestCaseClient) CreateAuthProxyWorkload(ctx context.Context, key types.NamespacedName, appLabel string, connectionString string, kind string) error
CreateAuthProxyWorkload creates an AuthProxyWorkload in the kubernetes cluster.
func (*TestCaseClient) CreateBusyboxDeployment ¶
func (cc *TestCaseClient) CreateBusyboxDeployment(ctx context.Context, name types.NamespacedName, appLabel string) (*appsv1.Deployment, error)
CreateBusyboxDeployment creates a simple busybox deployment, using the key as its namespace and name. It also sets the label "app"= appLabel.
func (*TestCaseClient) CreateDeploymentReplicaSetAndPods ¶
func (cc *TestCaseClient) CreateDeploymentReplicaSetAndPods(ctx context.Context, d *appsv1.Deployment) (*appsv1.ReplicaSet, []*corev1.Pod, error)
CreateDeploymentReplicaSetAndPods mimics the behavior of the deployment controller built into kubernetes. It creates one ReplicaSet and DeploymentSpec.Replicas pods with the correct labels and ownership annotations as if it were in a live cluster. This will make it easier to test and debug the behavior of our pod injection webhooks.
func (*TestCaseClient) CreateOrPatchNamespace ¶
func (cc *TestCaseClient) CreateOrPatchNamespace(ctx context.Context) error
CreateOrPatchNamespace ensures that a namespace exists with the given name in kubernetes, or fails the test as fatal.
func (*TestCaseClient) CreateResource ¶
func (cc *TestCaseClient) CreateResource(ctx context.Context) (*cloudsqlapi.AuthProxyWorkload, error)
CreateResource creates a new workload resource in the TestCaseClient's namespace waits until the resource exists.
func (*TestCaseClient) CreateWorkload ¶
func (*TestCaseClient) DeleteNamespace ¶
func (cc *TestCaseClient) DeleteNamespace(ctx context.Context) error
func (*TestCaseClient) DeleteResourceAndWait ¶
func (cc *TestCaseClient) DeleteResourceAndWait(ctx context.Context, res *cloudsqlapi.AuthProxyWorkload) error
DeleteResourceAndWait issues a delete request for the resource and then waits for the resource to actually be deleted. This will return an error if the resource is not deleted within 15 seconds.
func (*TestCaseClient) ExpectContainerCount ¶
func (cc *TestCaseClient) ExpectContainerCount(ctx context.Context, key types.NamespacedName, count int) error
ExpectContainerCount finds a deployment and keeps checking until the number of containers on the deployment's PodSpec.Containers == count. Returns error after 30 seconds if the containers do not match.
func (*TestCaseClient) ExpectPodContainerCount ¶
func (cc *TestCaseClient) ExpectPodContainerCount(ctx context.Context, podSelector *metav1.LabelSelector, count int, allOrAny string) error
ExpectPodContainerCount finds a deployment and keeps checking until the number of containers on the deployment's PodSpec.Containers == count. Returns error after 30 seconds if the containers do not match.
func (*TestCaseClient) GetAuthProxyWorkloadAfterReconcile ¶
func (cc *TestCaseClient) GetAuthProxyWorkloadAfterReconcile(ctx context.Context, key types.NamespacedName) (*v1alpha1.AuthProxyWorkload, error)
GetAuthProxyWorkloadAfterReconcile finds an AuthProxyWorkload resource named key, waits for its "UpToDate" condition to be "True", and the returns it. Fails after 30 seconds if the containers does not match.
func (*TestCaseClient) WaitForFinalizerOnResource ¶
func (cc *TestCaseClient) WaitForFinalizerOnResource(ctx context.Context, res *cloudsqlapi.AuthProxyWorkload) error
WaitForFinalizerOnResource queries the client to see if the resource has a finalizer.