Skip to content

Commit

Permalink
add test for parsing from bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Kaswen-Wilk committed Jul 15, 2022
1 parent 6a3bb0d commit bef3d7c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions internal/parser/parser_test.go
Expand Up @@ -37,6 +37,43 @@ func Test_FeatureFilePathParser(t *testing.T) {
}
}

func Test_ParseFromBytes_FromMultipleFeatures(t *testing.T) {
featureFileName := "godogs.feature"
eatGodogContents := `
Feature: eat godogs
In order to be happy
As a hungry gopher
I need to be able to eat godogs
Scenario: Eat 5 out of 12
Given there are 12 godogs
When I eat 5
Then there should be 7 remaining`

baseDir := filepath.Join(os.TempDir(), t.Name(), "godogs")
errA := os.MkdirAll(baseDir+"/a", 0755)
defer os.RemoveAll(baseDir)

require.Nil(t, errA)

err := ioutil.WriteFile(filepath.Join(baseDir, featureFileName), []byte(eatGodogContents), 0644)
require.Nil(t, err)

featureFromFile, err := parser.ParseFeatures("", []string{baseDir})
require.NoError(t, err)
require.Len(t, featureFromFile, 1)

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

featureFromBytes, err := parser.ParseFromBytes("", input)
require.NoError(t, err)
require.Len(t, featureFromBytes, 1)

assert.Equal(t, featureFromFile, featureFromBytes)
}

func Test_ParseFeatures_FromMultiplePaths(t *testing.T) {
const featureFileName = "godogs.feature"
const featureFileContents = `Feature: eat godogs
Expand Down
2 changes: 1 addition & 1 deletion run.go
Expand Up @@ -342,7 +342,7 @@ 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
// 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
Expand Down

0 comments on commit bef3d7c

Please sign in to comment.