Skip to content

Commit

Permalink
🌱 Update integration tests (#408)
Browse files Browse the repository at this point in the history
* Use the Ginkgo CLI for tests

The output is much clearer

Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>

* Add the compliance API service to the framework

Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>

* Refactor the addon tests

This will make adding addon tests in the future
much more straightforward.

Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>

---------

Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
  • Loading branch information
dhaiducek authored Apr 2, 2024
1 parent c24cfa7 commit 41a5ed4
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 186 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10

name: Create Release

env:
GO_VERSION: '1.21'
GO_VERSION: "1.21"

jobs:
build:
Expand Down
112 changes: 50 additions & 62 deletions pkg/cmd/addon/enable/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,33 @@ import (
)

var _ = ginkgo.Describe("addon enable", func() {
var cluster1Name string
var cluster2Name string
var suffix string
var err error

appMgrAddonName := "application-manager"
// Array of addons to check
var addons = []string{
"application-manager",
"governance-policy-framework",
"config-policy-controller",
}

var (
cluster1Name string
cluster2Name string
suffix string
err error
)

ginkgo.BeforeEach(func() {
suffix = rand.String(5)
cluster1Name = fmt.Sprintf("cluster-%s", suffix)
cluster2Name = fmt.Sprintf("cluster-%s", rand.String(5))
})

ginkgo.AfterEach(func() {
ginkgo.By("Delete cluster management add-on")
err = addonClient.AddonV1alpha1().ClusterManagementAddOns().Delete(
context.Background(), appMgrAddonName, metav1.DeleteOptions{})
if err != nil {
if !errors.IsNotFound(err) {
for _, addon := range addons {
err = addonClient.AddonV1alpha1().ClusterManagementAddOns().Delete(
context.Background(), addon, metav1.DeleteOptions{})
if err != nil && !errors.IsNotFound(err) {
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}
}
Expand Down Expand Up @@ -84,73 +93,53 @@ var _ = ginkgo.Describe("addon enable", func() {

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)
assertCreatingClusterManagementAddOn(appMgrAddonName)

o := Options{
Namespace: "open-cluster-management-agent-addon",
Streams: streams,
}

addons := []string{appMgrAddonName}
clusters := []string{cluster1Name, cluster1Name, cluster1Name}
// Generate entries for the `runWithClient` test table
addonTests := []ginkgo.TableEntry{}
for _, addon := range addons {
addonTests = append(addonTests, ginkgo.Entry(addon, addon))
}

err := o.runWithClient(clusterClient, addonClient, addons, clusters)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
ginkgo.DescribeTableSubtree("runWithClient",
func(addon string) {
ginkgo.It("Should create ManagedClusterAddOn "+addon+" in each ManagedCluster namespace successfully", func() {
assertCreatingClusters(cluster1Name)
assertCreatingClusters(cluster2Name)
assertCreatingClusterManagementAddOn(addon)

gomega.Eventually(func() error {
_, err := addonClient.AddonV1alpha1().ManagedClusterAddOns(cluster1Name).Get(context.Background(), appMgrAddonName, metav1.GetOptions{})
if err != nil {
return err
o := Options{
Namespace: "open-cluster-management-agent-addon",
Streams: streams,
}
return nil
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())
})

ginkgo.It("Should create application-manager ManagedClusterAddOns in each ManagedCluster namespace successfully", func() {
assertCreatingClusters(cluster1Name)
assertCreatingClusters(cluster2Name)
assertCreatingClusterManagementAddOn(appMgrAddonName)

o := Options{
Namespace: "open-cluster-management-agent-addon",
Streams: streams,
}

addons := []string{appMgrAddonName}
clusters := []string{cluster1Name, cluster2Name, cluster1Name}
clusters := []string{cluster1Name, cluster2Name}

err := o.runWithClient(clusterClient, addonClient, addons, clusters)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

gomega.Eventually(func() error {
_, err := addonClient.AddonV1alpha1().ManagedClusterAddOns(cluster1Name).Get(context.Background(), appMgrAddonName, metav1.GetOptions{})
if err != nil {
return err
}
return nil
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())
err := o.runWithClient(clusterClient, addonClient, []string{addon}, clusters)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

gomega.Eventually(func() error {
_, err := addonClient.AddonV1alpha1().ManagedClusterAddOns(cluster2Name).Get(context.Background(), appMgrAddonName, metav1.GetOptions{})
if err != nil {
return err
for _, cluster := range clusters {
gomega.Eventually(
addonClient.AddonV1alpha1().ManagedClusterAddOns(cluster).Get,
eventuallyTimeout, eventuallyInterval,
).WithArguments(
context.Background(), addon, metav1.GetOptions{},
).ShouldNot(gomega.BeNil())
}
return nil
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())
})
})
},
addonTests,
)

ginkgo.Context("runWithClient - invalid configurations", func() {
ginkgo.It("Should not create a ManagedClusterAddOn because ManagedCluster doesn't exist", func() {
assertCreatingClusterManagementAddOn(appMgrAddonName)
for _, addon := range addons {
assertCreatingClusterManagementAddOn(addon)
}

clusterName := "no-such-cluster"
o := Options{
Streams: streams,
}

addons := []string{appMgrAddonName}
clusters := []string{clusterName}

err := o.runWithClient(clusterClient, addonClient, addons, clusters)
Expand All @@ -165,7 +154,6 @@ var _ = ginkgo.Describe("addon enable", func() {
Streams: streams,
}

addons := []string{appMgrAddonName}
clusters := []string{cluster1Name, cluster1Name, cluster1Name}

err := o.runWithClient(clusterClient, addonClient, addons, clusters)
Expand Down
12 changes: 4 additions & 8 deletions pkg/cmd/install/hubaddon/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,11 @@ func (o *Options) validate() (err error) {
}

versionBundle, err := version.GetVersionBundle(o.bundleVersion)

if err != nil {
klog.Errorf("unable to retrieve version "+o.bundleVersion, err)
return err
}

o.values.BundleVersion = BundleVersion{
AppAddon: versionBundle.AppAddon,
PolicyAddon: versionBundle.PolicyAddon,
}
o.values.BundleVersion = versionBundle

return nil
}
Expand Down Expand Up @@ -139,6 +134,7 @@ func (o *Options) runWithClient() error {
"addon/policy/propagator_clusterrolebinding.yaml",
"addon/policy/propagator_role.yaml",
"addon/policy/propagator_rolebinding.yaml",
"addon/policy/propagator_service.yaml",
"addon/policy/propagator_serviceaccount.yaml",
"addon/policy/clustermanagementaddon_configpolicy.yaml",
"addon/policy/clustermanagementaddon_policyframework.yaml",
Expand All @@ -147,7 +143,7 @@ func (o *Options) runWithClient() error {

err := r.Apply(scenario.Files, o.values, files...)
if err != nil {
return err
return fmt.Errorf("Error deploying framework deployment dependencies: %w", err)
}

deployments := []string{
Expand All @@ -157,7 +153,7 @@ func (o *Options) runWithClient() error {

err = r.Apply(scenario.Files, o.values, deployments...)
if err != nil {
return err
return fmt.Errorf("Error deploying framework deployments: %w", err)
}

fmt.Fprintf(o.Streams.Out, "Installing built-in %s add-on to the Hub cluster...\n", policyFrameworkAddonName)
Expand Down
Loading

0 comments on commit 41a5ed4

Please sign in to comment.