diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-06-11 04:10:33 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-06-19 04:20:44 +0800 |
commit | c5d6fcbaba545d1078f5411dc67208d5d388222e (patch) | |
tree | 20d4e6592ba8411a0ab5980522029c4aac4a8244 /tests/init.go | |
parent | 24554629b162d20a1f945386a45e3221c58adc2b (diff) | |
download | dexon-c5d6fcbaba545d1078f5411dc67208d5d388222e.tar dexon-c5d6fcbaba545d1078f5411dc67208d5d388222e.tar.gz dexon-c5d6fcbaba545d1078f5411dc67208d5d388222e.tar.bz2 dexon-c5d6fcbaba545d1078f5411dc67208d5d388222e.tar.lz dexon-c5d6fcbaba545d1078f5411dc67208d5d388222e.tar.xz dexon-c5d6fcbaba545d1078f5411dc67208d5d388222e.tar.zst dexon-c5d6fcbaba545d1078f5411dc67208d5d388222e.zip |
Return error up stack instead of passing testing var down
Diffstat (limited to 'tests/init.go')
-rw-r--r-- | tests/init.go | 33 |
1 files changed, 20 insertions, 13 deletions
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 +} } |