forked from raviqqe/muffet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arguments_test.go
99 lines (91 loc) · 2.67 KB
/
arguments_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"testing"
"github.com/bradleyjkemp/cupaloy"
"github.com/stretchr/testify/assert"
)
func TestGetArguments(t *testing.T) {
for _, ss := range [][]string{
{"https://foo.com"},
{"-b", "42", "https://foo.com"},
{"--buffer-size", "42", "https://foo.com"},
{"-c", "1", "https://foo.com"},
{"--max-connections", "1", "https://foo.com"},
{"--max-connections-per-host", "1", "https://foo.com"},
{"--max-response-body-size", "1", "https://foo.com"},
{"-e", "regex1", "-e", "regex2", "https://foo.com"},
{"--exclude", "regex1", "--exclude", "regex2", "https://foo.com"},
{"--header", "MyHeader: foo", "--header", "YourHeader: bar", "https://foo.com"},
{"--header", "User-Agent: custom-agent", "https://foo.com"},
{"-r", "4", "https://foo.com"},
{"--max-redirections", "4", "https://foo.com"},
{"--follow-robots-txt", "https://foo.com"},
{"--follow-sitemap-xml", "https://foo.com"},
{"-t", "10", "https://foo.com"},
{"--timeout", "10", "https://foo.com"},
{"--rate-limit", "1", "https://foo.com"},
{"--proxy", "localhost:8080", "https://foo.com"},
{"--skip-tls-verification", "https://foo.com"},
{"-v", "https://foo.com"},
{"--verbose", "https://foo.com"},
{"-v", "-f", "https://foo.com"},
{"-v", "--ignore-fragments", "https://foo.com"},
{"--one-page-only", "https://foo.com"},
{"--json", "https://foo.com"},
{"-h"},
{"--help"},
{"--version"},
} {
_, err := getArguments(ss)
assert.Nil(t, err)
}
}
func TestGetArgumentsError(t *testing.T) {
for _, ss := range [][]string{
{},
{"-b", "foo", "https://foo.com"},
{"--buffer-size", "foo", "https://foo.com"},
{"-c", "foo", "https://foo.com"},
{"--max-connections", "foo", "https://foo.com"},
{"-e", "(", "https://foo.com"},
{"-j", "MyHeader", "https://foo.com"},
{"--header", "MyHeader", "https://foo.com"},
{"-l", "foo", "https://foo.com"},
{"--max-redirections", "foo", "https://foo.com"},
{"-t", "foo", "https://foo.com"},
{"--timeout", "foo", "https://foo.com"},
} {
_, err := getArguments(ss)
assert.NotNil(t, err)
}
}
func TestHelp(t *testing.T) {
cupaloy.SnapshotT(t, help())
}
func TestParseHeaders(t *testing.T) {
for _, c := range []struct {
arguments []string
answer map[string]string
}{
{
nil,
map[string]string{},
},
{
[]string{"MyHeader: foo"},
map[string]string{"MyHeader": "foo"},
},
{
[]string{"MyHeader: foo", "YourHeader: bar"},
map[string]string{"MyHeader": "foo", "YourHeader": "bar"},
},
} {
hs, err := parseHeaders(c.arguments)
assert.Nil(t, err)
assert.Equal(t, c.answer, hs)
}
}
func TestParseHeadersError(t *testing.T) {
_, err := parseHeaders([]string{"MyHeader"})
assert.NotNil(t, err)
}