Created
July 21, 2013 07:00
-
-
Save dahernan/6047770 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"github.com/bmizerany/assert" | |
"net/http" | |
"net/http/httptest" | |
"testing" | |
) | |
func TestJsonServerReturnsJsonDocumentWithRightHeaders(t *testing.T) { | |
req := new(http.Request) | |
builder := func(req *http.Request) interface{} { | |
return map[string]interface{}{ | |
"test": "test_value", | |
} | |
} | |
jsonServer := JsonServer(builder) | |
responseWriter := httptest.NewRecorder() | |
// call to test | |
jsonServer(responseWriter, req) | |
contentType := responseWriter.Header().Get("Content-Type") | |
assert.Equal(t, contentType, "application/json") | |
assert.Equal(t, "{\"test\":\"test_value\"}\n", responseWriter.Body.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment