2022-09-04 09:38:49 -07:00
|
|
|
package fixtures
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-09-04 15:28:39 -07:00
|
|
|
// Load returns the fixture at the given path.
|
|
|
|
func Load(t *testing.T, strs ...string) []byte {
|
2022-09-04 09:38:49 -07:00
|
|
|
_, file, _, ok := runtime.Caller(0)
|
|
|
|
require.True(t, ok, "runtime.Caller failed")
|
2022-09-04 15:28:39 -07:00
|
|
|
parts := make([]string, 1, 1+len(strs))
|
|
|
|
parts[0] = filepath.Dir(file)
|
|
|
|
parts = append(parts, strs...)
|
|
|
|
data, err := os.ReadFile(filepath.Join(parts...))
|
2022-09-04 09:38:49 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
return data
|
|
|
|
}
|