✨ Add Set method to Metas and tests
This commit is contained in:
parent
dbcaf7ee3c
commit
e9c01097a6
2 changed files with 81 additions and 3 deletions
|
|
@ -142,6 +142,66 @@ func TestMetasAppendTo(t *testing.T) {
|
|||
assert.Equal(t, Meta{"foo", 42}, (*ms)[0])
|
||||
}
|
||||
|
||||
func TestMetasSet(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
initial Metas
|
||||
key string
|
||||
value any
|
||||
expected Metas
|
||||
}{
|
||||
{
|
||||
name: "Set new key",
|
||||
initial: Metas{},
|
||||
key: "foo",
|
||||
value: 42,
|
||||
expected: Metas{{"foo", 42}},
|
||||
},
|
||||
{
|
||||
name: "Update existing key",
|
||||
initial: Metas{{"foo", 1}},
|
||||
key: "foo",
|
||||
value: 42,
|
||||
expected: Metas{{"foo", 42}},
|
||||
},
|
||||
{
|
||||
name: "Update existing key with different type",
|
||||
initial: Metas{{"foo", "hello"}},
|
||||
key: "foo",
|
||||
value: 42,
|
||||
expected: Metas{{"foo", 42}},
|
||||
},
|
||||
{
|
||||
name: "Set multiple new keys",
|
||||
initial: Metas{},
|
||||
key: "bar",
|
||||
value: true,
|
||||
expected: Metas{{"bar", true}},
|
||||
},
|
||||
{
|
||||
name: "Update one of multiple existing keys",
|
||||
initial: Metas{{"foo", 1}, {"bar", "hello"}},
|
||||
key: "foo",
|
||||
value: 42,
|
||||
expected: Metas{{"foo", 42}, {"bar", "hello"}},
|
||||
},
|
||||
{
|
||||
name: "Set new key when others exist",
|
||||
initial: Metas{{"foo", 1}, {"bar", "hello"}},
|
||||
key: "baz",
|
||||
value: false,
|
||||
expected: Metas{{"foo", 1}, {"bar", "hello"}, {"baz", false}},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := tt.initial.Set(tt.key, tt.value)
|
||||
assert.ElementsMatch(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetasGet(t *testing.T) {
|
||||
ms := Metas{{"foo", 42}, {"bar", "hello"}}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue