1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/newrelic/client/http_helper_test_fixtures.go
Chris Cummer 31926fd4a7
Integrate vendored NewRelic dependency (#767)
The NewRelic module relies on yfronto/newrelic, which no longer exists.
yfronto deleted that directory quite awhile ago, and since then it has
been vendored.

But vendoring a missing repository creates problems when trying to
update the vendored code.

This PR brings the yfronto/newrelic code into the mainline.

Signed-off-by: Chris Cummer <chriscummer@me.com>
2019-12-01 20:47:02 -08:00

120 lines
2.2 KiB
Go

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"
}