Skip to content

Commit

Permalink
Add an e2e test on init update
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Qiu <jqiu@redhat.com>
  • Loading branch information
qiujian16 committed Nov 8, 2023
1 parent 8541556 commit f5efa0b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/e2e/clusteradm/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"k8s.io/kubectl/pkg/scheme"
addonclientset "open-cluster-management.io/api/client/addon/clientset/versioned"
clusterv1client "open-cluster-management.io/api/client/cluster/clientset/versioned"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
clusterv1 "open-cluster-management.io/api/cluster/v1"

"testing"
Expand All @@ -30,6 +31,7 @@ var apiExtensionsClient apiextensionsclient.Interface
var dynamicClient dynamic.Interface
var clusterClient clusterv1client.Interface
var addonClient addonclientset.Interface
var operatorClient operatorclient.Interface

func TestE2EClusteradm(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
Expand Down Expand Up @@ -72,6 +74,8 @@ var _ = ginkgo.BeforeSuite(func() {
gomega.Expect(err).NotTo(gomega.HaveOccurred())
addonClient, err = addonclientset.NewForConfig(hubConfig)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
operatorClient, err = operatorclient.NewForConfig(hubConfig)
gomega.Expect(err).NotTo(gomega.HaveOccurred())

err = clusterv1.AddToScheme(scheme.Scheme)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand Down
44 changes: 44 additions & 0 deletions test/e2e/clusteradm/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright Contributors to the Open Cluster Management project

package clusteradme2e

import (
"context"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var _ = ginkgo.Describe("test clusteradm with bootstrap token in singleton mode", func() {
ginkgo.BeforeEach(func() {
ginkgo.By("clear e2e environment...")
err := e2e.ClearEnv()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})

ginkgo.Context("init hub again to change the feature flag", func() {
ginkgo.By("init hub with bootstrap token")
err := e2e.Clusteradm().Init(
"--use-bootstrap-token",
"--context", e2e.Cluster().Hub().Context(),
"--bundle-version=latest",
)
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "clusteradm init error")

cm, err := operatorClient.OperatorV1().ClusterManagers().Get(context.TODO(), "cluster-manager", metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(len(cm.Spec.RegistrationConfiguration.FeatureGates)).Should(gomega.Equal(1))

err = e2e.Clusteradm().Init(
"--use-bootstrap-token",
"--context", e2e.Cluster().Hub().Context(),
"--feature-gates=ManagedClusterAutoApproval=true",
"--bundle-version=latest",
)
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "clusteradm init error")
cm, err = operatorClient.OperatorV1().ClusterManagers().Get(context.TODO(), "cluster-manager", metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(len(cm.Spec.RegistrationConfiguration.FeatureGates)).Should(gomega.Equal(2))
})
})

0 comments on commit f5efa0b

Please sign in to comment.