Skip to content

Commit

Permalink
updated portfolio and submitter to support gherkin url
Browse files Browse the repository at this point in the history
Signed-off-by: Savvas Kyriacou <[email protected]>
  • Loading branch information
KirbyKatcher committed Feb 21, 2024
1 parent dfeac4b commit 6c211b2
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 41 deletions.
7 changes: 5 additions & 2 deletions pkg/runs/jsonReporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func TestJsonReportWorks(t *testing.T) {
Status: "myStatus",
Result: "PASSED",
Overrides: make(map[string]string, 1),
Tests: []TestMethod{{Method: "method1", Result: "passed"}, {Method: "method2", Result: "passed"}}}
Tests: []TestMethod{{Method: "method1", Result: "passed"}, {Method: "method2", Result: "passed"}},
GherkinUrl: "myfeature",
}

finishedRunsMap := make(map[string]*TestRun, 1)
finishedRunsMap["myTestRun"] = &finishedRuns
Expand Down Expand Up @@ -73,7 +75,8 @@ func TestJsonReportWorks(t *testing.T) {
"name": "method2",
"result": "passed"
}
]
],
"GherkinUrl":"myfeature"
}
]
}`
Expand Down
22 changes: 12 additions & 10 deletions pkg/runs/portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ type PortfolioMetadata struct {
}

type PortfolioClass struct {
Bundle string `yaml:"bundle"`
Class string `yaml:"class"`
Stream string `yaml:"stream"`
Obr string `yaml:"obr"`
Overrides map[string]string `yaml:"overrides"`
Bundle string `yaml:"bundle"`
Class string `yaml:"class"`
Stream string `yaml:"stream"`
Obr string `yaml:"obr"`
Overrides map[string]string `yaml:"overrides"`
GherkinUrl string `yaml:"gherkin"`
}

func NewPortfolio() *Portfolio {
Expand All @@ -55,11 +56,12 @@ func AddClassesToPortfolio(testSelection *TestSelection, testOverrides *map[stri

for _, selectedClass := range testSelection.Classes {
portfolioClass := PortfolioClass{
Bundle: selectedClass.Bundle,
Class: selectedClass.Class,
Stream: selectedClass.Stream,
Obr: selectedClass.Obr,
Overrides: *testOverrides,
Bundle: selectedClass.Bundle,
Class: selectedClass.Class,
Stream: selectedClass.Stream,
Obr: selectedClass.Obr,
Overrides: *testOverrides,
GherkinUrl: selectedClass.GherkinUrl,
}
portfolio.Classes = append(portfolio.Classes, portfolioClass)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/runs/runTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type TestRun struct {
Result string `yaml:"result" json:"result"`
Overrides map[string]string `yaml:"overrides" json:"overrides"`
Tests []TestMethod `yaml:"tests" json:"tests"`
GherkinUrl string `yaml:"gherkin"`
}

type TestMethod struct {
Expand Down
29 changes: 15 additions & 14 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, TestSelectionFlagValues.GherkinUrl)
err = submitter.validatePortfolio(portfolio, params.PortfolioFileName)
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

for len(readyRuns) > 0 || len(submittedRuns) > 0 || len(rerunRuns) > 0 { // Loop whilst there are runs to submit or are running

for len(submittedRuns) < throttle && len(readyRuns) > 0 {

readyRuns, err = submitter.submitRun(params.GroupName, readyRuns, submittedRuns,
lostRuns, &runOverrides, params.Trace, currentUser, params.RequestType, "")
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 @@ -286,7 +286,6 @@ func (submitter *Submitter) submitRun(
trace bool,
requestor string,
requestType string,
gherkinUrl string,
) ([]TestRun, error) {

var err error = nil
Expand All @@ -306,9 +305,9 @@ func (submitter *Submitter) submitRun(
}

var resultGroup *galasaapi.TestRuns
log.Printf("Submit Run - GherkunURL >" + gherkinUrl)
log.Printf("Submit Run - GherkunURL >" + nextRun.GherkinUrl)
resultGroup, err = submitter.launcher.SubmitTestRun(groupName, className, requestType, requestor,
nextRun.Stream, nextRun.Obr, trace, gherkinUrl, submitOverrides)
nextRun.Stream, nextRun.Obr, trace, nextRun.GherkinUrl, submitOverrides)
if err != nil {
log.Printf("Failed to submit test %v/%v - %v\n", nextRun.Bundle, nextRun.Class, err)
lostRuns[className] = &nextRun
Expand Down Expand Up @@ -482,6 +481,7 @@ func (submitter *Submitter) buildListOfRunsToSubmit(portfolio *Portfolio, runOve
Requestor: currentUser,
Status: "queued",
Overrides: make(map[string]string, 0),
GherkinUrl: portfolioTest.GherkinUrl,
}

// load the run overrides
Expand All @@ -495,8 +495,11 @@ func (submitter *Submitter) buildListOfRunsToSubmit(portfolio *Portfolio, runOve
}

readyRuns = append(readyRuns, newTestrun)

log.Printf("Added test %v/%v/%v to the ready queue\n", newTestrun.Stream, newTestrun.Bundle, newTestrun.Class)
if newTestrun.GherkinUrl == "" {
log.Printf("Added test %v/%v/%v to the ready queue\n", newTestrun.Stream, newTestrun.Bundle, newTestrun.Class)
} else {
log.Printf("Added gherkin test %v to the ready queue\n", newTestrun.GherkinUrl)
}
}

return readyRuns
Expand Down Expand Up @@ -694,13 +697,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) error {
var err error = nil
if portfolio.Classes == nil || len(portfolio.Classes) < 1 {
// Empty portfolio
if len(*gherkinUrl) < 1 {
err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_EMPTY_PORTFOLIO, portfolioFilename)
}
err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_EMPTY_PORTFOLIO, portfolioFilename)
}
return err
}
Expand Down
100 changes: 87 additions & 13 deletions pkg/runs/submitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,17 +482,7 @@ func TestSubmitRunwithGherkinFile(t *testing.T) {
groupName := "groupname"
var readyRuns []TestRun
testRun := TestRun{
Name: "mytest",
Bundle: "mybundle",
Class: "myclass",
Stream: "mystream",
Obr: "myobr",
Status: "",
QueuedTimeUTC: "",
Requestor: "",
Result : "",
Overrides: nil,
Tests: nil,
GherkinUrl: "gherkin.feature" ,
}
readyRuns = append(readyRuns, testRun)
submittedRuns := make(map[string]*TestRun)
Expand All @@ -501,10 +491,94 @@ func TestSubmitRunwithGherkinFile(t *testing.T) {
trace := false
requestor := "user"
requestType := ""
gherkinUrl :="gherkin.feature"

run, err := submitter.submitRun(groupName, readyRuns, submittedRuns, lostRuns ,runOverrides ,trace ,requestor ,requestType ,gherkinUrl)
run, err := submitter.submitRun(groupName, readyRuns, submittedRuns, lostRuns ,runOverrides ,trace ,requestor ,requestType)
assert.Nil(t,err)
assert.Empty(t,run)
assert.Contains(t, submittedRuns["M100"].GherkinUrl, "gherkin.feature")

}

func TestGetPortfolioReturnsGherkinPortfolio(t *testing.T) {
mockFileSystem := files.NewMockFileSystem()
env := utils.NewMockEnv()
env.SetUserName("myuserid")

galasaHome, err := utils.NewGalasaHome(mockFileSystem, env, "")
if err != nil {
assert.Fail(t, "Should not have failed! message = %s", err.Error())
}

mockLauncher := launcher.NewMockLauncher()

mockTimeService := utils.NewMockTimeService()
console := utils.NewMockConsole()
submitter := NewSubmitter(
galasaHome,
mockFileSystem,
mockLauncher,
mockTimeService,
env,
console,
)

flags := NewTestSelectionFlagValues()

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

portfolio, err := submitter.getPortfolio("", flags)

assert.Nil(t, err)
assert.NotEmpty(t, portfolio)
assert.Contains(t, portfolio.Classes[0].GherkinUrl, "gherkin.feature")
assert.Contains(t, portfolio.Classes[1].GherkinUrl, "test.feature")
assert.Contains(t, portfolio.Classes[2].GherkinUrl, "excellent.feature")
}

func TestGetReadyRunsFromPortfolioReturnsGherkinReadyRuns(t *testing.T) {
mockFileSystem := files.NewMockFileSystem()
env := utils.NewMockEnv()
env.SetUserName("myuserid")

galasaHome, err := utils.NewGalasaHome(mockFileSystem, env, "")
if err != nil {
assert.Fail(t, "Should not have failed! message = %s", err.Error())
}

mockLauncher := launcher.NewMockLauncher()

mockTimeService := utils.NewMockTimeService()
console := utils.NewMockConsole()
submitter := NewSubmitter(
galasaHome,
mockFileSystem,
mockLauncher,
mockTimeService,
env,
console,
)

flags := NewTestSelectionFlagValues()

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

portfolio, err := submitter.getPortfolio("", flags)
if err != nil {
assert.Fail(t, "Should not have failed! message = %s", err.Error())
}

overrides := make(map[string]string)

readyRuns := submitter.buildListOfRunsToSubmit(portfolio,overrides)

assert.NotEmpty(t, readyRuns)
assert.Contains(t, readyRuns[0].GherkinUrl, "gherkin.feature")
assert.Contains(t, readyRuns[1].GherkinUrl, "test.feature")
assert.Contains(t, readyRuns[2].GherkinUrl, "excellent.feature")
}
21 changes: 21 additions & 0 deletions pkg/runs/testSelection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,24 @@ func TestSelectTestFromGherkinUrlArrayReturnsTests(t *testing.T) {
assert.NotNil(t, testSelection)
assert.Equal(t, testSelection.Classes[0].GherkinUrl, "gherkin.feature")
}

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

*flags.GherkinUrl = make([]string, 3)
(*flags.GherkinUrl)[0] = "gherkin.feature"
(*flags.GherkinUrl)[1] = "test.feature"
(*flags.GherkinUrl)[2] = "excellent.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")
assert.Equal(t, testSelection.Classes[1].GherkinUrl, "test.feature")
assert.Equal(t, testSelection.Classes[2].GherkinUrl, "excellent.feature")
}
7 changes: 5 additions & 2 deletions pkg/runs/yamlReporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ func TestYamlReportWorks(t *testing.T) {
Requestor: "me",
Result: "PASSED",
Overrides: make(map[string]string, 1),
Tests: []TestMethod{{Method: "method1", Result: "passed"}, {Method: "method2", Result: "passed"}}}
Tests: []TestMethod{{Method: "method1", Result: "passed"}, {Method: "method2", Result: "passed"}},
GherkinUrl: "myfeature",
}

finishedRunsMap := make(map[string]*TestRun, 1)
finishedRunsMap["myTestRun"] = &finishedRuns
Expand Down Expand Up @@ -68,7 +70,8 @@ func TestYamlReportWorks(t *testing.T) {
- name: method1
result: passed
- name: method2
result: passed`
result: passed
gherkin: myfeature`

actualContents, err := mockFileSystem.ReadTextFile("myReportYamlFilename")
if err != nil {
Expand Down

0 comments on commit 6c211b2

Please sign in to comment.