-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aya Igarashi
committed
Jul 20, 2020
1 parent
632c3d2
commit 712f7a2
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Ladicle/kubectl-rolesum/pkg/util/subject" | ||
) | ||
|
||
func TestValidate(t *testing.T) { | ||
tests := []struct { | ||
desc string | ||
args []string | ||
option Option | ||
wantError bool | ||
}{ | ||
{ | ||
desc: "Use Service Account", | ||
args: []string{"ci-bot"}, | ||
option: Option{ | ||
SubjectKind: subject.KindSA, | ||
}, | ||
}, | ||
{ | ||
desc: "Use User", | ||
args: []string{"alice"}, | ||
option: Option{ | ||
SubjectKind: subject.KindUser, | ||
}, | ||
}, | ||
{ | ||
desc: "Use Group", | ||
args: []string{"developer"}, | ||
option: Option{ | ||
SubjectKind: subject.KindGroup, | ||
}, | ||
}, | ||
{ | ||
desc: "No arguments", | ||
wantError: true, | ||
}, | ||
{ | ||
desc: "Unknown subject kind", | ||
option: Option{ | ||
SubjectKind: "unknown", | ||
}, | ||
wantError: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.desc, func(t *testing.T) { | ||
err := tt.option.Validate(nil, tt.args) | ||
if err != nil { | ||
if !tt.wantError { | ||
t.Fatalf("o.Validate(): %v", err) | ||
} | ||
return | ||
} | ||
if tt.wantError { | ||
t.Fatal("o.Validate() should fail") | ||
} | ||
}) | ||
} | ||
} |