Skip to content

Commit

Permalink
created a testSelection for gherkin tests
Browse files Browse the repository at this point in the history
Signed-off-by: Savvas Kyriacou <[email protected]>
  • Loading branch information
KirbyKatcher committed Feb 20, 2024
1 parent ac06ef9 commit dfeac4b
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/generated/errors-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The `galasactl` tool can generate the following errors:
- GAL1006E: The submit command does not support mixing of the test selection flags and a portfolio. Use the --help flag for more information, or refer to the documentation at https://galasa.dev/docs/reference/cli-commands.
- GAL1007E: Failed to create report yaml file {}. Reason is {}
- GAL1008E: Failed to check if group {} exists already. Reason is {}
- GAL1009E: The submit command requires either test selection flags (eg: --stream, --class, --bundle, --package, --tag, --regex, --test) or --portfolio flag to be specified. Use the --help flag for more information, or refer to the documentation at https://galasa.dev/docs/reference/cli-commands.
- GAL1009E: The submit command requires either test selection flags (eg: --stream, --class, --bundle, --package, --tag, --regex, --test, --gherkin) or --portfolio flag to be specified. Use the --help flag for more information, or refer to the documentation at https://galasa.dev/docs/reference/cli-commands.
- GAL1010E: Invalid override '{}'
- GAL1011E: Failed to encode the yaml file {}. Reason is {}
- GAL1012E: Failed to prepare test report for writing to json file {}. Reason is {}
Expand Down
1 change: 0 additions & 1 deletion docs/generated/galasactl_runs_download.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ galasactl runs download [flags]

* [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem

###### Auto generated by spf13/cobra on 19-Feb-2024
1 change: 0 additions & 1 deletion docs/generated/galasactl_runs_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ galasactl runs get [flags]

* [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem

###### Auto generated by spf13/cobra on 19-Feb-2024
2 changes: 1 addition & 1 deletion docs/generated/galasactl_runs_prepare.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ galasactl runs prepare [flags]
--append Append tests to existing portfolio
--bundle strings bundles of which tests will be selected from, bundles are selected if the name contains this string, or if --regex is specified then matches the regex
--class strings test class names to run from the specified stream or portfolio. The format of each entry is osgi-bundle-name/java-class-name . Java class names are fully qualified. No .class suffix is needed.
--gherkin strings Gherkin feature file URL. Should start with 'file://'.
-h, --help Displays the options for the 'runs prepare' command.
--override strings overrides to be sent with the tests (overrides in the portfolio will take precedence)
--package strings packages of which tests will be selected from, packages are selected if the name contains this string, or if --regex is specified then matches the regex
Expand All @@ -38,4 +39,3 @@ galasactl runs prepare [flags]

* [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem

###### Auto generated by spf13/cobra on 19-Feb-2024
3 changes: 1 addition & 2 deletions docs/generated/galasactl_runs_submit.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ galasactl runs submit [flags]
```
--bundle strings bundles of which tests will be selected from, bundles are selected if the name contains this string, or if --regex is specified then matches the regex
--class strings test class names to run from the specified stream or portfolio. The format of each entry is osgi-bundle-name/java-class-name . Java class names are fully qualified. No .class suffix is needed.
--gherkin string Gherkin feature file URL. Should start with 'file://'.
--gherkin strings Gherkin feature file URL. Should start with 'file://'.
-g, --group string the group name to assign the test runs to, if not provided, a psuedo unique id will be generated
-h, --help Displays the options for the 'runs submit' command.
--noexitcodeontestfailures set to true if you don't want an exit code to be returned from galasactl if a test fails
Expand Down Expand Up @@ -51,4 +51,3 @@ galasactl runs submit [flags]
* [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem
* [galasactl runs submit local](galasactl_runs_submit_local.md) - submit a list of tests to be run on a local java virtual machine (JVM)

###### Auto generated by spf13/cobra on 19-Feb-2024
3 changes: 1 addition & 2 deletions docs/generated/galasactl_runs_submit_local.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ galasactl runs submit local [flags]
--debugMode string The mode to use when the --debug option causes the testcase to connect to a Java debugger. Valid values are 'listen' or 'attach'. 'listen' means the testcase JVM will pause on startup, waiting for the Java debugger to connect to the debug port (see the --debugPort option). 'attach' means the testcase JVM will pause on startup, trying to attach to a java debugger which is listening on the debug port. The default value is 'listen' but can be overridden by the 'galasactl.jvm.local.launch.debug.mode' property in the bootstrap file, which in turn can be overridden by this explicit parameter on the galasactl command.
--debugPort uint32 The port to use when the --debug option causes the testcase to connect to a java debugger. The default value used is 2970 which can be overridden by the 'galasactl.jvm.local.launch.debug.port' property in the bootstrap file, which in turn can be overridden by this explicit parameter on the galasactl command.
--galasaVersion string the version of galasa you want to use to run your tests. This should match the version of the galasa obr you built your test bundles against. (default "0.32.0")
--gherkin string
--gherkin strings Gherkin feature file URL. Should start with 'file://'.
-h, --help Displays the options for the 'runs submit local' command.
--localMaven string The url of a local maven repository are where galasa bundles can be loaded from on your local file system. Defaults to your home .m2/repository file. Please note that this should be in a URL form e.g. 'file:///Users/myuserid/.m2/repository', or 'file://C:/Users/myuserid/.m2/repository'
--obr strings The maven coordinates of the obr bundle(s) which refer to your test bundles. The format of this parameter is 'mvn:${TEST_OBR_GROUP_ID}/${TEST_OBR_ARTIFACT_ID}/${TEST_OBR_VERSION}/obr' Multiple instances of this flag can be used to describe multiple obr bundles.
Expand Down Expand Up @@ -50,4 +50,3 @@ galasactl runs submit local [flags]

* [galasactl runs submit](galasactl_runs_submit.md) - submit a list of tests to the ecosystem

###### Auto generated by spf13/cobra on 19-Feb-2024
3 changes: 2 additions & 1 deletion pkg/cmd/runsSubmitLocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (cmd *RunsSubmitLocalCommand) createRunsSubmitLocalCobraCmd(
"The maven coordinates of the obr bundle(s) which refer to your test bundles. "+
"The format of this parameter is 'mvn:${TEST_OBR_GROUP_ID}/${TEST_OBR_ARTIFACT_ID}/${TEST_OBR_VERSION}/obr' "+
"Multiple instances of this flag can be used to describe multiple obr bundles.")
runsSubmitLocalCobraCmd.MarkFlagRequired("obr")
//runsSubmitLocalCobraCmd.MarkFlagRequired("obr")

runsSubmitLocalCobraCmd.Flags().Uint32Var(&cmd.values.runsSubmitLocalCmdParams.DebugPort, "debugPort", 0,
"The port to use when the --debug option causes the testcase to connect to a java debugger. "+
Expand Down Expand Up @@ -149,6 +149,7 @@ func (cmd *RunsSubmitLocalCommand) createRunsSubmitLocalCobraCmd(

runs.AddGherkinFlag(runsSubmitLocalCobraCmd, cmd.values.submitLocalSelectionFlags, false, "Gherkin feature file URL. Should start with 'file://'. ")

runsSubmitLocalCobraCmd.MarkFlagsRequiredTogether("class","obr")
runsSubmitLocalCobraCmd.MarkFlagsOneRequired("class","gherkin")

runsSubmitCmd.CobraCommand().AddCommand(runsSubmitLocalCobraCmd)
Expand Down
17 changes: 8 additions & 9 deletions pkg/cmd/runsSubmitLocal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func TestRunsSubmitLocalWithoutObrWithClassErrors(t *testing.T) {

// Then...
// Check what the user saw was reasonable
checkOutput("", "required flag(s) \"obr\" not set", "", factory, t)
checkOutput("", "if any flags in the group [class obr] are set they must all be set; missing [obr]", "", factory, t)

// Should throw an error asking for flags to be set
assert.NotNil(t, err, "err should have been set!")
assert.Contains(t, err.Error(), "required flag(s) \"obr\" not set")
assert.Contains(t, err.Error(), "if any flags in the group [class obr] are set they must all be set; missing [obr]")
}

func TestRunsSubmitLocalWithoutClassWithObrErrors(t *testing.T) {
Expand All @@ -70,11 +70,11 @@ func TestRunsSubmitLocalWithoutClassWithObrErrors(t *testing.T) {

// Then...
// Check what the user saw was reasonable
checkOutput("", "at least one of the flags in the group [class gherkin] is required", "", factory, t)
checkOutput("", "if any flags in the group [class obr] are set they must all be set; missing [class]", "", factory, t)

// Should throw an error asking for flags to be set
assert.NotNil(t, err, "err should have been set!")
assert.Contains(t, err.Error(), "at least one of the flags in the group [class gherkin] is required")
assert.Contains(t, err.Error(), "if any flags in the group [class obr] are set they must all be set; missing [class]")
}

func TestMultipleRequiredFlagsNotSetReturnsListInError(t *testing.T) {
Expand All @@ -87,11 +87,11 @@ func TestMultipleRequiredFlagsNotSetReturnsListInError(t *testing.T) {

// Then...
// Check what the user saw was reasonable
checkOutput("", "required flag(s) \"obr\" not set", "", factory, t)
checkOutput("", "at least one of the flags in the group [class gherkin] is required", "", factory, t)

// Should throw an error asking for flags to be set
assert.NotNil(t, err, "err should have been set!")
assert.Contains(t, err.Error(), "required flag(s) \"obr\" not set")
assert.Contains(t, err.Error(), "at least one of the flags in the group [class gherkin] is required")
}

func TestRunsSubmitLocalClassObrFlagReturnsOk(t *testing.T) {
Expand Down Expand Up @@ -281,7 +281,6 @@ func TestRunsSubmitLocaGherkinFlagsWork(t *testing.T) {

var args []string = []string{"runs", "submit", "local",
"--gherkin", "gherkin.feature",
"--obr", "mvn:a.big.ol.obr",
"--galasaVersion", "0.1.0",
"--debug",
"--debugMode", "thorough",
Expand All @@ -298,13 +297,13 @@ func TestRunsSubmitLocaGherkinFlagsWork(t *testing.T) {
// Check what the user saw is reasonable.
checkOutput("", "", "", factory, t)

//assert.Contains(t, cmd.Values().(*RunsSubmitLocalCmdValues).runsSubmitLocalCmdParams.GherkinURL, "gherkin.feature")
assert.Contains(t, cmd.Values().(*RunsSubmitLocalCmdValues).runsSubmitLocalCmdParams.Obrs, "mvn:a.big.ol.obr")
assert.Contains(t, *cmd.Values().(*RunsSubmitLocalCmdValues).submitLocalSelectionFlags.GherkinUrl, "gherkin.feature")
assert.Contains(t, cmd.Values().(*RunsSubmitLocalCmdValues).runsSubmitLocalCmdParams.TargetGalasaVersion, "0.1.0")
assert.Equal(t, cmd.Values().(*RunsSubmitLocalCmdValues).runsSubmitLocalCmdParams.IsDebugEnabled, true)
assert.Contains(t, cmd.Values().(*RunsSubmitLocalCmdValues).runsSubmitLocalCmdParams.DebugMode, "thorough")
assert.Equal(t, cmd.Values().(*RunsSubmitLocalCmdValues).runsSubmitLocalCmdParams.DebugPort, uint32(515))
assert.Contains(t, cmd.Values().(*RunsSubmitLocalCmdValues).runsSubmitLocalCmdParams.LocalMaven, "local/maven/location")
assert.Contains(t, cmd.Values().(*RunsSubmitLocalCmdValues).runsSubmitLocalCmdParams.RemoteMaven, "remote.maven.location")
assert.Empty(t, cmd.Values().(*RunsSubmitLocalCmdValues).runsSubmitLocalCmdParams.Obrs)
assert.Empty(t, cmd.Values().(*RunsSubmitLocalCmdValues).submitLocalSelectionFlags.Classes)
}
2 changes: 1 addition & 1 deletion pkg/errors/errorMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var (
GALASA_ERROR_SUBMIT_MIX_FLAGS_AND_PORTFOLIO = NewMessageType("GAL1006E: The submit command does not support mixing of the test selection flags and a portfolio."+SEE_COMMAND_REFERENCE, 1006, STACK_TRACE_WANTED)
GALASA_ERROR_SUBMIT_CREATE_REPORT_YAML = NewMessageType("GAL1007E: Failed to create report yaml file %s. Reason is %s", 1007, STACK_TRACE_WANTED)
GALASA_ERROR_SUBMIT_RUNS_GROUP_CHECK = NewMessageType("GAL1008E: Failed to check if group %s exists already. Reason is %s", 1008, STACK_TRACE_WANTED)
GALASA_ERROR_SUBMIT_MISSING_ACTION_FLAGS = NewMessageType("GAL1009E: The submit command requires either test selection flags (eg: --stream, --class, --bundle, --package, --tag, --regex, --test) or --portfolio flag to be specified."+SEE_COMMAND_REFERENCE, 1009, STACK_TRACE_WANTED)
GALASA_ERROR_SUBMIT_MISSING_ACTION_FLAGS = NewMessageType("GAL1009E: The submit command requires either test selection flags (eg: --stream, --class, --bundle, --package, --tag, --regex, --test, --gherkin) or --portfolio flag to be specified."+SEE_COMMAND_REFERENCE, 1009, STACK_TRACE_WANTED)
GALASA_ERROR_SUBMIT_INVALID_OVERRIDE = NewMessageType("GAL1010E: Invalid override '%v'", 1010, STACK_TRACE_WANTED)
GALASA_ERROR_SUBMIT_REPORT_YAML_ENCODE = NewMessageType("GAL1011E: Failed to encode the yaml file %s. Reason is %s", 1011, STACK_TRACE_WANTED)
GALASA_ERROR_SUBMIT_REPORT_JSON_MARSHAL = NewMessageType("GAL1012E: Failed to prepare test report for writing to json file %s. Reason is %s", 1012, STACK_TRACE_WANTED)
Expand Down
18 changes: 9 additions & 9 deletions pkg/runs/submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (submitter *Submitter) ExecuteSubmitRuns(
var portfolio *Portfolio
portfolio, err = submitter.getPortfolio(params.PortfolioFileName, TestSelectionFlagValues)
if err == nil {
err = submitter.validatePortfolio(portfolio, params.PortfolioFileName, params.GherkinUrl)
err = submitter.validatePortfolio(portfolio, params.PortfolioFileName, TestSelectionFlagValues.GherkinUrl)
if err == nil {
err = submitter.executePortfolio(portfolio, runOverrides, *params)
}
Expand Down Expand Up @@ -141,13 +141,13 @@ func (submitter *Submitter) executeSubmitRuns(
//
nextProgressReport := submitter.timeService.Now().Add(progressReportInterval)
isThrottleFileLost := false
log.Printf("executePortfolio - GherkunURL >"+ params.GherkinUrl)

for len(readyRuns) > 0 || len(submittedRuns) > 0 || len(rerunRuns) > 0 { // Loop whilst there are runs to submit or are running
log.Printf("executePortfolio runs loop - GherkunURL >"+ params.GherkinUrl)

for len(submittedRuns) < throttle && len(readyRuns) > 0 {
log.Printf("executePortfolio throttle loop - GherkunURL >"+ params.GherkinUrl)

readyRuns, err = submitter.submitRun(params.GroupName, readyRuns, submittedRuns,
lostRuns, &runOverrides, params.Trace, currentUser, params.RequestType, params.GherkinUrl)
lostRuns, &runOverrides, params.Trace, currentUser, params.RequestType, "")

if err != nil {
// Ignore the error and continue to process the list of available runs.
Expand Down Expand Up @@ -306,7 +306,7 @@ func (submitter *Submitter) submitRun(
}

var resultGroup *galasaapi.TestRuns
log.Printf("Submit Run - GherkunURL >"+ gherkinUrl)
log.Printf("Submit Run - GherkunURL >" + gherkinUrl)
resultGroup, err = submitter.launcher.SubmitTestRun(groupName, className, requestType, requestor,
nextRun.Stream, nextRun.Obr, trace, gherkinUrl, submitOverrides)
if err != nil {
Expand Down Expand Up @@ -531,7 +531,7 @@ func (submitter *Submitter) validateAndCorrectParams(
err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_SUBMIT_MIX_FLAGS_AND_PORTFOLIO)
}
} else {
if !AreSelectionFlagsProvided(submitSelectionFlags) && params.GherkinUrl == "" {
if !AreSelectionFlagsProvided(submitSelectionFlags) {
err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_SUBMIT_MISSING_ACTION_FLAGS)
}
}
Expand Down Expand Up @@ -694,11 +694,11 @@ func (submitter *Submitter) GetCurrentUserName() string {
return userName
}

func (submitter *Submitter) validatePortfolio(portfolio *Portfolio, portfolioFilename string, gherkinUrl string) error {
func (submitter *Submitter) validatePortfolio(portfolio *Portfolio, portfolioFilename string, gherkinUrl *[]string) error {
var err error = nil
if portfolio.Classes == nil || len(portfolio.Classes) < 1 {
// Empty portfolio
if gherkinUrl == "" {
if len(*gherkinUrl) < 1 {
err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_EMPTY_PORTFOLIO, portfolioFilename)
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/runs/submitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ func TestValidateAndCorrectParametersSetsDefaultOverrideFile(t *testing.T) {
Classes: new([]string),
Stream: "myStream",
RegexSelect: &regexSelectValue,
GherkinUrl: new([]string),
}

mockLauncher := launcher.NewMockLauncher()
Expand Down Expand Up @@ -422,6 +423,7 @@ func TestLocalLaunchCanUseAPortfolioOk(t *testing.T) {
Classes: new([]string),
Stream: "",
RegexSelect: &regexSelectValue,
GherkinUrl: new([]string),
}

mockLauncher := launcher.NewMockLauncher()
Expand Down
27 changes: 27 additions & 0 deletions pkg/runs/testSelection.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func AreSelectionFlagsProvided(flags *utils.TestSelectionFlagValues) bool {
return true
}

if len(*flags.GherkinUrl) > 0 {
return true
}

if flags.Stream != "" {
return true
}
Expand Down Expand Up @@ -184,11 +188,34 @@ func SelectTests(launcherInstance launcher.Launcher, flags *utils.TestSelectionF
if err == nil {
err = selectTestsByClass(testCatalog, &testSelection, flags)
}
if err == nil {
err = selectTestsByGherkin(testCatalog, &testSelection, flags)
}
}

return testSelection, err
}

func selectTestsByGherkin(testCatalog launcher.TestCatalog, testSelection *TestSelection, flags *utils.TestSelectionFlagValues) error {
var err error = nil

if len(*flags.GherkinUrl) < 1{
return err
}
gherkinUrls := *flags.GherkinUrl
for _, gherkin := range gherkinUrls{

newSelectedClass := TestClass{
GherkinUrl: gherkin,
}

testSelection.Classes = append(testSelection.Classes, newSelectedClass)
}


return err
}

func selectTestsByBundle(testCatalog launcher.TestCatalog, testSelection *TestSelection, flags *utils.TestSelectionFlagValues) error {

var err error = nil
Expand Down
19 changes: 19 additions & 0 deletions pkg/runs/testSelection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/galasa-dev/cli/pkg/launcher"
)

// ---------------------------------------------------
Expand Down Expand Up @@ -78,3 +80,20 @@ func TestStreamBasedValidatorWithStreamAndClassSpecifiedIsOk(t *testing.T) {
assert.Nil(t, err)

}

func TestSelectTestFromGherkinUrlArrayReturnsTests(t *testing.T) {
// Given...
launcher := launcher.NewMockLauncher()
flags := NewTestSelectionFlagValues()

*flags.GherkinUrl = make([]string, 1)
(*flags.GherkinUrl)[0] = "gherkin.feature"

// When...
testSelection, err := SelectTests(launcher, flags)

// Then...
assert.Nil(t, err)
assert.NotNil(t, testSelection)
assert.Equal(t, testSelection.Classes[0].GherkinUrl, "gherkin.feature")
}
1 change: 0 additions & 1 deletion pkg/utils/runSubmitCmdValues.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ type RunsSubmitCmdValues struct {
ThrottleFileName string
PortfolioFileName string
OverrideFilePath string
GherkinUrl string
TestSelectionFlagValues *TestSelectionFlagValues
}

0 comments on commit dfeac4b

Please sign in to comment.