Skip to content

Commit

Permalink
Merge pull request #15 from nellyc/test_matrix_option
Browse files Browse the repository at this point in the history
Add suite properties
  • Loading branch information
nellyc authored Mar 19, 2020
2 parents 7183a3c + 53db2db commit a688f92
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 54 deletions.
4 changes: 2 additions & 2 deletions pkg/ginkgo-reporters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ This reporter fills in the xunit file the needed fields in order to upload it in
- --polarion-execution=true to enable the reporter
- --project-id="QE" will be set under 'properties'
- --polarion-custom-plannedin="QE_1_0" will be set under 'properties'
- --test-tier="tier1" will be set under 'properties'

#### Optional parameters:
- --polarion-report-file the output file will be generated under working directory, the default is polarion_results.xml
- --test-suite-params="OS=EL8 Storage=NFS Arch=x86" will be set under 'properties' and the values will get concatenated to the test run name

### Usage

Expand All @@ -28,6 +28,6 @@ when executing the tests, in addition to your regular execution parameters,
add the reporter parameters as specified above

``` bash
go test YOUR_PARAMS --polarion-execution=true --project-id="QE" --polarion-custom-plannedin="QE_1_0" --test-tier="tier1" --polarion-report-file="polarion.xml"
go test YOUR_PARAMS --polarion-execution=true --project-id="QE" --polarion-custom-plannedin="QE_1_0" --polarion-report-file="polarion.xml"
```
Will generate `polarion.xml` file under the work directory that can be imported into polarion.
79 changes: 39 additions & 40 deletions pkg/ginkgo-reporters/polarion_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func init() {
flag.StringVar(&Polarion.ProjectId, "polarion-project-id", "", "Set Polarion project ID")
flag.StringVar(&Polarion.Filename, "polarion-report-file", "polarion_results.xml", "Set Polarion report file path")
flag.StringVar(&Polarion.PlannedIn, "polarion-custom-plannedin", "", "Set Polarion planned-in ID")
flag.StringVar(&Polarion.Tier, "test-tier", "", "Set test tier number")
flag.StringVar(&Polarion.LookupMethod, "polarion-lookup-method", "id", "Set Polarion lookup method - id or name")
flag.StringVar(&Polarion.TestSuiteParams, "test-suite-params", "", "Set test suite params in space seperated name=value structure. Note that the values will be appended to the test run ID")
}

type PolarionTestSuite struct {
Expand Down Expand Up @@ -79,14 +79,14 @@ type PolarionProperty struct {
}

type PolarionReporter struct {
Suite PolarionTestSuite
Run bool
Filename string
TestSuiteName string
ProjectId string
PlannedIn string
Tier string
Suite PolarionTestSuite
Run bool
Filename string
TestSuiteName string
ProjectId string
PlannedIn string
LookupMethod string
TestSuiteParams string
}

func (reporter *PolarionReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
Expand All @@ -96,36 +96,30 @@ func (reporter *PolarionReporter) SpecSuiteWillBegin(config config.GinkgoConfigT
TestCases: []PolarionTestCase{},
}

properties := PolarionProperties{
Property: []PolarionProperty{
{
Name: "polarion-project-id",
Value: reporter.ProjectId,
},
{
Name: "polarion-lookup-method",
Value: reporter.LookupMethod,
},
{
Name: "polarion-custom-plannedin",
Value: reporter.PlannedIn,
},
{
Name: "polarion-testrun-id",
Value: reporter.PlannedIn + "_" + reporter.Tier,
},
{
Name: "polarion-custom-isautomated",
Value: "True",
},
{
Name: "polarion-testrun-status-id",
Value: "inprogress",
},
},
valuesString := ""
suiteParams := strings.Split(reporter.TestSuiteParams, " ")
for _, s := range suiteParams {
keyValue := strings.Split(s, "=")
if len(keyValue) > 1 {
valuesString = valuesString + "_" + keyValue[1]
reporter.Suite.Properties.Property = addProperty(
reporter.Suite.Properties.Property, "polarion-custom-"+keyValue[0], keyValue[1])
}
}

reporter.Suite.Properties = properties
reporter.Suite.Properties.Property = addProperty(
reporter.Suite.Properties.Property, "polarion-project-id", reporter.ProjectId)
reporter.Suite.Properties.Property = addProperty(
reporter.Suite.Properties.Property, "polarion-lookup-method", reporter.LookupMethod)
reporter.Suite.Properties.Property = addProperty(
reporter.Suite.Properties.Property, "polarion-custom-plannedin", reporter.PlannedIn)
reporter.Suite.Properties.Property = addProperty(
reporter.Suite.Properties.Property, "polarion-testrun-id", reporter.PlannedIn + valuesString)
reporter.Suite.Properties.Property = addProperty(
reporter.Suite.Properties.Property, "polarion-custom-isautomated", "True")
reporter.Suite.Properties.Property = addProperty(
reporter.Suite.Properties.Property, "polarion-testrun-status-id", "inprogress")

reporter.TestSuiteName = summary.SuiteDescription
}

Expand Down Expand Up @@ -194,10 +188,6 @@ func (reporter *PolarionReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
fmt.Println("Can not create Polarion report without planned-in ID")
return
}
if reporter.Tier == "" {
fmt.Println("Can not create Polarion report without tier ID")
return
}

reporter.Suite.Tests = summary.NumberOfSpecsThatWillBeRun
reporter.Suite.Time = summary.RunTime.Seconds()
Expand Down Expand Up @@ -238,3 +228,12 @@ func extractTestID(testname string, ProjectID string) PolarionProperties {
}
return properties
}

func addProperty(properties []PolarionProperty, key string, value string) []PolarionProperty {
properties = append(
properties, PolarionProperty{
Name: key,
Value: value,
})
return properties
}
31 changes: 19 additions & 12 deletions pkg/ginkgo-reporters/polarion_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,24 @@ var _ = Describe("ginkgo_reporters", func() {
}

reporter = PolarionReporter{
Run: true,
Filename: "polarion.xml",
ProjectId: "QE",
PlannedIn: "QE_1.0",
Tier: "tier1",
LookupMethod: "id",
Run: true,
Filename: "polarion.xml",
ProjectId: "QE",
PlannedIn: "QE_1.0",
LookupMethod: "id",
TestSuiteParams: "OS=EL7 SC=NFS",
}

properties = PolarionProperties{
Property: []PolarionProperty{
{
Name: "polarion-custom-OS",
Value: "EL7",
},
{
Name: "polarion-custom-SC",
Value: "NFS",
},
{
Name: "polarion-project-id",
Value: "QE",
Expand All @@ -74,15 +82,15 @@ var _ = Describe("ginkgo_reporters", func() {
},
{
Name: "polarion-testrun-id",
Value: "QE_1.0_tier1",
Value: "QE_1.0_EL7_NFS",
},
{
Name: "polarion-custom-isautomated",
Value: "True",
},
{
Name: "polarion-testrun-status-id",
Value: "inprogress",
Value: "inprogress",
},
},
}
Expand Down Expand Up @@ -148,9 +156,9 @@ var _ = Describe("ginkgo_reporters", func() {
},
},
{
Name: fmt.Sprintf("%s: %s", "IS", "A FAILING TEST"),
Name: fmt.Sprintf("%s: %s", "IS", "A FAILING TEST"),
Properties: PolarionProperties{},
SystemOut: "Test output",
SystemOut: "Test output",
FailureMessage: &JUnitFailureMessage{
Type: "Failure",
Message: "file/b:4\nERROR MSG\nfile/a:3",
Expand All @@ -175,7 +183,6 @@ var _ = Describe("ginkgo_reporters", func() {
Filename: "polarion.xml",
ProjectId: "QE",
PlannedIn: "QE_1.0",
Tier: "tier1",
}

It("Should info reporter test cases did complete", func() {
Expand Down Expand Up @@ -203,7 +210,7 @@ var _ = Describe("ginkgo_reporters", func() {
Filename: "polarion.xml",
ProjectId: "QE",
PlannedIn: "QE_1.0",
Tier: "tier1",
TestSuiteParams: "",
}

It("Should info number of tests, execution time, number of failures & verify report file was created", func() {
Expand Down

0 comments on commit a688f92

Please sign in to comment.