mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
util: test Response struct
This commit is contained in:
parent
f44d6a323a
commit
06eacf70a2
28
pkg/util/http_response_test.go
Normal file
28
pkg/util/http_response_test.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestResponse_DecodeJSON(t *testing.T) {
|
||||||
|
type temp struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
json := `{"name":"Test Name","a":"a"}`
|
||||||
|
reader := ioutil.NopCloser(bytes.NewReader([]byte(json)))
|
||||||
|
resp, err := NewResponse(&http.Response{
|
||||||
|
StatusCode: 200,
|
||||||
|
Body: reader,
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, json, resp.String())
|
||||||
|
|
||||||
|
var result temp
|
||||||
|
assert.NoError(t, resp.DecodeJSON(&result))
|
||||||
|
assert.Equal(t, "Test Name", result.Name)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user