36 lines
798 B
Go
36 lines
798 B
Go
|
|
package suite
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
// readRepoFile reads a path relative to the repository root.
|
||
|
|
//
|
||
|
|
// Tests run from their own package directory, so fixture paths are resolved
|
||
|
|
// against the module root rather than the working directory. Hard-coding
|
||
|
|
// "../.." would break the moment the suite moved.
|
||
|
|
func readRepoFile(t *testing.T, rel string) []byte {
|
||
|
|
t.Helper()
|
||
|
|
|
||
|
|
dir, err := os.Getwd()
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
for {
|
||
|
|
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
|
||
|
|
raw, err := os.ReadFile(filepath.Join(dir, rel))
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("read %s: %v", rel, err)
|
||
|
|
}
|
||
|
|
return raw
|
||
|
|
}
|
||
|
|
parent := filepath.Dir(dir)
|
||
|
|
if parent == dir {
|
||
|
|
t.Fatalf("could not find the repository root above %s", dir)
|
||
|
|
}
|
||
|
|
dir = parent
|
||
|
|
}
|
||
|
|
}
|