func TestReadXML(t *testing.T) { assert := assert.New(t) body := strings.NewReader(`<Sample><hello>world</hello></Sample>`) req, err := http.NewRequest("POST", "/test", body) assert.NoError(err) req.Header.Set("Content-Type", "application/xml") var b Sample err = shttp.Read(req, &b) assert.Nil(err) assert.Equal(b.Hello, "world") }
func TestReadJSON(t *testing.T) { assert := assert.New(t) body := strings.NewReader(`{"hello":"world"}`) req, err := http.NewRequest("POST", "/test", body) assert.NoError(err) req.Header.Set("Content-Type", "application/json") var b Sample err = shttp.Read(req, &b) assert.Nil(err) assert.Equal(b.Hello, "world") }