- Module github.com/eslider/go-config with env/yaml/json/ini packages - internal: source, keymap, merge, structconv, bytesutil - cmd/envc: convert, get, merge - docs/asr ASR-0001..0008, README/CHANGELOG/AGENTS refresh - golangci-lint v2 config; tests + fixtures Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1008 B
Go
47 lines
1008 B
Go
// Package testfixtures resolves paths to files under the module's fixtures/ directory.
|
|
package testfixtures
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func moduleRoot(t *testing.T) string {
|
|
t.Helper()
|
|
_, file, _, ok := runtime.Caller(0)
|
|
if !ok {
|
|
t.Fatal("runtime.Caller")
|
|
}
|
|
dir := filepath.Dir(file)
|
|
for {
|
|
data, err := os.ReadFile(filepath.Join(dir, "go.mod"))
|
|
if err == nil && strings.Contains(string(data), "module github.com/eslider/go-config") {
|
|
return dir
|
|
}
|
|
parent := filepath.Dir(dir)
|
|
if parent == dir {
|
|
t.Fatal("module root not found")
|
|
}
|
|
dir = parent
|
|
}
|
|
}
|
|
|
|
// Path joins repo fixtures/ with parts.
|
|
func Path(t *testing.T, parts ...string) string {
|
|
t.Helper()
|
|
return filepath.Join(append([]string{moduleRoot(t), "fixtures"}, parts...)...)
|
|
}
|
|
|
|
// Load reads a fixture file relative to fixtures/.
|
|
func Load(t *testing.T, parts ...string) []byte {
|
|
t.Helper()
|
|
b, err := os.ReadFile(Path(t, parts...))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return b
|
|
}
|