Skip to content

Commit

Permalink
Update tests for new error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cbroglie committed May 22, 2019
1 parent aa27687 commit 940a4ad
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions crypto11_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,34 @@ func TestKeyDelete(t *testing.T) {

func TestAmbiguousTokenConfig(t *testing.T) {
slotNum := 1
badConfigs := []*Config{
{TokenSerial: "serial", TokenLabel: "label"},
{TokenSerial: "serial", SlotNumber: &slotNum},
{SlotNumber: &slotNum, TokenLabel: "label"},
tests := []struct {
config *Config
err string
}{
{
config: &Config{TokenSerial: "serial", TokenLabel: "label"},
err: "config must specify exactly one way to select a token: token label, token serial number given",
},
{
config: &Config{TokenSerial: "serial", SlotNumber: &slotNum},
err: "config must specify exactly one way to select a token: slot number, token serial number given",
},
{
config: &Config{SlotNumber: &slotNum, TokenLabel: "label"},
err: "config must specify exactly one way to select a token: slot number, token label given",
},
{
config: &Config{},
err: "config must specify exactly one way to select a token: none given",
},
}

for _, config := range badConfigs {
_, err := Configure(config)
assert.Equal(t, errAmbiguousToken, err)
for i, test := range tests {
t.Run(fmt.Sprintf("test_%d", i), func(t *testing.T) {
_, err := Configure(test.config)
if assert.Error(t, err) {
assert.Equal(t, test.err, err.Error())
}
})
}
}

Expand Down

0 comments on commit 940a4ad

Please sign in to comment.