-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_test.go
102 lines (87 loc) · 2.07 KB
/
request_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
100
101
102
package facio
import (
"fmt"
"testing"
)
func TestRequest(t *testing.T) {
tts := []testCases{}
{
gotR, gotErr := NewRequest("GET", "https://example.com/")
tts = append(tts, testCases{
name: "NewRequest - Correct",
got: gotR.baseURL,
want: "https://example.com",
testType: Equal,
})
tts = append(tts, testCases{
name: "NewRequest - Correct",
got: gotErr,
testType: Nil,
})
}
{
method := "random_method"
gotR, gotErr := NewRequest(method, "https://example.com/")
tts = append(tts, testCases{
name: "NewRequest - Correct",
got: gotR,
want: &Req{},
testType: Equal,
})
tts = append(tts, testCases{
name: "NewRequest - Correct",
got: gotErr,
want: fmt.Errorf(msgInvalidMethod, method),
testType: Equal,
})
}
{
method := "GET"
gotR, gotErr := NewRequest(method, "")
tts = append(tts, testCases{
name: "NewRequest - Correct",
got: gotR,
want: &Req{},
testType: Equal,
})
tts = append(tts, testCases{
name: "NewRequest - Correct",
got: gotErr,
want: fmt.Errorf(msgInvalidURL, ""),
testType: Equal,
})
}
{
gotR, _ := NewRequest("GET", "https://example.com/")
gotR.AddHeader(AcceptEncoding, "application/json")
tts = append(tts, testCases{
name: "NewRequest - Correct",
got: gotR.headers[AcceptEncoding.getHeader()],
want: "application/json",
testType: Equal,
})
}
{
gotR, _ := NewRequest("GET", "https://example.com/")
gotR.AddCustomHeader(AcceptEncoding.getHeader(), "application/json")
tts = append(tts, testCases{
name: "NewRequest - Correct",
got: gotR.headers[AcceptEncoding.getHeader()],
want: "application/json",
testType: Equal,
})
}
{
gotR, _ := NewRequest("GET", "https://example.com/")
gotR.SetURLForm(map[string][]string{
"val": {"foo", "bar"},
})
tts = append(tts, testCases{
name: "NewRequest - Correct",
got: gotR.formURL["val"],
want: []string{"foo", "bar"},
testType: Equal,
})
}
runTests(t, tts)
}