-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for enable toolkit flags/config
- Loading branch information
1 parent
9e7e261
commit 000963f
Showing
3 changed files
with
201 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
package enable | ||
|
||
import ( | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5" | ||
. "github.com/weaveworks/eksctl/pkg/ctl/ctltest" | ||
) | ||
|
||
var _ = Describe("enable toolkit", func() { | ||
var mockEnableToolkitCmd func(args ...string) *MockCmd | ||
|
||
BeforeEach(func() { | ||
mockEnableToolkitCmd = func(args ...string) *MockCmd { | ||
return NewMockCmd(configureAndRun, "enable", args...) | ||
} | ||
}) | ||
|
||
When("--config-file is not provided", func() { | ||
It("should fail", func() { | ||
cmd := mockEnableToolkitCmd("toolkit") | ||
out, err := cmd.Execute() | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err).To(MatchError("--config-file/-f <file> must be set")) | ||
Expect(out).To(ContainSubstring("Usage")) | ||
}) | ||
}) | ||
|
||
When("name arg is provided", func() { | ||
It("should fail", func() { | ||
cmd := mockEnableToolkitCmd("toolkit", "foo") | ||
out, err := cmd.Execute() | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err).To(MatchError("name argument is not supported")) | ||
Expect(out).To(ContainSubstring("Usage")) | ||
}) | ||
}) | ||
|
||
When("--cluster is provided", func() { | ||
It("should fail", func() { | ||
cmd := mockEnableToolkitCmd("toolkit", "--cluster", "foo") | ||
out, err := cmd.Execute() | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err).To(MatchError("unknown flag: --cluster")) | ||
Expect(out).To(ContainSubstring("Usage")) | ||
}) | ||
}) | ||
|
||
When("--region is provided", func() { | ||
It("should fail", func() { | ||
cmd := mockEnableToolkitCmd("toolkit", "--region", "foo") | ||
out, err := cmd.Execute() | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err).To(MatchError("unknown flag: --region")) | ||
Expect(out).To(ContainSubstring("Usage")) | ||
}) | ||
}) | ||
|
||
When("--config-file is provided", func() { | ||
var ( | ||
configFile string | ||
cfg *api.ClusterConfig | ||
|
||
cmd *MockCmd | ||
err error | ||
) | ||
|
||
BeforeEach(func() { | ||
// Minimal valid cluster config for the command to work | ||
cfg = &api.ClusterConfig{ | ||
TypeMeta: api.ClusterConfigTypeMeta(), | ||
Metadata: &api.ClusterMeta{ | ||
Name: "cluster-1", | ||
Region: "us-west-2", | ||
}, | ||
Git: &api.Git{ | ||
Toolkit: &api.Toolkit{ | ||
GitProvider: "github", | ||
Repository: "repo1", | ||
Owner: "username", | ||
}, | ||
}, | ||
} | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
configFile = CreateConfigFile(cfg) | ||
cmd = mockEnableToolkitCmd("toolkit", "-f", configFile) | ||
_, err = cmd.Execute() | ||
}) | ||
|
||
AfterEach(func() { | ||
Expect(os.Remove(configFile)).To(Succeed()) | ||
}) | ||
|
||
It("succeeds with the basic configuration", func() { | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
toolkitCfg := cmd.Cmd.ClusterConfig.Git.Toolkit | ||
Expect(toolkitCfg).ToNot(BeNil()) | ||
Expect(toolkitCfg.Repository).To(Equal("repo1")) | ||
Expect(toolkitCfg.GitProvider).To(Equal("github")) | ||
Expect(toolkitCfg.Owner).To(Equal("username")) | ||
}) | ||
|
||
It("loads the correct default", func() { | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
toolkitCfg := cmd.Cmd.ClusterConfig.Git.Toolkit | ||
Expect(toolkitCfg).ToNot(BeNil()) | ||
Expect(toolkitCfg.Namespace).To(Equal("flux-system")) | ||
}) | ||
|
||
When("metadata.cluster is not provided", func() { | ||
BeforeEach(func() { | ||
cfg.Metadata.Name = "" | ||
}) | ||
|
||
It("fails", func() { | ||
Expect(err).To(MatchError("metadata.name must be set")) | ||
}) | ||
}) | ||
|
||
When("metadata.region is not provided", func() { | ||
BeforeEach(func() { | ||
cfg.Metadata.Region = "" | ||
}) | ||
|
||
It("fails", func() { | ||
Expect(err).To(MatchError("metadata.region must be set")) | ||
}) | ||
}) | ||
|
||
When("git.toolkit is not provided", func() { | ||
BeforeEach(func() { | ||
cfg.Git.Toolkit = nil | ||
}) | ||
|
||
It("fails", func() { | ||
Expect(err).To(MatchError("no configuration found for enable toolkit")) | ||
}) | ||
}) | ||
|
||
When("git.toolkit.gitProvider is not provided", func() { | ||
BeforeEach(func() { | ||
cfg.Git.Toolkit.GitProvider = "" | ||
}) | ||
|
||
It("fails", func() { | ||
Expect(err).To(MatchError("git.toolkit.gitProvider must be set")) | ||
}) | ||
}) | ||
|
||
When("git.toolkit.repository is not provided", func() { | ||
BeforeEach(func() { | ||
cfg.Git.Toolkit.Repository = "" | ||
}) | ||
|
||
It("fails", func() { | ||
Expect(err).To(MatchError("git.toolkit.repository must be set")) | ||
}) | ||
}) | ||
|
||
When("git.toolkit.owner is not provided", func() { | ||
BeforeEach(func() { | ||
cfg.Git.Toolkit.Owner = "" | ||
}) | ||
|
||
It("fails", func() { | ||
Expect(err).To(MatchError("git.toolkit.owner must be set")) | ||
}) | ||
}) | ||
}) | ||
}) |