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