Skip to content

Commit

Permalink
Add validation test
Browse files Browse the repository at this point in the history
  • Loading branch information
Aya Igarashi committed Jul 20, 2020
1 parent 632c3d2 commit 712f7a2
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions cmd/cmd_test.go
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")
}
})
}
}

0 comments on commit 712f7a2

Please sign in to comment.