Skip to content

Commit

Permalink
chore(#330): add system-tests for destination
Browse files Browse the repository at this point in the history
  • Loading branch information
kirederik committed Jan 31, 2025
1 parent 3acebd6 commit 3c915e8
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/v1alpha1/destination_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type DestinationStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,path=destinations,categories=kratix
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`,description="Indicates the destination is ready to use",default="False"
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`,description="Indicates the destination is ready to use"

// Destination is the Schema for the Destinations API
type Destination struct {
Expand Down
23 changes: 23 additions & 0 deletions test/system/assets/destination/worker-3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: platform.kratix.io/v1alpha1
kind: BucketStateStore
metadata:
name: destination-test-store
spec:
authMethod: accessKey
bucketName: kratix
endpoint: minio.kratix-platform-system.svc.cluster.local
insecure: true
secretRef:
name: minio-credentials
namespace: default
---
apiVersion: platform.kratix.io/v1alpha1
kind: Destination
metadata:
name: worker-3
labels:
environment: dev
spec:
stateStoreRef:
name: destination-test-store
kind: BucketStateStore
92 changes: 92 additions & 0 deletions test/system/destination_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package system_test

import (
"strings"
"time"

"github.com/syntasso/kratix/test/kubeutils"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Destinations", func() {
Describe("status and events", func() {
var destinationName string
BeforeEach(func() {
destinationName = "worker-3"

SetDefaultEventuallyTimeout(2 * time.Minute)
SetDefaultEventuallyPollingInterval(2 * time.Second)
kubeutils.SetTimeoutAndInterval(2*time.Minute, 2*time.Second)

platform.Kubectl("apply", "-f", "assets/destination/worker-3.yaml")
})

AfterEach(func() {
platform.Kubectl("delete", "-f", "assets/destination/worker-3.yaml")
})

It("properly set the conditions and events", func() {
By("showing `Ready` as true", func() {
Eventually(func() string {
return platform.Kubectl("get", "destinations", destinationName)
}).Should(ContainSubstring("True"))
})

By("firing the success event", func() {
Eventually(func() string {
describeOutput := strings.Split(platform.Kubectl("describe", "destinations", destinationName), "\n")
return describeOutput[len(describeOutput)-2]
}).Should(ContainSubstring(`Destination "worker-3" is ready`))
})

// set stateStoreRef to a non-existing one
platform.Kubectl("patch", "destinations", destinationName, "--type=merge", "-p", `{"spec":{"stateStoreRef":{"name":"non-existing"}}}`)

By("showing `Ready` as False when the State Store is wrong", func() {
Eventually(func() string {
return platform.Kubectl("get", "destinations", destinationName)
}).Should(ContainSubstring("False"))
})

By("firing a failure event", func() {
Eventually(func() string {
describeOutput := strings.Split(platform.Kubectl("describe", "destinations", destinationName), "\n")
return describeOutput[len(describeOutput)-2]
}).Should(ContainSubstring("Failed to write test documents"))
})

// restore the ready condition
platform.Kubectl("apply", "-f", "assets/destination/worker-3.yaml")

By("showing `Ready` as true", func() {
Eventually(func() string {
return platform.Kubectl("get", "destinations", destinationName)
}).Should(ContainSubstring("True"))
})

By("firing the success event", func() {
Eventually(func() string {
describeOutput := strings.Split(platform.Kubectl("describe", "destinations", destinationName), "\n")
return describeOutput[len(describeOutput)-2]
}).Should(ContainSubstring(`Destination "worker-3" is ready`))
})

// update the underlying state store with an invalid secret
platform.Kubectl("patch", "bucketstatestore", "destination-test-store", "--type=merge", "-p", `{"spec":{"secretRef":{"name":"non-existing"}}}`)
By("showing `Ready` as False when the State Store is wrong", func() {
Eventually(func() string {
return platform.Kubectl("get", "destinations", destinationName)
}).Should(ContainSubstring("False"))
})

By("firing a failure event", func() {
Eventually(func() string {
describeOutput := strings.Split(platform.Kubectl("describe", "destinations", destinationName), "\n")
return describeOutput[len(describeOutput)-2]
}).Should(ContainSubstring("Failed to write test documents"))
})
})
})
})

0 comments on commit 3c915e8

Please sign in to comment.