Skip to content

Commit

Permalink
Add apply() test for multi-cluster/kustomize example
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Manno committed Jun 10, 2022
1 parent db9a635 commit 0c524d3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
72 changes: 56 additions & 16 deletions integration/apply_test.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,58 @@
package bundle_test
package integration_test

import (
"context"
"os"

"github.com/rancher/fleet/modules/cli/apply"
"github.com/rancher/fleet/modules/cli/pkg/client"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"

"gopkg.in/yaml.v2"

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

var _ = Describe("Apply", func() {
currentDir, _ := os.Getwd()
var (
c *client.Getter
currentDir string
dir string
)

When("Apply", func() {
AfterEach(func() {
err := os.Chdir(currentDir)
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
err := os.Chdir(currentDir)
Expect(err).ToNot(HaveOccurred())
})

It("creates a bundle", func() {
client := client.NewGetter("", "", "fleet-local")
// behaves different if in the same dir
name := "test"
err := os.Chdir(examplePath("single-cluster/helm"))
baseDirs := []string{}
Expect(err).ToNot(HaveOccurred())
JustBeforeEach(func() {
c = client.NewGetter("", "", "fleet-local")

// write to buffer, instead of cluster
// apply() behaves different if in the same dir, so chdir first
currentDir, _ = os.Getwd()
err := os.Chdir(dir)
Expect(err).ToNot(HaveOccurred())
})

When("given an existing directory", func() {
BeforeEach(func() {
dir = examplePath("single-cluster", "helm")
})

It("creates a bundle and adds the label", func() {
buf := gbytes.NewBuffer()
opts := &apply.Options{
// write to buffer, instead of cluster
Output: buf,
// add label to bundles
Labels: map[string]string{"fleet.cattle.io/commit": "fake"},
}

err = apply.Apply(context.Background(), client, name, baseDirs, opts)
name := "test"
baseDirs := []string{}
err := apply.Apply(context.Background(), c, name, baseDirs, opts)
Expect(err).ToNot(HaveOccurred())
Expect(buf).To(gbytes.Say(`apiVersion: fleet.cattle.io/v1alpha1
kind: Bundle
Expand All @@ -49,4 +65,28 @@ metadata:
Expect(buf).To(gbytes.Say("app: redis"))
})
})

When("applying a multi-cluster example", func() {
BeforeEach(func() {
dir = examplePath("multi-cluster", "kustomize")
})

It("creates a bundle with all the resources", func() {
buf := gbytes.NewBuffer()
opts := &apply.Options{Output: buf}

name := "test"
baseDirs := []string{}
err := apply.Apply(context.Background(), c, name, baseDirs, opts)
Expect(err).ToNot(HaveOccurred())

b := &fleet.Bundle{}
err = yaml.Unmarshal(buf.Contents(), b)
Expect(err).ToNot(HaveOccurred())

Expect(b.Name).To(BeEmpty())
Expect(b.Spec.Resources).To(HaveLen(17))
Expect(b.Spec.Targets).To(HaveLen(3))
})
})
})
2 changes: 1 addition & 1 deletion integration/match_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle_test
package integration_test

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion integration/suite_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle_test
package integration_test

import (
"path"
Expand Down

0 comments on commit 0c524d3

Please sign in to comment.