add TestDeleteOrder to check that the order of keys is correct after deletion

This commit is contained in:
Scott 2020-02-26 09:53:08 +10:30
parent 9a9dba0cd2
commit 7ae9f265e0
1 changed files with 42 additions and 0 deletions

View File

@ -251,3 +251,45 @@ func TestEncodeAsString(t *testing.T) {
t.Errorf("Did not get expected out. \nGot : %v, \nWant: %v or %v\n", got, want1, want2)
}
}
// TestDeleteOrder checks that the order of keys is correct after a deletion.
func TestDeleteOrder(t *testing.T) {
tests := []struct {
delKey string
want []string
}{
{
"key1",
[]string{"key2", "key3", "key4"},
},
{
"key2",
[]string{"key1", "key3", "key4"},
},
{
"key3",
[]string{"key1", "key2", "key4"},
},
{
"key4",
[]string{"key1", "key2", "key3"},
},
}
for _, test := range tests {
t.Logf("deleting %s", test.delKey)
meta := NewWith([][2]string{
{"key1", "val1"},
{"key2", "val2"},
{"key3", "val3"},
{"key4", "val4"},
})
meta.Delete(test.delKey)
got := meta.order
want := test.want
if !reflect.DeepEqual(got, want) {
t.Errorf("Did not get expected out. \nGot: %v, \nWant: %v\n", got, want)
}
}
}