diff --git a/internal/saucecloud/retry/junitretrier.go b/internal/saucecloud/retry/junitretrier.go index f873dbfb2..51f96afdf 100644 --- a/internal/saucecloud/retry/junitretrier.go +++ b/internal/saucecloud/retry/junitretrier.go @@ -52,7 +52,7 @@ func setClassesToRetry(opt *job.StartOptions, testcases []junit.TestCase) { } if opt.Framework == xcuitest.Kind { - tests := getFailedXCUITests(testcases) + tests := getFailedXCUITests(testcases, opt.RealDevice) // RDC and VDC API filter use different fields for test filtering. if opt.RealDevice { @@ -89,11 +89,11 @@ func (b *JunitRetrier) Retry(jobOpts chan<- job.StartOptions, opt job.StartOptio // getFailedXCUITests returns a list of failed XCUITest tests from the given // test cases. The format is "/", with the test // method name being optional. -func getFailedXCUITests(testCases []junit.TestCase) []string { +func getFailedXCUITests(testCases []junit.TestCase, rdc bool) []string { classes := map[string]bool{} for _, tc := range testCases { if tc.Error != nil || tc.Failure != nil { - className := normalizeXCUITestClassName(tc.ClassName) + className := conformXCUITestClassName(tc.ClassName, rdc) if tc.Name != "" { classes[fmt.Sprintf("%s/%s", className, tc.Name)] = true } else { @@ -104,12 +104,18 @@ func getFailedXCUITests(testCases []junit.TestCase) []string { return maps.Keys(classes) } -// normalizeXCUITestClassName normalizes the class name of an XCUITest. The -// class name within the platform generated JUnit XML file can be dot-separated, -// but our platform API expects a slash-separated class name. The platform is -// unfortunately not consistent in this regard and is not in full control of the -// generated JUnit XML file, hence we reconcile the two here. -func normalizeXCUITestClassName(name string) string { +// conformXCUITestClassName conforms the class name of an XCUITest to either +// RDC or VMD. The class name within the platform generated JUnit XML file can +// be dot-separated, but unlike RDC, VMD expects a slash-separated class name. +// The platform is unfortunately not consistent in this regard and is not in +// full control of the generated JUnit XML file. +// If the test is run on RDC, the class name is not modified and returned as is. +// If the test is run on VMD, the class name is converted to a slash-separated. +func conformXCUITestClassName(name string, rdc bool) string { + if rdc { + return name + } + items := strings.Split(name, ".") if len(items) == 1 { return name diff --git a/internal/saucecloud/retry/junitretrier_test.go b/internal/saucecloud/retry/junitretrier_test.go index 1e04af31c..c45465a89 100644 --- a/internal/saucecloud/retry/junitretrier_test.go +++ b/internal/saucecloud/retry/junitretrier_test.go @@ -196,7 +196,7 @@ func TestAppsRetrier_Retry(t *testing.T) { Framework: xcuitest.Kind, DisplayName: "Dummy Test", TestOptions: map[string]interface{}{}, - TestsToRun: []string{"Demo/Class1/demoTest"}, + TestsToRun: []string{"Demo.Class1/demoTest"}, SmartRetry: job.SmartRetry{ FailedOnly: true, }, @@ -377,6 +377,7 @@ func TestAppsRetrier_Retry(t *testing.T) { func Test_normalizeXCUITestClassName(t *testing.T) { type args struct { name string + rdc bool } tests := []struct { name string @@ -384,24 +385,41 @@ func Test_normalizeXCUITestClassName(t *testing.T) { want string }{ { - name: "needs normalization", - args: args{name: "DemoAppTests.ClassyTest"}, + name: "dot separated is not VMD conform", + args: args{ + name: "DemoAppTests.ClassyTest", + rdc: false, + }, want: "DemoAppTests/ClassyTest", }, { - name: "already normalized", - args: args{name: "DemoAppTests/ClassyTest"}, + name: "already VMD conform with slashes", + args: args{ + name: "DemoAppTests/ClassyTest", + rdc: false, + }, want: "DemoAppTests/ClassyTest", }, { - name: "nothing to normalize", - args: args{name: "DemoAppTests"}, + name: "already VMD conform without separators", + args: args{ + name: "DemoAppTests", + rdc: false, + }, want: "DemoAppTests", }, + { + name: "already RDC conform", + args: args{ + name: "DemoAppTests.ClassyTest", + rdc: true, + }, + want: "DemoAppTests.ClassyTest", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - assert.Equalf(t, tt.want, normalizeXCUITestClassName(tt.args.name), "normalizeXCUITestClassName(%v)", tt.args.name) + assert.Equalf(t, tt.want, conformXCUITestClassName(tt.args.name, tt.args.rdc), "conformXCUITestClassName(%v)", tt.args.name) }) } }