Skip to content

Commit

Permalink
more tests, using pathseparator in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psschwei committed Aug 6, 2021
1 parent 46c7bc4 commit 5d1e08d
Showing 1 changed file with 36 additions and 15 deletions.
51 changes: 36 additions & 15 deletions pkg/kn/plugin/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,44 @@ func TestNoSlashInPlugin(t *testing.T) {
tmpPathDir, cleanupFunc := preparePathDirectory(t)
defer cleanupFunc()

fmt.Println(tmpPathDir)
var middleSlashPlugin string
var middleSlashArg string
ctx.pluginManager.lookupInPath = true

createTestPluginInDirectory(t, "kn-path-test", tmpPathDir)
pluginCommands := []string{"path", "test", "/withslash"}
// Windows does not allow slashes in filenames, so testing for a slash
// in the middle of an argument will have different results depending on OS
if os.PathSeparator == '/' {
middleSlashPlugin = "kn-slash-test-with\\slash"
middleSlashArg = "with\\slash"
} else {
middleSlashPlugin = "kn-slash-test"
middleSlashArg = "with/slash"
}

// args with slash are not returned
ctx.pluginManager.lookupInPath = true
plugin, err := ctx.pluginManager.FindPlugin(pluginCommands)
assert.NilError(t, err)
assert.Assert(t, plugin != nil)
desc, err := plugin.Description()
name := plugin.Name()
fmt.Println(plugin.Name())
assert.NilError(t, err)
assert.Assert(t, desc != "")
assert.Equal(t, plugin.Path(), filepath.Join(tmpPathDir, "kn-path-test"))
assert.Assert(t, !strings.Contains(name, "/"))
createTestPluginInDirectory(t, "kn-slash-test", tmpPathDir)
createTestPluginInDirectory(t, middleSlashPlugin, tmpPathDir)

data := []struct {
parts []string
name string
}{
{[]string{"slash", "test", string(os.PathSeparator) + "withslash"}, "kn-slash-test"},
{[]string{"slash", "test", string(os.PathSeparator) + "withslash", "extraarg"}, "kn-slash-test"},
{[]string{"slash", "test", "with" + string(os.PathSeparator) + "slash", "extraarg"}, "kn-slash-test"},
{[]string{"slash", "test", middleSlashArg}, middleSlashPlugin},
}

for _, d := range data {
plugin, err := ctx.pluginManager.FindPlugin(d.parts)
assert.NilError(t, err)
assert.Assert(t, plugin != nil)
desc, err := plugin.Description()
name := plugin.Name()
assert.NilError(t, err)
assert.Assert(t, desc != "")
assert.Equal(t, plugin.Path(), filepath.Join(tmpPathDir, d.name))
assert.Assert(t, !strings.Contains(name, string(os.PathSeparator)))
}
}

// ====================================================================
Expand Down

0 comments on commit 5d1e08d

Please sign in to comment.