-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
gobdd_go1_16.go
57 lines (46 loc) · 996 Bytes
/
gobdd_go1_16.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//go:build go1.16
// +build go1.16
package gobdd
import (
"fmt"
"io"
"io/fs"
)
// WithFeaturesFS configures a filesystem and a path (glob pattern) where features can be found.
func WithFeaturesFS(fs fs.FS, path string) func(*SuiteOptions) {
return func(options *SuiteOptions) {
options.featureSource = fsFeatureSource{
fs: fs,
path: path,
}
}
}
type fsFeatureSource struct {
fs fs.FS
path string
}
func (s fsFeatureSource) loadFeatures() ([]feature, error) {
files, err := fs.Glob(s.fs, s.path)
if err != nil {
return nil, fmt.Errorf("loading features: %w", err)
}
features := make([]feature, 0, len(files))
for _, f := range files {
features = append(features, fsFeature{
fs: s.fs,
file: f,
})
}
return features, nil
}
type fsFeature struct {
fs fs.FS
file string
}
func (f fsFeature) Open() (io.Reader, error) {
file, err := f.fs.Open(f.file)
if err != nil {
return nil, fmt.Errorf("opening feature: %w", err)
}
return file, nil
}