From 5c6754344d8070761b4e6ad1e354e3a4b7d17eef Mon Sep 17 00:00:00 2001 From: Prudhvi Godithi Date: Fri, 25 Oct 2024 13:13:32 -0700 Subject: [PATCH] Handle publishIntegTestResults lib when test reports are not available. (#547) Signed-off-by: Prudhvi Godithi --- .../TestPublishIntegTestResults.groovy | 43 ++++++++++++++++++- vars/publishIntegTestResults.groovy | 8 +++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/tests/jenkins/TestPublishIntegTestResults.groovy b/tests/jenkins/TestPublishIntegTestResults.groovy index 446bbb9e..92136004 100644 --- a/tests/jenkins/TestPublishIntegTestResults.groovy +++ b/tests/jenkins/TestPublishIntegTestResults.groovy @@ -475,8 +475,8 @@ class TestPublishIntegTestResults extends BuildPipelineTest { distribution: 'tar', component_category: 'test_category', test_type: 'test_type', - test_class: 'Not Available', - test_name: 'Not Available' + test_class: 'Result Not Available', + test_name: 'Result Not Available' ] ] def parsedResult = result.trim().split('\n').collect { new JsonSlurper().parseText(it) } @@ -486,6 +486,45 @@ class TestPublishIntegTestResults extends BuildPipelineTest { assert parsedResult == expectedJson } + @Test + void testProcessFailedTestsWithTestResultFilesListNotAvailable() { + def script = loadScript('vars/publishIntegTestResults.groovy') + def result = script.processFailedTests(['Test Result Files List Not Available'], 'component1', 'componentRepo', + 'https://componentRepoUrl', '1.0', 123, 'http://example.com/build/123', 456, + 'http://example.com/distribution/456', System.currentTimeMillis(), 'rc1', 1, + 'linux', 'x64', 'tar', 'test_category', 'test_type', 'test_failures_index') + def expectedJson = [ + [ + index: [ + _index: 'test_failures_index' + ] + ], + [ + component: 'component1', + component_repo: 'componentRepo', + component_repo_url: 'https://componentRepoUrl', + version: '1.0', + integ_test_build_number: 123, + integ_test_build_url: 'http://example.com/build/123', + distribution_build_number: 456, + distribution_build_url: 'http://example.com/distribution/456', + rc: 'rc1', + rc_number: 1, + platform: 'linux', + architecture: 'x64', + distribution: 'tar', + component_category: 'test_category', + test_type: 'test_type', + test_class: 'Report Not Available', + test_name: 'Report Not Available' + ] + ] + def parsedResult = result.trim().split('\n').collect { new JsonSlurper().parseText(it) } + parsedResult.each { json -> + json.remove('build_start_time') + } + assert parsedResult == expectedJson + } @Test diff --git a/vars/publishIntegTestResults.groovy b/vars/publishIntegTestResults.groovy index 8024034e..21c9c6e6 100644 --- a/vars/publishIntegTestResults.groovy +++ b/vars/publishIntegTestResults.groovy @@ -108,7 +108,13 @@ def processFailedTests(failedTests, componentName, componentRepo, componentRepoU case failedTests.contains("Test Result Not Available"): def testResultJsonContent = generateFailedTestJson(componentName, componentRepo, componentRepoUrl, version, integTestBuildNumber, integTestBuildUrl, distributionBuildNumber, distributionBuildUrl, buildStartTime, rc, rcNumber, - platform, architecture, distribution, componentCategory, securityType, "Not Available", "Not Available") + platform, architecture, distribution, componentCategory, securityType, "Result Not Available", "Result Not Available") + finalFailedTestsJsonDoc += "{\"index\": {\"_index\": \"${testFailuresindexName}\"}}\n${testResultJsonContent}\n" + break + case failedTests.contains("Test Result Files List Not Available"): + def testResultJsonContent = generateFailedTestJson(componentName, componentRepo, componentRepoUrl, version, integTestBuildNumber, + integTestBuildUrl, distributionBuildNumber, distributionBuildUrl, buildStartTime, rc, rcNumber, + platform, architecture, distribution, componentCategory, securityType, "Report Not Available", "Report Not Available") finalFailedTestsJsonDoc += "{\"index\": {\"_index\": \"${testFailuresindexName}\"}}\n${testResultJsonContent}\n" break case failedTests.contains("No Failed Test"):