Skip to content

Commit

Permalink
test: add a simple test for XlineCluster
Browse files Browse the repository at this point in the history
Signed-off-by: Phoeniix Zhao <[email protected]>
  • Loading branch information
Phoenix500526 committed Nov 28, 2023
1 parent 06260b1 commit 19d51fb
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions internal/controller/xlinecluster_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controller

import (
"context"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
xapi "github.com/xline-kv/xline-operator/api/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

// +kubebuilder:docs-gen:collapse=Imports

var _ = Describe("XlineCluster controller", func() {

// Define utility constants for object names and testing timeouts/durations and intervals.
const (
XlineClusterName = "test-xline-cluster"
XlineClusterNamespace = "default"
XlineClusterStsName = "test-xline-cluster-sts"
XlineClusterSvcName = "test-xline-cluster-svc"

timeout = time.Second * 10
duration = time.Second * 10
interval = time.Millisecond * 250
)

Context("When updating XlineCluster Status", func() {
It("Should increase XlineCluster Status count when a new XlineCluster resource is created", func() {
By("By creating a new XlineCluster")
ctx := context.Background()
image := "test-image"
xlineCluster := &xapi.XlineCluster{
TypeMeta: metav1.TypeMeta{
APIVersion: "xline.kvstore.datenlord.com/v1alpha1",
Kind: "XlineCluster",
},
ObjectMeta: metav1.ObjectMeta{
Name: XlineClusterName,
Namespace: XlineClusterNamespace,
},
Spec: xapi.XlineClusterSpec{
Version: "latest",
Image: &image,
Replicas: 3,
},
}
Expect(k8sClient.Create(ctx, xlineCluster)).Should(Succeed())

xcLookupKey := types.NamespacedName{Name: XlineClusterName, Namespace: XlineClusterNamespace}
createdXlineCluster := &xapi.XlineCluster{}

// We'll need to retry getting this newly created CronJob, given that creation may not immediately happen.
Eventually(func() bool {
err := k8sClient.Get(ctx, xcLookupKey, createdXlineCluster)
if err != nil {

Check failure on line 74 in internal/controller/xlinecluster_controller_test.go

View workflow job for this annotation

GitHub Actions / Lint Check

S1008: should use 'return err == nil' instead of 'if err != nil { return false }; return true' (gosimple)
return false
}
return true
}, timeout, interval).Should(BeTrue())
// Let's make sure our Schedule string value was properly converted/handled.
Expect(createdXlineCluster.Spec.Replicas).Should(Equal(int32(3)))
Expect(createdXlineCluster.Spec.Version).Should(Equal("latest"))
Expect(*createdXlineCluster.Spec.Image).Should(Equal(image))

})
})

})

0 comments on commit 19d51fb

Please sign in to comment.