Skip to content

Commit

Permalink
feat: make pattern optional by introducing a separate function
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed Aug 23, 2022
1 parent 545d683 commit fb14f48
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions gobdd_go1_16.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@ import (
"io/fs"
)

// WithFeaturesFS configures a filesystem where features can be found and loads all files mathing the "*.feature" pattern.
func WithFeaturesFS(fs fs.FS) func(*SuiteOptions) {
return func(options *SuiteOptions) {
options.featureSource = fsFeatureSource{
fs: fs,
pattern: "*.feature",
}
}
}

// WithFeaturesFS configures a filesystem and a pattern (regexp) where features can be found.
// An empty path defaults to "*.feature"
func WithFeaturesFS(fs fs.FS, pattern string) func(*SuiteOptions) {
func WithFeaturesFSPattern(fs fs.FS, pattern string) func(*SuiteOptions) {
if pattern == "" {
pattern = "*.feature"
}

return func(options *SuiteOptions) {
options.featureSource = fsFeatureSource{
fs: fs,
Expand All @@ -26,12 +40,7 @@ type fsFeatureSource struct {
}

func (s fsFeatureSource) loadFeatures() ([]feature, error) {
pattern := s.pattern
if pattern == "" {
pattern = "*.feature"
}

files, err := fs.Glob(s.fs, pattern)
files, err := fs.Glob(s.fs, s.pattern)
if err != nil {
return nil, fmt.Errorf("loading features: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion gobdd_go1_16_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestWithFeaturesFS(t *testing.T) {
suite := NewSuite(t, WithFeaturesFS(featuresFS, "example.feature"))
suite := NewSuite(t, WithFeaturesFSPattern(featuresFS, "example.feature"))
compiled := regexp.MustCompile(`I add (\d+) and (\d+)`)
suite.AddRegexStep(compiled, add)
compiled = regexp.MustCompile(`the result should equal (\d+)`)
Expand Down

0 comments on commit fb14f48

Please sign in to comment.