From bef3d7c7c5e12739da443c891ea799b57a8cf21c Mon Sep 17 00:00:00 2001 From: Aaron Kaswen-Wilk Date: Thu, 14 Jul 2022 18:09:35 +0200 Subject: [PATCH] add test for parsing from bytes --- internal/parser/parser_test.go | 37 ++++++++++++++++++++++++++++++++++ run.go | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/internal/parser/parser_test.go b/internal/parser/parser_test.go index 19fbf851..c3dd4965 100644 --- a/internal/parser/parser_test.go +++ b/internal/parser/parser_test.go @@ -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 diff --git a/run.go b/run.go index ad1f865f..c29f3cbb 100644 --- a/run.go +++ b/run.go @@ -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