Skip to content

Commit

Permalink
Add missing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Feb 20, 2017
1 parent 411f8e0 commit 272cdae
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,20 @@ func TestProtect(t *testing.T) {
}
}

func TestAccessRequestID(t *testing.T) {
func TestGetRequestID(t *testing.T) {
log.SetLevel(log.PanicLevel) // suppress logs in test output
reqID := "alphabetsoup"
mockReq, _ := http.NewRequest("GET", "http://example.com/foo", nil)
ctx := context.WithValue(mockReq.Context(), CtxValueRequestID, reqID)
mockReq = mockReq.WithContext(ctx)
ctxReqID := GetRequestID(mockReq.Context())
if reqID != ctxReqID {
t.Errorf("TestAccessRequestID wanted request ID '%s', got '%s'", reqID, ctxReqID)
t.Errorf("TestGetRequestID wanted request ID '%s', got '%s'", reqID, ctxReqID)
}

noReqIDInReq, _ := http.NewRequest("GET", "http://example.com/foo", nil)
ctxReqID = GetRequestID(noReqIDInReq.Context())
if ctxReqID != "" {
t.Errorf("TestGetRequestID wanted empty request ID, got '%s'", ctxReqID)
}
}

0 comments on commit 272cdae

Please sign in to comment.