29 lines
851 B
Go
29 lines
851 B
Go
package fa
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// fixturesDir is where captured FA HTML responses live. The refresh tool
|
|
// (see fixtures_refresh_test.go, build tag `fixtures`) writes here.
|
|
const fixturesDir = "testdata/html"
|
|
|
|
// loadFixture reads a captured HTML fixture by name and skips the test if
|
|
// the file is missing. Pairs with the `fixtures` build-tagged refresh test:
|
|
// if you've never run the refresh, parser tests against real HTML are skipped
|
|
// cleanly instead of failing.
|
|
func loadFixture(t *testing.T, name string) []byte {
|
|
t.Helper()
|
|
path := filepath.Join(fixturesDir, name)
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
t.Skipf("fixture %s not present run `go test -tags=fixtures` with FA_* env vars to refresh", path)
|
|
}
|
|
t.Fatalf("read fixture %s: %v", path, err)
|
|
}
|
|
return data
|
|
}
|