diff --git a/container/mts/meta/meta_test.go b/container/mts/meta/meta_test.go index 2b40284d..2d65bc8c 100644 --- a/container/mts/meta/meta_test.go +++ b/container/mts/meta/meta_test.go @@ -216,3 +216,77 @@ func TestKeys(t *testing.T) { t.Errorf("Did not get expected out. \nGot : %v, \nWant: %v\n", got, want) } } + +// TestNewFromMap checks that we can successfully create a new data struct from a map. +func TestNewFromMap(t *testing.T) { + want := map[string]string{ + "loc": "a,b,c", + "ts": "12345", + } + + meta := NewFromMap(want) + + got := meta.All() + + if !reflect.DeepEqual(got, want) { + t.Errorf("Did not get expected out. \nGot : %v, \nWant: %v\n", got, want) + } +} + +// TestEncodeAsString checks that metadata is correctly encoded as a string. +func TestEncodeAsString(t *testing.T) { + meta := NewFromMap(map[string]string{ + "loc": "a,b,c", + "ts": "12345", + }) + + got := meta.EncodeAsString() + want1 := "loc=a,b,c\tts=12345" + want2 := "ts=12345\tloc=a,b,c" + + if got != want1 && got != want2 { + 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) + } + } +}