Skip to content

Commit

Permalink
test: increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
em-r authored and Sajiyah-Salat committed Jun 11, 2023
1 parent adf43b5 commit 33e3d62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions pkg/cli/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,32 @@ var _ = Describe("Discover external plugins", func() {
Expect(err.Error()).To(ContainSubstring("host not supported"))
})

It("should return full path to the external plugins", func() {
It("should return full path to the external plugins without XDG_CONFIG_HOME", func() {
if _, ok := os.LookupEnv("XDG_CONFIG_HOME"); ok {
err = os.Setenv("XDG_CONFIG_HOME", "")
Expect(err).To(BeNil())
}

home := os.Getenv("HOME")

pluginsRoot, err := getPluginsRoot("darwin")
Expect(err).To(BeNil())
expected := filepath.Join(home, "Library", "Application Support", "kubebuilder", "plugins")
Expect(pluginsRoot).To(Equal(expected))

pluginsRoot, err = getPluginsRoot("linux")
Expect(err).To(BeNil())
expected = filepath.Join(home, ".config", "kubebuilder", "plugins")
Expect(pluginsRoot).To(Equal(expected))
})

It("should return full path to the external plugins with XDG_CONFIG_HOME", func() {
err = os.Setenv("XDG_CONFIG_HOME", "/some/random/path")
Expect(err).To(BeNil())

pluginsRoot, err := getPluginsRoot(runtime.GOOS)
Expect(err).To(BeNil())
Expect(pluginsRoot).To(Equal("/some/random/path/kubebuilder/plugins"))

})

It("should return error when home directory is set to empty", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
)

var (
supportedPlatforms = []string{"linux", "darwin"}
supportedPlatforms = []string{"darwin", "linux"}
)

func (c CLI) newRootCmd() *cobra.Command {
Expand Down

0 comments on commit 33e3d62

Please sign in to comment.