Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/internal/runner/options_test.go
2070 views
1
package runner
2
3
import (
4
"strings"
5
"testing"
6
7
"github.com/projectdiscovery/goflags"
8
"github.com/projectdiscovery/nuclei/v3/pkg/types"
9
"github.com/stretchr/testify/require"
10
)
11
12
func TestParseHeadlessOptionalArguments(t *testing.T) {
13
tests := []struct {
14
name string
15
input string
16
want map[string]string
17
}{
18
{
19
name: "single value",
20
input: "a=b",
21
want: map[string]string{"a": "b"},
22
},
23
{
24
name: "empty string",
25
input: "",
26
want: map[string]string{},
27
},
28
{
29
name: "empty key",
30
input: "=b",
31
want: map[string]string{},
32
},
33
{
34
name: "empty value",
35
input: "a=",
36
want: map[string]string{},
37
},
38
{
39
name: "double input",
40
input: "a=b,c=d",
41
want: map[string]string{"a": "b", "c": "d"},
42
},
43
{
44
name: "duplicated input",
45
input: "a=b,a=b",
46
want: map[string]string{"a": "b"},
47
},
48
}
49
for _, tt := range tests {
50
t.Run(tt.name, func(t *testing.T) {
51
strsl := goflags.StringSlice{}
52
for _, v := range strings.Split(tt.input, ",") {
53
//nolint
54
strsl.Set(v)
55
}
56
opt := types.Options{HeadlessOptionalArguments: strsl}
57
got := opt.ParseHeadlessOptionalArguments()
58
require.Equal(t, tt.want, got)
59
})
60
}
61
}
62
63