summaryrefslogtreecommitdiff
path: root/test/fixture.go
blob: 8edcb25136b21c750f25bc692aca51f359899043 (plain)
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
package test

import (
	"io/ioutil"
	"path/filepath"
	"runtime"
	"strings"
)

func Fixture(path string) string {
	bytes, err := ioutil.ReadFile(filepath.Join(thisDir(), "fixtures", path))
	if err != nil {
		return ""
	}
	return strings.TrimSuffix(string(bytes), "\n")
}

func thisFile() string {
	_, thisFile, _, _ := runtime.Caller(0)
	return thisFile
}

func thisDir() string {
	return filepath.Dir(thisFile())
}