From 3bc64b6b6edf380aaa145e612988a4aa640e0d23 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 18 Oct 2014 23:20:25 +0200 Subject: Readers --- tests/helper/http.go | 25 ------------------------- tests/helper/readers.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 25 deletions(-) delete mode 100644 tests/helper/http.go create mode 100644 tests/helper/readers.go (limited to 'tests/helper') diff --git a/tests/helper/http.go b/tests/helper/http.go deleted file mode 100644 index 3c570d106..000000000 --- a/tests/helper/http.go +++ /dev/null @@ -1,25 +0,0 @@ -package helper - -import ( - "encoding/json" - "io/ioutil" - "net/http" - "testing" -) - -func CreateTests(t *testing.T, uri string, value interface{}) { - resp, err := http.Get(uri) - if err != nil { - t.Error(err) - - return - } - defer resp.Body.Close() - - data, err := ioutil.ReadAll(resp.Body) - - err = json.Unmarshal(data, &value) - if err != nil { - t.Error(err) - } -} 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) +} -- cgit