Skip to content

Commit

Permalink
adjust feature contents option to slice of structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Kaswen-Wilk committed Jul 26, 2022
1 parent 25813de commit 9b38dd2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
7 changes: 6 additions & 1 deletion internal/flags/options.go
Expand Up @@ -68,5 +68,10 @@ type Options struct {
// 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
FeatureContents []Feature
}

type Feature struct {
Name string
Contents []byte
}
9 changes: 6 additions & 3 deletions internal/parser/parser.go
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/cucumber/gherkin-go/v19"
"github.com/cucumber/messages-go/v16"

"github.com/cucumber/godog/internal/flags"
"github.com/cucumber/godog/internal/models"
"github.com/cucumber/godog/internal/tags"
)
Expand Down Expand Up @@ -178,14 +179,16 @@ func ParseFeatures(filter string, paths []string) ([]*models.Feature, error) {
return features, nil
}

func ParseFromBytes(filter string, featuresInputs map[string][]byte) ([]*models.Feature, error) {
type FeatureContent = flags.Feature

func ParseFromBytes(filter string, featuresInputs []FeatureContent) ([]*models.Feature, error) {
var order int

featureIdxs := make(map[string]int)
uniqueFeatureURI := make(map[string]*models.Feature)
newIDFunc := (&messages.Incrementing{}).NewId
for path, feature := range featuresInputs {
ft, err := parseBytes(path, feature, newIDFunc)
for _, f := range featuresInputs {
ft, err := parseBytes(f.Name, f.Contents, newIDFunc)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/parser/parser_test.go
Expand Up @@ -63,8 +63,8 @@ Feature: eat godogs
require.NoError(t, err)
require.Len(t, featureFromFile, 1)

input := map[string][]byte{
filepath.Join(baseDir, featureFileName): []byte(eatGodogContents),
input := []parser.FeatureContent{
{Name: filepath.Join(baseDir, featureFileName), Contents: []byte(eatGodogContents)},
}

featureFromBytes, err := parser.ParseFromBytes("", input)
Expand Down
17 changes: 10 additions & 7 deletions run_test.go
Expand Up @@ -267,19 +267,22 @@ func Test_RunsWithFeatureContentsOption(t *testing.T) {
items, err := ioutil.ReadDir("./features")
require.NoError(t, err)

featureContents := make(map[string][]byte)
var featureContents []Feature
for _, item := range items {
if !item.IsDir() && strings.Contains(item.Name(), ".feature"){
contents, err := os.ReadFile("./features/"+item.Name())
if !item.IsDir() && strings.Contains(item.Name(), ".feature") {
contents, err := os.ReadFile("./features/" + item.Name())
require.NoError(t, err)
featureContents[item.Name()] = contents
featureContents = append(featureContents, Feature{
Name: item.Name(),
Contents: contents,
})
}
}

opts := Options{
Format: "progress",
Output: ioutil.Discard,
Strict: true,
Format: "progress",
Output: ioutil.Discard,
Strict: true,
FeatureContents: featureContents,
}

Expand Down
3 changes: 3 additions & 0 deletions test_context.go
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/cucumber/godog/formatters"
"github.com/cucumber/godog/internal/builder"
"github.com/cucumber/godog/internal/flags"
"github.com/cucumber/godog/internal/models"
"github.com/cucumber/messages-go/v16"
)
Expand Down Expand Up @@ -316,3 +317,5 @@ func (ctx *ScenarioContext) Step(expr, stepFunc interface{}) {
func Build(bin string) error {
return builder.Build(bin)
}

type Feature = flags.Feature

0 comments on commit 9b38dd2

Please sign in to comment.