Skip to content
Closed
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
14 changes: 8 additions & 6 deletions pkg/kn/commands/plugin/plugin_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func (o *PluginFlags) complete(cmd *cobra.Command) error {
}

func (o *PluginFlags) run() error {
pluginsFound := false
isFirstFile := true
pluginErrors := []error{}
pluginWarnings := 0
Expand All @@ -120,7 +119,15 @@ func (o *PluginFlags) run() error {
continue
}

// Treat a missing dir as just something we skip - meaning
// it's ok to include a path that might not exist yet or you
// don't have access to - so just skip it
if _, err := os.Stat(dir); os.IsNotExist(err) {
continue
}

files, err := ioutil.ReadDir(dir)
// However, error reading a dir that does exist is an issue
if err != nil {
if _, ok := err.(*os.PathError); ok {
fmt.Fprintf(o.ErrOut, "Unable read directory '%s' from your plugins path: %v. Skipping...", dir, err)
Expand All @@ -143,7 +150,6 @@ func (o *PluginFlags) run() error {
fmt.Fprintf(o.ErrOut, "The following compatible plugins are available, using options:\n")
fmt.Fprintf(o.ErrOut, " - plugins dir: '%s'\n", commands.Cfg.PluginsDir)
fmt.Fprintf(o.ErrOut, " - lookup plugins in path: '%t'\n\n", commands.Cfg.LookupPluginsInPath)
pluginsFound = true
isFirstFile = false
}

Expand All @@ -162,10 +168,6 @@ func (o *PluginFlags) run() error {
}
}

if !pluginsFound {
pluginErrors = append(pluginErrors, fmt.Errorf("warning: unable to find any kn plugins in your plugin path: '%s'", o.PluginPaths))
}

if pluginWarnings > 0 {
if pluginWarnings == 1 {
pluginErrors = append(pluginErrors, fmt.Errorf("error: one plugin warning was found"))
Expand Down
36 changes: 4 additions & 32 deletions pkg/kn/commands/plugin/plugin_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,6 @@ func TestPluginList(t *testing.T) {
t.Run("when --lookup-plugins-in-path is true", func(t *testing.T) {
var pluginPath string

beforeEach := func(t *testing.T) {
err = os.Setenv("PATH", tmpPathDir)
assert.Assert(t, err == nil)
}

t.Run("no plugins installed", func(t *testing.T) {
setup(t)
defer cleanup(t)
beforeEach(t)

t.Run("warns user that no plugins found", func(t *testing.T) {
rootCmd.SetArgs([]string{"plugin", "list", "--lookup-plugins-in-path=true", pluginsDirFlag})
err = rootCmd.Execute()
assert.Assert(t, err != nil)
assert.Assert(t, strings.Contains(err.Error(), "warning: unable to find any kn plugins in your plugin path:"))
})
})

t.Run("plugins installed", func(t *testing.T) {
t.Run("with valid plugin in $PATH", func(t *testing.T) {
beforeEach := func(t *testing.T) {
Expand All @@ -113,21 +95,19 @@ func TestPluginList(t *testing.T) {
})
})

t.Run("with non-executable plugin", func(t *testing.T) {
t.Run("with missing plugin path", func(t *testing.T) {
beforeEach := func(t *testing.T) {
pluginPath = CreateTestPluginInPath(t, KnTestPluginName, KnTestPluginScript, FileModeReadable, tmpPathDir)
assert.Assert(t, pluginPath != "")
pluginPath = "/tmp/does-not-exist"
}

t.Run("warns user plugin invalid", func(t *testing.T) {
t.Run("don't warns user of missing path", func(t *testing.T) {
setup(t)
defer cleanup(t)
beforeEach(t)

rootCmd.SetArgs([]string{"plugin", "list", "--lookup-plugins-in-path=true", pluginsDirFlag})
err = rootCmd.Execute()
assert.Assert(t, err != nil)
assert.Assert(t, strings.Contains(err.Error(), "warning: unable to find any kn plugins in your plugin path:"))
assert.Assert(t, err == nil)
})
})

Expand Down Expand Up @@ -228,13 +208,5 @@ func TestPluginList(t *testing.T) {
assert.Assert(t, err == nil)
})

t.Run("no plugins installed", func(t *testing.T) {
setup(t)
defer cleanup(t)

rootCmd.SetArgs([]string{"plugin", "list", pluginsDirFlag})
err = rootCmd.Execute()
assert.Assert(t, err != nil)
})
})
}