Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change pointer to struct #47

Merged
merged 22 commits into from
Jun 15, 2020
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: refactor testRequest
  • Loading branch information
suzuki-shunsuke committed Jun 15, 2020
commit 137349601ae65728303231fb79ddb05409bfdee2
14 changes: 6 additions & 8 deletions flute/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type testFunc func(t *testing.T, req *http.Request, service Service, route Route

var testFuncs = [...]testFunc{ //nolint:gochecknoglobals
testPath, testMethod, testBodyString, testBodyJSON,
testBodyJSONString, testPartOfHeader, testHeader,
testBodyJSONString, testPartOfHeader, testHeader, testPartOfQuery,
}

func testHeader(t *testing.T, req *http.Request, service Service, route Route) {
Expand All @@ -32,9 +32,6 @@ func testRequest(t *testing.T, req *http.Request, service Service, route Route)
fn(t, req, service, route)
}
tester := route.Tester
if tester.PartOfQuery != nil {
testPartOfQuery(t, req, service, route)
}
if tester.Query != nil {
assert.Equal(
t, tester.Query, req.URL.Query(),
Expand Down Expand Up @@ -171,22 +168,23 @@ func testPartOfHeader(t *testing.T, req *http.Request, service Service, route Ro
}

func testPartOfQuery(t *testing.T, req *http.Request, service Service, route Route) {
reqName := route.Name
srv := service.Endpoint
if route.Tester.PartOfQuery == nil {
return
}

query := req.URL.Query()
for k, v := range route.Tester.PartOfQuery {
a, ok := query[k]
if !ok {
assert.Fail(
t, makeMsg(
"the following request query is required: "+k, srv, reqName))
"the following request query is required: "+k, service.Endpoint, route.Name))
return
}
if v != nil {
assert.Equal(
t, v, a,
makeMsg(fmt.Sprintf(`the request query "%s" should match`, k), srv, reqName))
makeMsg(fmt.Sprintf(`the request query "%s" should match`, k), service.Endpoint, route.Name))
}
}
}