Skip to content

Commit

Permalink
add e2e testing.
Browse files Browse the repository at this point in the history
Signed-off-by: morvencao <[email protected]>
  • Loading branch information
morvencao committed Jun 12, 2024
1 parent 7bb3466 commit 96820a7
Show file tree
Hide file tree
Showing 3 changed files with 547 additions and 11 deletions.
39 changes: 28 additions & 11 deletions test/e2e/pkg/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,29 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
Expect(err).ShouldNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusCreated))
Expect(*resource.Id).ShouldNot(BeEmpty())
Expect(*resource.Version).To(Equal(int32(1)))

Eventually(func() error {
_, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{})
deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{})
if err != nil {
return err
}
if *deploy.Spec.Replicas != 1 {
return fmt.Errorf("unexpected replicas, expected 1, got %d", *deploy.Spec.Replicas)
}
return nil
}, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred())
})

It("patch the nginx resource", func() {
It("get the nginx resource from the maestro api", func() {
gotResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdGet(context.Background(), *resource.Id).Execute()
Expect(err).ShouldNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
Expect(*gotResource.Id).To(Equal(*resource.Id))
Expect(*gotResource.Version).To(Equal(*resource.Version))
})

It("patch the nginx resource with the maestro api", func() {

newRes := helper.NewAPIResource(consumer_name, 2)
patchedResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdPatch(context.Background(), *resource.Id).
Expand All @@ -51,10 +63,10 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
if err != nil {
return err
}
if *deploy.Spec.Replicas == 2 {
return nil
if *deploy.Spec.Replicas != 2 {
return fmt.Errorf("unexpected replicas, expected 2, got %d", *deploy.Spec.Replicas)
}
return fmt.Errorf("replicas is not 2")
return nil
}, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred())
})

Expand Down Expand Up @@ -88,10 +100,13 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
Expect(*resource.Id).ShouldNot(BeEmpty())

Eventually(func() error {
_, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{})
deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{})
if err != nil {
return err
}
if *deploy.Spec.Replicas != 1 {
return fmt.Errorf("unexpected replicas, expected 1, got %d", *deploy.Spec.Replicas)
}
return nil
}, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred())
})
Expand Down Expand Up @@ -167,10 +182,13 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
Expect(*resource.Id).ShouldNot(BeEmpty())

Eventually(func() error {
_, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{})
deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{})
if err != nil {
return err
}
if *deploy.Spec.Replicas != 1 {
return fmt.Errorf("unexpected replicas, expected 1, got %d", *deploy.Spec.Replicas)
}
return nil
}, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred())
})
Expand All @@ -189,10 +207,10 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
if err != nil {
return err
}
if *deploy.Spec.Replicas == 1 {
return nil
if *deploy.Spec.Replicas != 1 {
return fmt.Errorf("unexpected replicas, expected 1, got %d", *deploy.Spec.Replicas)
}
return fmt.Errorf("replicas is not 1")
return nil
}, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred())
})

Expand All @@ -214,5 +232,4 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
}, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred())
})
})

})
Loading

0 comments on commit 96820a7

Please sign in to comment.