-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstress_test.go
82 lines (74 loc) · 2.58 KB
/
stress_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
package main
import "testing"
func TestParseValidHeaderFlag(t *testing.T) {
match, err := parseInputWithRegexp("X-Something: !Y10K:;(He@poverflow?)", headerRegexp)
if err != nil {
t.Errorf("A valid header was not parsed correctly: %v", err.Error())
return
}
if match[1] != "X-Something" || match[2] != "!Y10K:;(He@poverflow?)" {
t.Errorf("A valid header was not parsed correctly, parsed values: %v %v", match[1], match[2])
}
}
func TestParseInvalidHeaderFlag(t *testing.T) {
_, err := parseInputWithRegexp("X|oh|bad-input: badbadbad", headerRegexp)
if err == nil {
t.Errorf("An invalid header passed parsing")
}
}
func TestParseValidMethodFlag(t *testing.T) {
match, err := parseInputWithRegexp("http://127.0.0.1:8080,m:GET", methodsRegexp)
if err != nil {
t.Errorf("A valid method was not parsed correctly: %v", err.Error())
return
}
if match[1] != "GET" {
t.Errorf("A valid method was not parsed correctly, parsed values: %v", match[1])
}
}
func TestParseValidBodyFlag(t *testing.T) {
match, err := parseInputWithRegexp("http://127.0.0.1:8080,b:hello body", bodyRegexp)
if err != nil {
t.Errorf("A valid body was not parsed correctly: %v", err.Error())
return
}
if match[1] != "hello body" {
t.Errorf("A valid body was not parsed correctly, parsed values: %v", match[1])
}
}
func TestParseValidBodyFileFlag(t *testing.T) {
match, err := parseInputWithRegexp("http://127.0.0.1:8080,B:./bodyFile.txt", bodyFileRegexp)
if err != nil {
t.Errorf("A valid bodyFile was not parsed correctly: %v", err.Error())
return
}
if match[1] != "./bodyFile.txt" {
t.Errorf("A valid bodyFile was not parsed correctly, parsed values: %v", match[1])
}
}
func TestParseValidProxyAddrFlag(t *testing.T) {
match, err := parseInputWithRegexp("http://127.0.0.1:8080,x:http://127.0.0.1:8888", proxyAddrRegexp)
if err != nil {
t.Errorf("A valid ProxyAddr was not parsed correctly: %v", err.Error())
return
}
if match[1] != "http://127.0.0.1:8888" {
t.Errorf("A valid ProxyAddr was not parsed correctly, parsed values: %v", match[1])
}
}
func TestParseValidThinkTimeFlag(t *testing.T) {
match, err := parseInputWithRegexp("http://127.0.0.1:8080,thinkTime:2", thinkTimeRegexp)
if err != nil {
t.Errorf("A valid ThinkTime was not parsed correctly: %v", err.Error())
return
}
if match[1] != "2" {
t.Errorf("A valid ThinkTime was not parsed correctly, parsed values: %v", match[1])
}
}
func TestParseInvalidThinkTimeFlag(t *testing.T) {
_, err := parseInputWithRegexp("http://127.0.0.1:8080,thinkTime:abc", thinkTimeRegexp)
if err == nil {
t.Errorf("An invalid ThinkTime passed parsing")
}
}