Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 21 additions & 37 deletions pkg/cmd/addon/enable/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ package enable
import (
"context"
"fmt"
"os"

"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/cli-runtime/pkg/genericclioptions"

clusterapiv1 "open-cluster-management.io/api/cluster/v1"
)
Expand All @@ -20,6 +22,8 @@ var _ = ginkgo.Describe("addon enable", func() {
var suffix string
var err error

appMgrAddonName := "application-manager"

ginkgo.BeforeEach(func() {
suffix = rand.String(5)
cluster1Name = fmt.Sprintf("cluster-%s", suffix)
Expand Down Expand Up @@ -47,19 +51,21 @@ var _ = ginkgo.Describe("addon enable", func() {
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}

streams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}

ginkgo.Context("runWithClient", func() {
ginkgo.It("Should create an application-manager ManagedClusterAddOn in ManagedCluster namespace successfully", func() {
assertCreatingClusters(cluster1Name)

o := Options{
values: Values{
clusters: []string{cluster1Name},
addons: []string{appMgrAddonName},
},
namespace: "open-cluster-management-agent-addon",
Streams: streams,
}

err := o.runWithClient(clusterClient, kubeClient, apiExtensionsClient, dynamicClient, false)
addons := []string{appMgrAddonName}
clusters := []string{cluster1Name}

err := o.runWithClient(clusterClient, kubeClient, apiExtensionsClient, dynamicClient, false, addons, clusters)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

gomega.Eventually(func() error {
Expand All @@ -76,14 +82,14 @@ var _ = ginkgo.Describe("addon enable", func() {
assertCreatingClusters(cluster2Name)

o := Options{
values: Values{
clusters: []string{cluster1Name, cluster2Name},
addons: []string{appMgrAddonName},
},
namespace: "open-cluster-management-agent-addon",
Streams: streams,
}

err := o.runWithClient(clusterClient, kubeClient, apiExtensionsClient, dynamicClient, false)
addons := []string{appMgrAddonName}
clusters := []string{cluster1Name, cluster2Name}

err := o.runWithClient(clusterClient, kubeClient, apiExtensionsClient, dynamicClient, false, addons, clusters)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

gomega.Eventually(func() error {
Expand All @@ -106,37 +112,15 @@ var _ = ginkgo.Describe("addon enable", func() {
ginkgo.It("Should not create a ManagedClusterAddOn because ManagedCluster doesn't exist", func() {
clusterName := "no-such-cluster"
o := Options{
values: Values{
clusters: []string{clusterName},
addons: []string{appMgrAddonName},
},
Streams: streams,
}

err := o.runWithClient(clusterClient, kubeClient, apiExtensionsClient, dynamicClient, false)
addons := []string{appMgrAddonName}
clusters := []string{clusterName}

err := o.runWithClient(clusterClient, kubeClient, apiExtensionsClient, dynamicClient, false, addons, clusters)
gomega.Expect(err).To(gomega.HaveOccurred())
})

ginkgo.It("Should not create a ManagedClusterAddOn because it's not a valid add-on name", func() {
assertCreatingClusters(cluster1Name)

addonName := "no-such-addon"
o := Options{
values: Values{
clusters: []string{cluster1Name},
addons: []string{addonName},
},
}

err := o.runWithClient(clusterClient, kubeClient, apiExtensionsClient, dynamicClient, false)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

gomega.Consistently(func() error {
_, err := addonClient.AddonV1alpha1().ManagedClusterAddOns(cluster1Name).Get(context.Background(), addonName, metav1.GetOptions{})
if err != nil {
return err
}
return nil
}, consistentlyTimeout, consistentlyInterval).Should(gomega.HaveOccurred())
})
})
})
2 changes: 1 addition & 1 deletion pkg/cmd/install/addons/scenario/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"open-cluster-management.io/clusteradm/pkg/helpers/asset"
)

//go:embed addons
//go:embed addon
var files embed.FS

func GetScenarioResourcesReader() *asset.ScenarioResourcesReader {
Expand Down
2 changes: 1 addition & 1 deletion test/integration-test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ clean-integration-test:
clean: clean-integration-test

test-integration: ensure-kubebuilder-tools
go test -v ./pkg/cmd/enable/addons ./pkg/cmd/install/addons
go test -v ./pkg/cmd/addon/enable ./pkg/cmd/install/addons
.PHONY: test-integration