Path: blob/dev/pkg/protocols/common/generators/maps_test.go
2846 views
package generators12import (3"testing"45"github.com/stretchr/testify/require"6)78func TestMergeMapsMany(t *testing.T) {9got := MergeMapsMany(map[string]interface{}{"a": []string{"1", "2"}, "c": "5"}, map[string][]string{"b": {"3", "4"}})10require.Equal(t, map[string][]string{11"a": {"1", "2"},12"b": {"3", "4"},13"c": {"5"},14}, got, "could not get correct merged map")15}1617func TestMergeMapsAndExpand(t *testing.T) {18m1 := map[string]interface{}{"a": "1"}19m2 := map[string]interface{}{"b": "2"}20out := MergeMaps(m1, m2)21if out["a"].(string) != "1" || out["b"].(string) != "2" {22t.Fatalf("unexpected merge: %#v", out)23}24flat := map[string]string{"x": "y"}25exp := ExpandMapValues(flat)26if len(exp["x"]) != 1 || exp["x"][0] != "y" {27t.Fatalf("unexpected expand: %#v", exp)28}29}3031func TestIteratorRemaining(t *testing.T) {32g, err := New(map[string]interface{}{"k": []interface{}{"a", "b"}}, BatteringRamAttack, "", nil, "", nil)33if err != nil {34t.Fatalf("new: %v", err)35}36it := g.NewIterator()37if it.Total() != 2 || it.Remaining() != 2 {38t.Fatalf("unexpected totals: %d %d", it.Total(), it.Remaining())39}40_, _ = it.Value()41if it.Remaining() != 1 {42t.Fatalf("unexpected remaining after one: %d", it.Remaining())43}44}454647