forked from TheQuestionru/newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_helper_test_fixtures.go
119 lines (110 loc) · 2.23 KB
/
http_helper_test_fixtures.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package newrelic
import (
"errors"
"net/http"
"strings"
)
type testJSONInterface struct {
data string `json:"data"id,omitempty"`
}
type testParamsInterface struct {
data string
}
type doGetTestsInput struct {
path string
params *testParamsInterface
out testJSONInterface
status int
data string
}
type doGetTestsOutput struct {
data testJSONInterface
err error
}
type doRequestTestsInput struct {
req *http.Request
out testJSONInterface
status int
data string
}
type doRequestTestOutput struct {
data testJSONInterface
err error
}
var (
doGetTests = []struct {
in doGetTestsInput
out doGetTestsOutput
}{
{
doGetTestsInput{
path: "somePath",
params: &testParamsInterface{"testData"},
out: testJSONInterface{"testData"},
status: 200,
data: `{"data": "testStructData"}`,
},
doGetTestsOutput{
data: testJSONInterface{"testData"},
err: nil,
},
},
{
doGetTestsInput{
status: 404,
data: "Not Found",
},
doGetTestsOutput{
err: errors.New("newrelic http error (404 Not Found): Not Found"),
},
},
}
testRequest, _ = http.NewRequest("GET", "http://testPath",
strings.NewReader("testBody"))
doRequestTests = []struct {
in doRequestTestsInput
out doRequestTestOutput
}{
{
doRequestTestsInput{
req: testRequest,
out: testJSONInterface{"testData"},
status: 200,
data: `{"data": "testStructData"}`,
},
doRequestTestOutput{
data: testJSONInterface{"testData"},
err: nil,
},
},
}
encodeGetParamsTests = []struct {
in map[string]interface{}
out string
}{
{
map[string]interface{}{
"testInt": 5,
"testString": "test",
"testStringSlice": []string{"test1", "test2"},
"testArray": Array{[]string{"test1", "test2"}},
"testTime": testTime,
},
"testArray=test1" +
"&testArray=test2" +
"&testInt=5" +
"&testString=test" +
"&testStringSlice=test1%2Ctest2" +
"&testTime=" + testTimeStringEscaped,
},
{
map[string]interface{}{
"unexpectedType": map[string]string{"unexpected": "type"},
},
"unexpectedType=map%5Bunexpected%3Atype%5D",
},
}
)
func (m *testParamsInterface) String() string {
return "data=testData"
}