Created
July 7, 2018 20:02
-
-
Save gufranmirza/cb22e70f131b15ae0434aebc57ab36b2 to your computer and use it in GitHub Desktop.
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
func TestStaticFileServer(t *testing.T) { | |
r := newRouter() | |
mockServer := httptest.NewServer(r) | |
// We want to hit the `GET /assets/` route to get the index.html file response | |
resp, err := http.Get(mockServer.URL + "/assets/") | |
if err != nil { | |
t.Fatal(err) | |
} | |
// We want our status to be 200 (ok) | |
if resp.StatusCode != http.StatusOK { | |
t.Errorf("Status should be 200, got %d", resp.StatusCode) | |
} | |
// It isn't wise to test the entire content of the HTML file. | |
// Instead, we test that the content-type header is "text/html; charset=utf-8" | |
// so that we know that an html file has been served | |
contentType := resp.Header.Get("Content-Type") | |
expectedContentType := "text/html; charset=utf-8" | |
if expectedContentType != contentType { | |
t.Errorf("Wrong content type, expected %s, got %s", expectedContentType, contentType) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment