diff options
author | obscuren <geffobscura@gmail.com> | 2014-10-19 05:20:25 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-10-19 05:20:25 +0800 |
commit | 3bc64b6b6edf380aaa145e612988a4aa640e0d23 (patch) | |
tree | d495f81a7e7b27334ef35ddaeff7ce3757e403c0 /tests/helper/readers.go | |
parent | 73c1c2c4af17115b1b1d39d947d5d9cc4d8b07fb (diff) | |
download | go-tangerine-3bc64b6b6edf380aaa145e612988a4aa640e0d23.tar go-tangerine-3bc64b6b6edf380aaa145e612988a4aa640e0d23.tar.gz go-tangerine-3bc64b6b6edf380aaa145e612988a4aa640e0d23.tar.bz2 go-tangerine-3bc64b6b6edf380aaa145e612988a4aa640e0d23.tar.lz go-tangerine-3bc64b6b6edf380aaa145e612988a4aa640e0d23.tar.xz go-tangerine-3bc64b6b6edf380aaa145e612988a4aa640e0d23.tar.zst go-tangerine-3bc64b6b6edf380aaa145e612988a4aa640e0d23.zip |
Readers
Diffstat (limited to 'tests/helper/readers.go')
-rw-r--r-- | tests/helper/readers.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/helper/readers.go b/tests/helper/readers.go new file mode 100644 index 000000000..03313aeda --- /dev/null +++ b/tests/helper/readers.go @@ -0,0 +1,42 @@ +package helper + +import ( + "encoding/json" + "io" + "io/ioutil" + "net/http" + "os" + "testing" +) + +func readJSON(t *testing.T, reader io.Reader, value interface{}) { + data, err := ioutil.ReadAll(reader) + err = json.Unmarshal(data, &value) + if err != nil { + t.Error(err) + } +} + +func CreateHttpTests(t *testing.T, uri string, value interface{}) { + resp, err := http.Get(uri) + if err != nil { + t.Error(err) + + return + } + defer resp.Body.Close() + + readJSON(t, resp.Body, value) +} + +func CreateFileTests(t *testing.T, fn string, value interface{}) { + file, err := os.Open(fn) + if err != nil { + t.Error(err) + + return + } + defer file.Close() + + readJSON(t, file, value) +} |