testing/md/results.go

45 lines
872 B
Go
Raw 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:08:10 +00:00
2024-05-08 20:28:36 +00:00
package mockdata
import (
"path/filepath"
"log"
"fmt"
2024-05-08 21:32:31 +00:00
"gitea.rosskeen.house/rosskeen.house/testing/fixture"
2024-05-08 20:28:36 +00:00
)
type Results struct {
*fixture.Results
name string
basepath string
}
func R(name string) *Results { return &Results{ name: name } }
func (r *Results) BasePath() string {
if r.basepath == "" {
g := fmt.Sprintf("result_%s_", r.name)
r.basepath = filepath.Join("./testdata", g)
}
return r.basepath
}
func (r *Results) Paths() []string {
df, e := filepath.Glob(r.BasePath() + "*")
if e != nil {
log.Fatal(e)
}
return df
}
func (r *Results) Values() []fixture.Result {
// return MockData files
paths := r.Paths()
res := make([]fixture.Result, len(paths))
for i := range(paths) {
res[i] = ReadRaw(paths[i])
}
return res
}