forked from mirror/go-ethereum
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
930 B
54 lines
930 B
10 years ago
|
package tests
|
||
10 years ago
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"io"
|
||
|
"io/ioutil"
|
||
10 years ago
|
// "log"
|
||
10 years ago
|
"net/http"
|
||
|
"os"
|
||
|
"testing"
|
||
10 years ago
|
|
||
|
// logpkg "github.com/ethereum/go-ethereum/logger"
|
||
10 years ago
|
)
|
||
|
|
||
10 years ago
|
// var Logger *logpkg.StdLogSystem
|
||
|
// var Log = logpkg.NewLogger("TEST")
|
||
|
|
||
|
// func init() {
|
||
|
// Logger = logpkg.NewStdLogSystem(os.Stdout, log.LstdFlags, logpkg.InfoLevel)
|
||
|
// logpkg.AddLogSystem(Logger)
|
||
|
// }
|
||
|
|
||
10 years ago
|
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)
|
||
|
}
|