2021-11-24 21:56:55 +05:30
|
|
|
package generators
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestMergeMapsMany(t *testing.T) {
|
2022-05-27 18:01:56 +02:00
|
|
|
got := MergeMapsMany(map[string]interface{}{"a": []string{"1", "2"}, "c": "5"}, map[string][]string{"b": {"3", "4"}})
|
2021-11-24 21:56:55 +05:30
|
|
|
require.Equal(t, map[string][]string{
|
2022-05-27 18:01:56 +02:00
|
|
|
"a": {"1", "2"},
|
|
|
|
|
"b": {"3", "4"},
|
|
|
|
|
"c": {"5"},
|
2021-11-24 21:56:55 +05:30
|
|
|
}, got, "could not get correct merged map")
|
|
|
|
|
}
|
2025-09-15 23:48:02 +05:30
|
|
|
|
|
|
|
|
func TestMergeMapsAndExpand(t *testing.T) {
|
|
|
|
|
m1 := map[string]interface{}{"a": "1"}
|
|
|
|
|
m2 := map[string]interface{}{"b": "2"}
|
|
|
|
|
out := MergeMaps(m1, m2)
|
|
|
|
|
if out["a"].(string) != "1" || out["b"].(string) != "2" {
|
|
|
|
|
t.Fatalf("unexpected merge: %#v", out)
|
|
|
|
|
}
|
|
|
|
|
flat := map[string]string{"x": "y"}
|
|
|
|
|
exp := ExpandMapValues(flat)
|
|
|
|
|
if len(exp["x"]) != 1 || exp["x"][0] != "y" {
|
|
|
|
|
t.Fatalf("unexpected expand: %#v", exp)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestIteratorRemaining(t *testing.T) {
|
|
|
|
|
g, err := New(map[string]interface{}{"k": []interface{}{"a", "b"}}, BatteringRamAttack, "", nil, "", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("new: %v", err)
|
|
|
|
|
}
|
|
|
|
|
it := g.NewIterator()
|
|
|
|
|
if it.Total() != 2 || it.Remaining() != 2 {
|
|
|
|
|
t.Fatalf("unexpected totals: %d %d", it.Total(), it.Remaining())
|
|
|
|
|
}
|
|
|
|
|
_, _ = it.Value()
|
|
|
|
|
if it.Remaining() != 1 {
|
|
|
|
|
t.Fatalf("unexpected remaining after one: %d", it.Remaining())
|
|
|
|
|
}
|
|
|
|
|
}
|