Last active
August 29, 2015 14:21
-
-
Save lateefj/f70f27b1824fd64b4cc6 to your computer and use it in GitHub Desktop.
Basic McTest Usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
req, _ := http.NewRequest("GET", "/path/to/handler", nil) | |
resp := NewMockTestResponse(t) | |
HomeHandler(resp, req) | |
b := "HomeHandler" | |
if !resp.AssertCode(http.StatusOK) { | |
t.Fatalf("Response StatusCode is %d asserted that it is %d", resp.StatusCode, http.StatusOK) | |
} | |
if !resp.AssertBody(b) { | |
t.Fatalf("Response body is %s asserted that it is %s", resp.String(), b) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
req, _ := http.NewRequest("GET", "/path/to/handler", nil) | |
resp := NewMockTestResponse(t) | |
HomeHandler(resp, req) | |
b := "HomeHandler" | |
if !resp.AssertCode(http.StatusOK) { | |
t.Fatalf("Response StatusCode is %d asserted that it is %d", resp.StatusCode, http.StatusOK) | |
} | |
p := payload{X: "bar", Y: "foo"} | |
inst := &payload{} | |
if !resp.AssertJson(inst, p) { | |
t.Fatalf("Response body is %s asserted that it is %v", resp.String(), p) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
req, _ := http.NewRequest("GET", "/path/to/handler", nil) | |
// Create mock | |
resp := NewMockTestResponse(t) | |
testAuthWrapper(testAuthHandler)(resp, req) | |
if !resp.AssertCode(http.StatusUnauthorized) { | |
t.Fatalf("Response StatusCode is %d asserted that it is %d", resp.StatusCode, http.StatusUnauthorized) | |
} | |
if !resp.AssertBody(failedAuth) { | |
t.Fatalf("Response body is %s asserted that it is %s", resp.String(), failedAuth) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment