testing/fixtures/testdata.go

46 lines
906 B
Go
Raw Permalink Normal View History

2024-05-08 20:28:36 +00:00
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
2024-05-08 21:32:31 +00:00
2024-05-08 20:28:36 +00:00
package fixtures
2024-05-08 21:32:31 +00:00
/*
2024-05-08 20:28:36 +00:00
import (
"testing"
"io/ioutil"
"path/filepath"
"log"
"fmt"
"strings"
"strconv"
)
func (f *F) FixtureTestDataBasePath() string {
g := fmt.Sprintf("fixture_%s_", f.Name())
p := filepath.Join("./testdata", g)
d := filepath.Join(g,p)
return d
}
func (f *F) FixtureTestDataPaths() []string {
p := f.FixtureTestDataBasePath()
df, e := filepath.Glob(p + "*")
if e != nil {
log.Fatal(e)
}
return df
}
func (f *F) FixtureTestData() {
bp := f.FixtureTestDataBasePath()
df := f.FixtureTestDataPaths()
for i, d := range(df) {
subtestname := strings.TrimPrefix(d, bp)
if subtestname == d {
subtestname = strconv.Itoa(i)
}
data,_ := ioutil.ReadFile(d)
f.Run(f.Name() + "." + subtestname, func (t *testing.T) { f.RunWith(f.T, data) })
}
}
2024-05-08 21:32:31 +00:00
*/