Skip to content

Commit

Permalink
add consumer test
Browse files Browse the repository at this point in the history
Signed-off-by: myan <[email protected]>
  • Loading branch information
yanmxa committed Jun 11, 2024
1 parent c2fa3e9 commit 7af7c53
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 222 deletions.
202 changes: 0 additions & 202 deletions test/e2e/pkg/api_test.go

This file was deleted.

72 changes: 72 additions & 0 deletions test/e2e/pkg/consumer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package e2e_test

import (
"net/http"
"reflect"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/openshift-online/maestro/pkg/api/openapi"
)

// go test -v ./test/e2e/pkg -args -api-server=$api_server -consumer-name=$consumer_name -consumer-kubeconfig=$consumer_kubeconfig -ginkgo.focus "Server Side API"
var _ = Describe("Consumer", Ordered, func() {
var testConsumerName string
var testConsumerID string
BeforeAll(func() {
testConsumerName = "test-consumer"
})

Context("Consumer CRUD Tests", func() {
It("list the default consumer", func() {
consumerList, resp, err := apiClient.DefaultApi.ApiMaestroV1ConsumersGet(ctx).Execute()
Expect(err).To(Succeed())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
Expect(consumerList).NotTo(BeNil())
Expect(len(consumerList.Items) > 0).To(BeTrue())

got := false
for _, consumer := range consumerList.Items {
if *consumer.Name == consumerOpts.Name {
got = true
}
}
Expect(got).To(BeTrue())
})

It("create consumer", func() {
consumer := openapi.Consumer{Name: &testConsumerName}
created, resp, err := apiClient.DefaultApi.ApiMaestroV1ConsumersPost(ctx).Consumer(consumer).Execute()
Expect(err).To(Succeed())
Expect(resp.StatusCode).To(Equal(http.StatusCreated))
Expect(*created.Id).NotTo(BeEmpty())
testConsumerID = *created.Id

got, resp, err := apiClient.DefaultApi.ApiMaestroV1ConsumersIdGet(ctx, testConsumerID).Execute()
Expect(err).To(Succeed())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
Expect(got).NotTo(BeNil())
})

It("patch consumer", func() {
labels := &map[string]string{"hello": "world"}
patched, resp, err := apiClient.DefaultApi.ApiMaestroV1ConsumersIdPatch(ctx, testConsumerID).
ConsumerPatchRequest(openapi.ConsumerPatchRequest{Labels: labels}).Execute()
Expect(err).To(Succeed())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
_, ok := patched.GetLabelsOk()
Expect(ok).To(BeTrue())

got, resp, err := apiClient.DefaultApi.ApiMaestroV1ConsumersIdGet(ctx, testConsumerID).Execute()
Expect(err).To(Succeed())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
Expect(got).NotTo(BeNil())
eq := reflect.DeepEqual(*labels, *got.Labels)
Expect(eq).To(BeTrue())
})

AfterAll(func() {
// TODO: add the conusmer deletion
})
})
})
Loading

0 comments on commit 7af7c53

Please sign in to comment.