-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathrequestValidation_test.go
76 lines (68 loc) · 1.39 KB
/
requestValidation_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
package mockingjay
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestItValidatesRequests(t *testing.T) {
spaceyHeaders := make(map[string]string)
spaceyHeaders["hello world"] = "l o l"
aForm := make(map[string]string)
aForm["name"] = "Hudson"
tests := []struct {
Description string
Request Request
ExpectedError error
}{
{
Description: "Empty URIs are not valid",
Request: Request{
URI: "",
Method: "POST",
},
ExpectedError: errEmptyURI,
},
{
Description: "URIs not starting with slash are not valid",
Request: Request{
URI: "hello",
Method: "POST",
},
ExpectedError: errBadURI,
},
{
Description: "Empty methods are not valid",
Request: Request{
URI: "/",
Method: "",
},
ExpectedError: errEmptyMethod,
},
{
Description: "Headers cant have spaces",
Request: Request{
URI: "/",
Method: "POST",
Headers: spaceyHeaders,
},
ExpectedError: errBadHeaders,
},
{
Description: "Cant have both form and a body",
Request: Request{
URI: "/",
Method: "POST",
Body: "hi",
Form: aForm,
},
ExpectedError: errBodyAndForm,
},
}
for _, test := range tests {
assert.Equal(t, test.ExpectedError, test.Request.errors(), test.Description)
}
validRequest := Request{
URI: "/",
Method: "POST",
}
assert.Nil(t, validRequest.errors())
}