1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
// OpenRDAP
// Copyright 2017 Tom Harwood
// MIT License, see the LICENSE file.
package test
import (
"io/ioutil"
"log"
"path"
"runtime"
)
var testDataPath string
func LoadFile(filename string) []byte {
var body []byte
if len(testDataPath) == 0 {
testDataPath = findTestDataPath()
}
body, err := ioutil.ReadFile(path.Join(testDataPath, filename))
if err != nil {
log.Panic(err)
}
return body
}
func findTestDataPath() string {
_, filename, _, ok := runtime.Caller(0)
if !ok {
log.Panic("runtime.Caller() failed")
}
dir, _ := path.Split(filename)
return path.Join(dir, "testdata")
}
|