From c5d6fcbaba545d1078f5411dc67208d5d388222e Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 10 Jun 2015 16:10:33 -0400 Subject: Return error up stack instead of passing testing var down --- tests/init.go | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'tests/init.go') diff --git a/tests/init.go b/tests/init.go index b487f81c3..4a176698f 100644 --- a/tests/init.go +++ b/tests/init.go @@ -1,13 +1,14 @@ package tests import ( + "bytes" "encoding/json" + "fmt" "io" "io/ioutil" // "log" "net/http" "os" - "testing" // logpkg "github.com/ethereum/go-ethereum/logger" ) @@ -20,34 +21,40 @@ import ( // logpkg.AddLogSystem(Logger) // } -func readJSON(t *testing.T, reader io.Reader, value interface{}) { +func readJSON(reader io.Reader, value interface{}) error { data, err := ioutil.ReadAll(reader) err = json.Unmarshal(data, &value) if err != nil { - t.Error(err) + return err } + return nil } -func CreateHttpTests(t *testing.T, uri string, value interface{}) { +func CreateHttpTests(uri string, value interface{}) error { resp, err := http.Get(uri) if err != nil { - t.Error(err) - - return + return err } defer resp.Body.Close() - readJSON(t, resp.Body, value) + err = readJSON(resp.Body, value) + if err != nil { + return err + } + return nil } -func CreateFileTests(t *testing.T, fn string, value interface{}) { +func CreateFileTests(fn string, value interface{}) error { file, err := os.Open(fn) if err != nil { - t.Error(err) - - return + return err } defer file.Close() - readJSON(t, file, value) + err = readJSON(file, value) + if err != nil { + return err + } + return nil +} } -- cgit v1.2.3