Skip to content

Commit

Permalink
Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskim06 committed Apr 28, 2020
1 parent 79cf9e1 commit 9ab6eb2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
29 changes: 22 additions & 7 deletions cmd/krew/cmd/namingutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,28 @@ func Test_canonicalName(t *testing.T) {
}

func Test_isCanonicalName(t *testing.T) {
if isCanonicalName("foo") {
t.Error("expected foo to not be considered a canonical name")
}
if isCanonicalName("../index/foo") {
t.Error("expected ../index/foo to not be considered a canonical name")
tests := []struct {
arg string
expected bool
}{
{"foo", false},
{"../index/foo", false},
{"index/foo", true},
{"", false},
{"0-0", false},
{"a/", false},
{"/b", false},
{"a-a/b-b", true},
{"a//b", false},
{"a / b", false},
{"a /b", false},
{"a/ b", false},
}
if !isCanonicalName("index/foo") {
t.Error("expected index/foo to be considered a canonical name")
for _, tt := range tests {
t.Run(tt.arg, func(t *testing.T) {
if isCanonicalName(tt.arg) != tt.expected {
t.Errorf("expected isCanonicalName(%q) to be %t", tt.arg, tt.expected)
}
})
}
}
3 changes: 1 addition & 2 deletions cmd/krew/cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ Remarks:
for _, name := range args {
if isCanonicalName(name) {
return errors.New("uninstall command does not support INDEX/PLUGIN syntax; just specify PLUGIN")
}
if !validation.IsSafePluginName(name) {
} else if !validation.IsSafePluginName(name) {
return unsafePluginNameErr(name)
}
klog.V(4).Infof("Going to uninstall plugin %s\n", name)
Expand Down
3 changes: 1 addition & 2 deletions cmd/krew/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ kubectl krew upgrade foo bar"`,
for _, arg := range args {
if isCanonicalName(arg) {
return errors.New("upgrade command does not support INDEX/PLUGIN syntax; just specify PLUGIN")
}
if !validation.IsSafePluginName(arg) {
} else if !validation.IsSafePluginName(arg) {
return unsafePluginNameErr(arg)
}
r, err := receipt.Load(paths.PluginInstallReceiptPath(arg))
Expand Down
19 changes: 16 additions & 3 deletions integration_test/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,26 @@ func TestKrewUninstallPluginsFromCustomIndex(t *testing.T) {
test.Krew("index", "add", "foo", test.TempDir().Path("index/"+constants.DefaultIndexName)).RunOrFail()
test.Krew("install", "foo/"+validPlugin).RunOrFail()

if _, err := test.Krew("uninstall", "foo/"+validPlugin).Run(); err == nil {
t.Error("expected error when uninstalling by canonical name")
}
test.Krew("uninstall", validPlugin).RunOrFail()
test.AssertExecutableNotInPATH("kubectl-" + validPlugin)
}

func TestKrewUninstall_CannotUseIndexSyntax(t *testing.T) {
skipShort(t)

test, cleanup := NewTest(t)
defer cleanup()

test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithIndex()
out, err := test.Krew("uninstall", "foo/"+validPlugin).Run()
if err == nil {
t.Error("expected error when uninstalling by canonical name")
}
if !strings.Contains(string(out), "INDEX/PLUGIN") {
t.Error("expected warning about using canonical name to be in output")
}
}

func TestKrewRemove_AliasSupported(t *testing.T) {
skipShort(t)

Expand Down
7 changes: 7 additions & 0 deletions integration_test/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func TestKrewUpgradePluginsFromCustomIndex(t *testing.T) {
if !strings.Contains(out, "Upgrading plugin: foo/"+validPlugin) {
t.Errorf("expected plugin foo/%s to be upgraded", validPlugin)
}
}

func TestKrewUpgrade_CannotUseIndexSyntax(t *testing.T) {
skipShort(t)

test, cleanup := NewTest(t)
defer cleanup()

b, err := test.Krew("upgrade", "foo/"+validPlugin).Run()
if err == nil {
Expand Down

0 comments on commit 9ab6eb2

Please sign in to comment.