Skip to content

Commit

Permalink
metadata defined by library should override custom metadata to sure f…
Browse files Browse the repository at this point in the history
…ile hashing is correct
  • Loading branch information
Stein Fletcher committed Feb 14, 2019
1 parent da2d54c commit 544de43
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
9 changes: 5 additions & 4 deletions apitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,17 @@ func (a *APITest) report() {
})

meta := map[string]interface{}{}

for k, v := range a.meta {
meta[k] = v
}

meta["status_code"] = capturedFinalRes.StatusCode
meta["path"] = capturedInboundReq.URL.String()
meta["method"] = capturedInboundReq.Method
meta["name"] = a.name
meta["hash"] = createHash(meta)

for k, v := range a.meta {
meta[k] = v
}

recorder.AddMeta(meta)

a.reporter.Format(recorder)
Expand Down
28 changes: 28 additions & 0 deletions apitest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,34 @@ func TestApiTest_CopyHttpRequest(t *testing.T) {
assert.Equal(t, reqCopy.Header, req.Header)
}

func TestCreateHash_GroupsByEndpoint(t *testing.T) {
tests := []struct {
app string
method string
path string
name string
expected string
}{
{app: "a", method: "GET", path: "/v1/abc", name: "test1", expected: "1850189403_2569220284"},
{app: "a", method: "GET", path: "/v1/abc", name: "test2", expected: "1850189403_2619553141"},
{app: "b", method: "GET", path: "/v1/abc", name: "test1", expected: "547235502_2569220284"},
{app: "b", method: "GET", path: "/v1/abc", name: "test2", expected: "547235502_2619553141"},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%s %s %s %s", test.app, test.method, test.path, test.name), func(t *testing.T) {
meta := map[string]interface{}{
"app": test.app,
"method": test.method,
"path": test.path,
"name": test.name,
}
hash := createHash(meta)
assert.Equal(t, test.expected, hash)
})
}
}


type RecorderCaptor struct {
capturedRecorder *Recorder
}
Expand Down

0 comments on commit 544de43

Please sign in to comment.