Skip to content

Instantly share code, notes, and snippets.

@didil
Created November 19, 2020 17:19
Show Gist options
  • Save didil/d015d10656ff6016c17aa756772b52b3 to your computer and use it in GitHub Desktop.
Save didil/d015d10656ff6016c17aa756772b52b3 to your computer and use it in GitHub Desktop.
Deployment test
Context("When creating a deployment", func() {
var deployment *appsv1.Deployment
var bucket *abv1.Bucket
It("Should create the bucket crd", func() {
ctx := context.Background()
gcpSvc.On("CreateBucket", mock.AnythingOfType("*context.emptyCtx"), BucketFullName).Return(nil)
deployment = &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: DeploymentName,
Namespace: NamespaceName,
Annotations: map[string]string{
"ab.leclouddev.com/cloud": "gcp",
"ab.leclouddev.com/name-prefix": "abtest",
"ab.leclouddev.com/on-delete-policy": "ignore",
},
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "test",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "test",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
corev1.Container{
Name: "test",
Image: "busybox",
},
},
},
},
},
}
Expect(k8sClient.Create(ctx, deployment)).Should(Succeed())
// wait for bucket creation
Eventually(func() error {
bucket = &abv1.Bucket{}
err := k8sClient.Get(ctx, types.NamespacedName{Name: DeploymentName, Namespace: deployment.Namespace}, bucket)
if err != nil {
return err
}
if cloud := bucket.Spec.Cloud; cloud != "gcp" {
return fmt.Errorf("wrong cloud %v", cloud)
}
if fullName := bucket.Spec.FullName; fullName != BucketFullName {
return fmt.Errorf("wrong full name %v", fullName)
}
return nil
}, timeout, interval).Should(BeNil())
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment