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 59a6d90
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 59a6d90

Please sign in to comment.