-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support shard by scenario (#940)
* feat: Support shard by scenario * unique names * refine JSON schema * refine JSON schema * Update internal/cucumber/config.go Co-authored-by: Alex Plischke <[email protected]> * Update internal/cucumber/scenario/scenario.go Co-authored-by: Alex Plischke <[email protected]> * read feature separately --------- Co-authored-by: Alex Plischke <[email protected]>
- Loading branch information
1 parent
f00fcc8
commit ca4dd29
Showing
5 changed files
with
74 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package scenario | ||
|
||
import ( | ||
"io/fs" | ||
|
||
gherkin "github.com/cucumber/gherkin/go/v28" | ||
messages "github.com/cucumber/messages/go/v24" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
// List parses the provided files and returns a list of scenarios. | ||
func List(sys fs.FS, files []string) []*messages.Pickle { | ||
uuid := &messages.UUID{} | ||
|
||
var scenarios []*messages.Pickle | ||
for _, filename := range files { | ||
scenarios = append(scenarios, ReadFile(sys, filename, uuid)...) | ||
} | ||
return scenarios | ||
} | ||
|
||
// ReadFile reads a feature file and returns the parsed list of scenarios. | ||
func ReadFile(sys fs.FS, filename string, uuid *messages.UUID) []*messages.Pickle { | ||
f, err := sys.Open(filename) | ||
if err != nil { | ||
log.Warn().Str("filename", filename).Msgf("Failed to open the file: %v", err) | ||
return nil | ||
} | ||
defer f.Close() | ||
|
||
doc, err := gherkin.ParseGherkinDocument(f, uuid.NewId) | ||
if err != nil { | ||
log.Warn(). | ||
Str("filename", filename). | ||
Msg("Could not parse file. It will be excluded from sharded execution.") | ||
return nil | ||
} | ||
return gherkin.Pickles(*doc, filename, uuid.NewId) | ||
} | ||
|
||
// GetUniqueNames extracts and returns unique scenario names. | ||
func GetUniqueNames(scenarios []*messages.Pickle) []string { | ||
uniqueMap := make(map[string]bool) | ||
|
||
for _, s := range scenarios { | ||
uniqueMap[s.Name] = true | ||
} | ||
|
||
var names []string | ||
for name := range uniqueMap { | ||
names = append(names, name) | ||
} | ||
|
||
return names | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters