github.com/machinebox/remoto@v0.1.2-0.20191024144331-eff21a7d321f/go/remotohttp/encode_test.go (about) 1 package remotohttp_test 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "testing" 7 8 "github.com/machinebox/remoto/go/remotohttp" 9 "github.com/matryer/is" 10 ) 11 12 func TestEncode(t *testing.T) { 13 is := is.New(t) 14 data := struct { 15 Greeting string `json:"greeting"` 16 }{ 17 Greeting: "Hi there", 18 } 19 w := httptest.NewRecorder() 20 err := remotohttp.Encode(w, nil, http.StatusOK, data) 21 is.NoErr(err) 22 is.Equal(w.Code, http.StatusOK) 23 is.Equal(w.Body.String(), `{"greeting":"Hi there"}`) 24 is.Equal(w.HeaderMap.Get("Content-Type"), "application/json; chatset=utf-8") 25 }