Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Srikrishna Paparaju <[email protected]>
  • Loading branch information
spaparaju committed Jun 18, 2021
1 parent 073971d commit cbb46e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/logging/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func (m *HTTPServerMiddleware) HTTPMiddleware(name string, next http.Handler) ht
}
}

var deciderUrl string = r.URL.String()
deciderURL := r.URL.String()
if len(port) > 0 {
deciderUrl = net.JoinHostPort(r.URL.String(), port)
deciderURL = net.JoinHostPort(deciderURL, port)
}
decision := m.opts.shouldLog(deciderUrl, nil)
decision := m.opts.shouldLog(deciderURL, nil)

switch decision {
case NoLogCall:
Expand Down
15 changes: 15 additions & 0 deletions pkg/logging/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,19 @@ func TestHTTPServerMiddleware(t *testing.T) {
testutil.Equals(t, 200, resp.StatusCode)
testutil.Equals(t, "Test Works", string(body))
testutil.Assert(t, !strings.Contains(b.String(), "err="))

// URL with no explicit port number in the format- hostname:port
req = httptest.NewRequest("GET", "http://example.com/foo", nil)
b.Reset()

w = httptest.NewRecorder()
hm(w, req)

resp = w.Result()
body, err = ioutil.ReadAll(resp.Body)
testutil.Ok(t, err)

testutil.Equals(t, 200, resp.StatusCode)
testutil.Equals(t, "Test Works", string(body))
testutil.Assert(t, !strings.Contains(b.String(), "err="))
}

0 comments on commit cbb46e9

Please sign in to comment.