make pickleStepIDs unique accross multiple paths (#366)
* make pickleStepIDs unique accross multiple paths * add test case for duplicate pickle ids * go fmt Co-authored-by: Rickard Englund <rickard.englund@skf.com>
Этот коммит содержится в:
родитель
adfc936dd7
коммит
2fc2995149
2 изменённых файлов: 48 добавлений и 4 удалений
|
@ -78,7 +78,7 @@ func parseFeatureDir(dir string, newIDFunc func() string) ([]*models.Feature, er
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func parsePath(path string) ([]*models.Feature, error) {
|
func parsePath(path string, newIDFunc func() string) ([]*models.Feature, error) {
|
||||||
var features []*models.Feature
|
var features []*models.Feature
|
||||||
|
|
||||||
path, line := ExtractFeaturePathLine(path)
|
path, line := ExtractFeaturePathLine(path)
|
||||||
|
@ -88,8 +88,6 @@ func parsePath(path string) ([]*models.Feature, error) {
|
||||||
return features, err
|
return features, err
|
||||||
}
|
}
|
||||||
|
|
||||||
newIDFunc := (&messages.Incrementing{}).NewId
|
|
||||||
|
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
return parseFeatureDir(path, newIDFunc)
|
return parseFeatureDir(path, newIDFunc)
|
||||||
}
|
}
|
||||||
|
@ -119,8 +117,9 @@ func ParseFeatures(filter string, paths []string) ([]*models.Feature, error) {
|
||||||
|
|
||||||
featureIdxs := make(map[string]int)
|
featureIdxs := make(map[string]int)
|
||||||
uniqueFeatureURI := make(map[string]*models.Feature)
|
uniqueFeatureURI := make(map[string]*models.Feature)
|
||||||
|
newIDFunc := (&messages.Incrementing{}).NewId
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
feats, err := parsePath(path)
|
feats, err := parsePath(path, newIDFunc)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case os.IsNotExist(err):
|
case os.IsNotExist(err):
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package parser_test
|
package parser_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/cucumber/godog/internal/parser"
|
"github.com/cucumber/godog/internal/parser"
|
||||||
)
|
)
|
||||||
|
@ -32,3 +36,44 @@ func Test_FeatureFilePathParser(t *testing.T) {
|
||||||
assert.Equal(t, ln, c.line)
|
assert.Equal(t, ln, c.line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_ParseFeatures_FromMultiplePaths(t *testing.T) {
|
||||||
|
const featureFileName = "godogs.feature"
|
||||||
|
const featureFileContents = `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)
|
||||||
|
errB := os.MkdirAll(baseDir+"/b", 0755)
|
||||||
|
defer os.RemoveAll(baseDir)
|
||||||
|
|
||||||
|
require.Nil(t, errA)
|
||||||
|
require.Nil(t, errB)
|
||||||
|
|
||||||
|
err := ioutil.WriteFile(filepath.Join(baseDir+"/a", featureFileName), []byte(featureFileContents), 0644)
|
||||||
|
require.Nil(t, err)
|
||||||
|
err = ioutil.WriteFile(filepath.Join(baseDir+"/b", featureFileName), []byte(featureFileContents), 0644)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
features, err := parser.ParseFeatures("", []string{baseDir + "/a", baseDir + "/b"})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Len(t, features, 2)
|
||||||
|
|
||||||
|
pickleIDs := map[string]bool{}
|
||||||
|
for _, f := range features {
|
||||||
|
for _, p := range f.Pickles {
|
||||||
|
if pickleIDs[p.Id] {
|
||||||
|
assert.Failf(t, "found duplicate pickle ID", "Pickle ID %s was already used", p.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pickleIDs[p.Id] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче