Exemplo n.º 1
0
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")
}
Exemplo n.º 2
0
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")
}