inital commit
This commit is contained in:
28
fixtures_test.go
Normal file
28
fixtures_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user