49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||
|
package testdata
|
||
|
|
||
|
import (
|
||
|
"path/filepath"
|
||
|
"log"
|
||
|
"fmt"
|
||
|
"gitea.cv.mazarbul.net/rosskeen.house/testing/fixture"
|
||
|
)
|
||
|
|
||
|
type TypeConversion func(value interface{}) interface{}
|
||
|
|
||
|
type Results struct {
|
||
|
*fixture.Results
|
||
|
name string
|
||
|
basepath string
|
||
|
convert TypeConversion
|
||
|
}
|
||
|
|
||
|
func NoConversion(value interface{}) interface{} { return value }
|
||
|
func R(name string) *Results { return &Results{ name: name, convert: NoConversion } }
|
||
|
func Rt(name string, convert TypeConversion) *Results { return &Results{ name: name, convert: convert } }
|
||
|
|
||
|
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 TestData files
|
||
|
paths := r.Paths()
|
||
|
res := make([]fixture.Result, len(paths))
|
||
|
for i := range(paths) {
|
||
|
res[i] = r.convert(string(Read(paths[i])))
|
||
|
}
|
||
|
return res
|
||
|
}
|