Skip to content

Commit

Permalink
test(unit): fix TestAPIMultiOwnerSet_PopAPIKey tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njhale committed Jan 10, 2019
1 parent 7c004cf commit b26b3f8
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions pkg/controller/registry/resolver/operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ func TestAPIMultiOwnerSet_PopAPIKey(t *testing.T) {
tests := []struct {
name string
s APIMultiOwnerSet
want *opregistry.APIKey
}{
{
name: "Empty",
s: EmptyAPIMultiOwnerSet(),
want: nil,
},
{
name: "OneApi/OneOwner",
Expand All @@ -61,7 +59,6 @@ func TestAPIMultiOwnerSet_PopAPIKey(t *testing.T) {
"owner1": &Operator{name: "op1"},
},
},
want: &opregistry.APIKey{"g", "v", "k", "p"},
},
{
name: "OneApi/MultiOwner",
Expand All @@ -71,7 +68,6 @@ func TestAPIMultiOwnerSet_PopAPIKey(t *testing.T) {
"owner2": &Operator{name: "op2"},
},
},
want: &opregistry.APIKey{"g", "v", "k", "p"},
},
{
name: "MultipleApi/MultiOwner",
Expand All @@ -85,24 +81,20 @@ func TestAPIMultiOwnerSet_PopAPIKey(t *testing.T) {
"owner2": &Operator{name: "op2"},
},
},
want: &opregistry.APIKey{"g", "v", "k", "p"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
startLen := len(tt.s)
require.Equal(t, tt.s.PopAPIKey(), tt.want)

// Verify entry removed once popped
if tt.want != nil {
_, ok := tt.s[*tt.want]
require.False(t, ok)
}
popped := tt.s.PopAPIKey()

// Verify len has decreased
if startLen == 0 {
require.Nil(t, popped, "popped key from empty MultiOwnerSet should be nil")
require.Equal(t, 0, len(tt.s))
} else {
_, found := tt.s[*popped]
require.False(t, found, "popped key should not still exist in set")
require.Equal(t, startLen-1, len(tt.s))
}
})
Expand Down

0 comments on commit b26b3f8

Please sign in to comment.