go-pulse/tests/init.go

54 lines
930 B
Go
Raw Normal View History

2015-06-10 17:00:54 +00:00
package tests
2014-10-18 21:20:25 +00:00
import (
"encoding/json"
"io"
"io/ioutil"
2015-06-10 17:00:54 +00:00
// "log"
2014-10-18 21:20:25 +00:00
"net/http"
"os"
"testing"
2015-06-10 17:00:54 +00:00
// logpkg "github.com/ethereum/go-ethereum/logger"
2014-10-18 21:20:25 +00:00
)
2015-06-10 17:00:54 +00:00
// var Logger *logpkg.StdLogSystem
// var Log = logpkg.NewLogger("TEST")
// func init() {
// Logger = logpkg.NewStdLogSystem(os.Stdout, log.LstdFlags, logpkg.InfoLevel)
// logpkg.AddLogSystem(Logger)
// }
2014-10-18 21:20:25 +00:00
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)
}