Skip to content

Commit

Permalink
ssntp: add unit test of Role set function Set()
Browse files Browse the repository at this point in the history
The Role setting function supports three usage modes:  setting a single
value, setting values via successive sequential calls, or providing a
comma-separated list.  A table test is added for the first case, and a
simple pair of calls are added to cover the two ways to set multiple roles.

Signed-off-by: Tim Pepper <[email protected]>
  • Loading branch information
Tim Pepper committed Jul 12, 2016
1 parent 5ecc80d commit b6d25ed
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ssntp/ssntp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2580,6 +2580,46 @@ func TestRoleToDefaultCertName(t *testing.T) {
}
}

func TestRoleSet(t *testing.T) {
var stringTests = []struct {
r string
expected Role
}{
{"unknown", UNKNOWN},
{"server", SERVER},
{"controller", Controller},
{"agent", AGENT},
{"netagent", NETAGENT},
{"scheduler", SCHEDULER},
{"cnciagent", CNCIAGENT},
}

for _, test := range stringTests {
var role Role
role.Set(test.r)
if role != test.expected {
t.Errorf("expected \"%x\", got \"%x\"", test.expected, role)
}
}

var role Role
err := role.Set("asdf")
if err == nil {
t.Error("expected \"Unknown role\" error, got nil")
}

role.Set("agent")
role.Set("netagent")
if role != AGENT|NETAGENT {
t.Error("didn't correctly sequantially assign role")
}

role.Set("agent, netagent")
if role != AGENT|NETAGENT {
t.Error("didn't correctly multi-assign role")
}
}

func TestMain(m *testing.M) {
flag.Parse()

Expand Down

0 comments on commit b6d25ed

Please sign in to comment.