Skip to content

Commit

Permalink
Clean up test
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Ibrahim <[email protected]>
  • Loading branch information
Ali Ibrahim committed Jun 10, 2024
1 parent dd83792 commit 36c030c
Showing 1 changed file with 39 additions and 38 deletions.
77 changes: 39 additions & 38 deletions internal/controller/isbservicerollout_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controller

import (
"context"
"encoding/json"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -26,9 +27,9 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

numaflowv1 "github.com/numaproj/numaflow/pkg/apis/numaflow/v1alpha1"
apiv1 "github.com/numaproj/numaplane/pkg/apis/numaplane/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var _ = Describe("ISBServiceRollout Controller", func() {
Expand All @@ -41,30 +42,27 @@ var _ = Describe("ISBServiceRollout Controller", func() {

ctx := context.Background()

isbsSpec := numaflowv1.InterStepBufferServiceSpec{
Redis: &numaflowv1.RedisBufferService{},
JetStream: &numaflowv1.JetStreamBufferService{
Version: "latest",
Persistence: &numaflowv1.PersistenceStrategy{
VolumeSize: &numaflowv1.DefaultVolumeSize,
},
},
}

isbsSpecRaw, err := json.Marshal(isbsSpec)
Expect(err).ToNot(HaveOccurred())

isbServiceRollout := &apiv1.ISBServiceRollout{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: isbServiceRolloutName,
},
Spec: apiv1.ISBServiceRolloutSpec{
InterStepBufferService: runtime.RawExtension{
Raw: []byte(`{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "my-service"
},
"spec": {
"selector": {
"app": "MyApp"
},
"ports": [{
"protocol": "TCP",
"port": 80,
"targetPort": 9376
}]
}
}`),
Raw: isbsSpecRaw,
},
},
}
Expand All @@ -82,6 +80,8 @@ var _ = Describe("ISBServiceRollout Controller", func() {
}, timeout, interval).Should(BeTrue())

By("Verifying the content of the ISBServiceRollout spec field")
createdInterStepBufferServiceSpec := numaflowv1.InterStepBufferService{}
Expect(json.Unmarshal(createdResource.Spec.InterStepBufferService.Raw, &createdInterStepBufferServiceSpec)).ToNot(HaveOccurred())
Expect(createdResource.Spec).Should(Equal(isbServiceRollout.Spec))
})

Expand All @@ -91,35 +91,36 @@ var _ = Describe("ISBServiceRollout Controller", func() {
currentISBServiceRollout := &apiv1.ISBServiceRollout{}
Expect(k8sClient.Get(ctx, resourceLookupKey, currentISBServiceRollout)).ToNot(HaveOccurred())

// Update the spec here
currentISBServiceRollout.Spec.InterStepBufferService = runtime.RawExtension{
Raw: []byte(`{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "my-updated-service"
},
"spec": {
"selector": {
"app": "MyUpdatedApp"
},
"ports": [{
"protocol": "TCP",
"port": 8080,
"targetPort": 9377
}]
}
}`),
// Prepare a new spec for update
newIsbsSpec := numaflowv1.InterStepBufferServiceSpec{
Redis: &numaflowv1.RedisBufferService{},
JetStream: &numaflowv1.JetStreamBufferService{
Version: "an updated version",
Persistence: &numaflowv1.PersistenceStrategy{
VolumeSize: &numaflowv1.DefaultVolumeSize,
},
},
}

newIsbsSpecRaw, err := json.Marshal(newIsbsSpec)
Expect(err).ToNot(HaveOccurred())

// Update the spec
currentISBServiceRollout.Spec.InterStepBufferService = runtime.RawExtension{Raw: newIsbsSpecRaw}

Expect(k8sClient.Update(ctx, currentISBServiceRollout)).ToNot(HaveOccurred())

By("Verifying the content of the ISBServiceRollout spec field")
Eventually(func() apiv1.ISBServiceRolloutSpec {
updatedResource := &apiv1.ISBServiceRollout{}
_ = k8sClient.Get(ctx, resourceLookupKey, updatedResource)

createdInterStepBufferServiceSpec := numaflowv1.InterStepBufferService{}
Expect(json.Unmarshal(updatedResource.Spec.InterStepBufferService.Raw, &createdInterStepBufferServiceSpec)).ToNot(HaveOccurred())

return updatedResource.Spec
}, timeout, interval).Should(Equal(currentISBServiceRollout.Spec))

})

It("Should delete the ISBServiceRollout", func() {
Expand Down

0 comments on commit 36c030c

Please sign in to comment.