Skip to content

Commit

Permalink
fix: boolean logic (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
busser authored Sep 23, 2020
1 parent 071f5c7 commit 751a3d1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func getResourceScope(scope string) (cluster, namespace bool, err error) {
switch scope {
case "":
cluster = viper.GetString(constants.FlagNamespace) == ""
namespace = false
namespace = true
case "namespace":
cluster = false
namespace = true
Expand Down
56 changes: 56 additions & 0 deletions internal/client/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package client

import "testing"

func TestGetResourceScope(t *testing.T) {
tests := map[string]struct {
scope string
wantCluster bool
wantNamespace bool
wantErr bool
}{
"no scope": {
scope: "",
wantCluster: true,
wantNamespace: true,
wantErr: false,
},
"namespace scope": {
scope: "namespace",
wantCluster: false,
wantNamespace: true,
wantErr: false,
},
"cluster scope": {
scope: "cluster",
wantCluster: true,
wantNamespace: false,
wantErr: false,
},
"unknown scope": {
scope: "unknown",
wantCluster: false,
wantNamespace: false,
wantErr: true,
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
gotCluster, gotNamespace, gotErr := getResourceScope(test.scope)

if gotCluster != test.wantCluster {
t.Fatalf("wrong cluster: got %t, want %t", gotCluster, test.wantNamespace)
}
if gotNamespace != test.wantNamespace {
t.Fatalf("wrong namespace: got %t, want %t", gotNamespace, test.wantNamespace)
}
if gotErr != nil && !test.wantErr {
t.Fatalf("unexpected error: %s", gotErr.Error())
}
if gotErr == nil && test.wantErr {
t.Fatal("expected error, got none")
}
})
}
}

0 comments on commit 751a3d1

Please sign in to comment.