Skip to content

Commit

Permalink
change interface to pass bytes as option
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Kaswen-Wilk committed Jul 23, 2022
1 parent bef3d7c commit 239dd4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
7 changes: 4 additions & 3 deletions internal/flags/options.go
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"io"
"testing"

"github.com/cucumber/godog/internal/models"
)

// Options are suite run options
Expand Down Expand Up @@ -67,5 +65,8 @@ type Options struct {
// TestingT runs scenarios as subtests.
TestingT *testing.T

Features []*models.Feature
// FeatureContents allows passing in each feature manually
// where the contents of each feature is stored as a byte slice
// in a map entry
FeatureContents map[string][]byte
}
29 changes: 7 additions & 22 deletions run.go
Expand Up @@ -227,13 +227,14 @@ func runWithOptions(suiteName string, runner runner, opt Options) int {
runner.fmt = multiFmt.FormatterFunc(suiteName, output)

var err error
if len(opt.Features) <= 0 {
if runner.features, err = parser.ParseFeatures(opt.Tags, opt.Paths); err != nil {
fmt.Fprintln(os.Stderr, err)
return exitOptionError
}
if len(opt.Paths) > 0 {
runner.features, err = parser.ParseFeatures(opt.Tags, opt.Paths)
} else {
runner.features = opt.Features
runner.features, err = parser.ParseFromBytes(opt.Tags, opt.FeatureContents)
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
return exitOptionError
}

runner.storage = storage.NewStorage()
Expand Down Expand Up @@ -342,22 +343,6 @@ func (ts TestSuite) RetrieveFeatures() ([]*models.Feature, error) {
return parser.ParseFeatures(opt.Tags, opt.Paths)
}

// should be a map of string[]byte where the string is the path name of the feature file
// and the []byte is the bytes read from the file
func (ts TestSuite) RetrieveFeaturesFromBytes(featuresInputs map[string][]byte) ([]*models.Feature, error) {
opt := ts.Options

if opt == nil {
var err error
opt, err = getDefaultOptions()
if err != nil {
return nil, err
}
}

return parser.ParseFromBytes(opt.Tags, featuresInputs)
}

func getDefaultOptions() (*Options, error) {
opt := &Options{}
opt.Output = colors.Colored(os.Stdout)
Expand Down

0 comments on commit 239dd4b

Please sign in to comment.