From 5dfc90f386e06a285fc24537c62808e223c8162c Mon Sep 17 00:00:00 2001 From: Maximilian Lenkeit Date: Tue, 5 Nov 2019 15:33:18 +0100 Subject: [PATCH 1/2] Make cobertura defaults compatible with UI5 (#941) * tests(testsPublishResults): evaluate file pattern for cobertura * tests(testsPublishResults): test for cobertura in UI5 projects * feat(testsPublishResults): collect cobertura of UI5 projects by default --- pom.xml | 7 +++++++ resources/default_pipeline_environment.yml | 2 +- test/groovy/TestsPublishResultsTest.groovy | 15 +++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 6231dd661..5d9913115 100644 --- a/pom.xml +++ b/pom.xml @@ -139,6 +139,13 @@ test + + fr.opensagres.js + minimatch.java + 1.1.0 + test + + diff --git a/resources/default_pipeline_environment.yml b/resources/default_pipeline_environment.yml index f8b0c7b64..675ff6177 100644 --- a/resources/default_pipeline_environment.yml +++ b/resources/default_pipeline_environment.yml @@ -526,7 +526,7 @@ steps: archive: false active: false cobertura: - pattern: '**/target/coverage/cobertura-coverage.xml' + pattern: '**/target/coverage/**/cobertura-coverage.xml' onlyStableBuilds: true allowEmptyResults: true archive: false diff --git a/test/groovy/TestsPublishResultsTest.groovy b/test/groovy/TestsPublishResultsTest.groovy index 3a4b9ff10..685bb3d24 100644 --- a/test/groovy/TestsPublishResultsTest.groovy +++ b/test/groovy/TestsPublishResultsTest.groovy @@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals import static org.junit.Assert.assertTrue import util.Rules +import minimatch.Minimatch class TestsPublishResultsTest extends BasePiperTest { Map publisherStepOptions @@ -90,14 +91,20 @@ class TestsPublishResultsTest extends BasePiperTest { stepRule.step.testsPublishResults(script: nullScript, jacoco: true, cobertura: true) assertTrue('JaCoCo options are empty', publisherStepOptions.jacoco != null) - assertTrue('Cobertura options are empty', publisherStepOptions.cobertura != null) assertEquals('JaCoCo default pattern not set correct', '**/target/*.exec', publisherStepOptions.jacoco.execPattern) - assertEquals('Cobertura default pattern not set correct', - '**/target/coverage/cobertura-coverage.xml', publisherStepOptions.cobertura.coberturaReportFile) // ensure nothing else is published assertTrue('JUnit options are not empty', publisherStepOptions.junit == null) assertTrue('JMeter options are not empty', publisherStepOptions.jmeter == null) + + assertTrue('Cobertura options are empty', publisherStepOptions.cobertura != null) + assertTrue('Cobertura default pattern is empty', publisherStepOptions.cobertura.coberturaReportFile != null) + String sampleCoberturaPathForJava = 'my/workspace/my/project/target/coverage/cobertura-coverage.xml' + assertTrue('Cobertura default pattern does not match files at target/coverage/cobertura-coverage.xml for Java projects', + Minimatch.minimatch(sampleCoberturaPathForJava, publisherStepOptions.cobertura.coberturaReportFile)) + String sampleCoberturaPathForKarma = 'my/workspace/my/project/target/coverage/Chrome 78.0.3904 (Mac OS X 10.14.6)/cobertura-coverage.xml' + assertTrue('Cobertura default pattern does not match files at target/coverage//cobertura-coverage.xml for UI5 projects', + Minimatch.minimatch(sampleCoberturaPathForKarma, publisherStepOptions.cobertura.coberturaReportFile)) } @Test @@ -145,7 +152,7 @@ class TestsPublishResultsTest extends BasePiperTest { }] }] } - + stepRule.step.testsPublishResults(script: nullScript) assertJobStatusSuccess() } From 58128be9701e06b2b8c6df0633efa010b7edbe23 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Tue, 5 Nov 2019 21:51:44 +0100 Subject: [PATCH 2/2] apply formatter (#950) --- cmd/piper_test.go | 5 ++--- cmd/version_test.go | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cmd/piper_test.go b/cmd/piper_test.go index c824d9a67..72bbbfce6 100644 --- a/cmd/piper_test.go +++ b/cmd/piper_test.go @@ -13,7 +13,6 @@ import ( "github.com/stretchr/testify/assert" ) - type execMockRunner struct { dir []string calls []execCall @@ -42,11 +41,11 @@ func (m *execMockRunner) RunExecutable(e string, p ...string) error { return nil } -func(m *shellMockRunner) Dir(d string) { +func (m *shellMockRunner) Dir(d string) { m.dir = d } -func(m *shellMockRunner) RunShell(s string, c string) error { +func (m *shellMockRunner) RunShell(s string, c string) error { m.calls = append(m.calls, c) return nil } diff --git a/cmd/version_test.go b/cmd/version_test.go index 5135bb4b5..a3daffb87 100644 --- a/cmd/version_test.go +++ b/cmd/version_test.go @@ -1,11 +1,11 @@ package cmd import ( - "testing" - "os" "bytes" - "io" "github.com/stretchr/testify/assert" + "io" + "os" + "testing" ) func TestVersion(t *testing.T) { @@ -17,7 +17,6 @@ func TestVersion(t *testing.T) { assert.Contains(t, result, "tag: \"\"") }) - t.Run("versionAndTagSet", func(t *testing.T) { result := runVersionCommand(t, "16bafe", "v1.2.3") @@ -29,9 +28,9 @@ func TestVersion(t *testing.T) { func runVersionCommand(t *testing.T, commitID, tag string) string { orig := os.Stdout - defer func() {os.Stdout = orig}() + defer func() { os.Stdout = orig }() - r,w,e := os.Pipe() + r, w, e := os.Pipe() if e != nil { t.Error("Cannot setup pipes.") } @@ -41,8 +40,12 @@ func runVersionCommand(t *testing.T, commitID, tag string) string { // // needs to be set in the free wild by the build process: // go build -ldflags "-X github.com/SAP/jenkins-library/cmd.GitCommit=${GIT_COMMIT} -X github.com/SAP/jenkins-library/cmd.GitTag=${GIT_TAG}" - if len(commitID) > 0 { GitCommit = commitID; } - if len(tag) > 0 { GitTag = tag } + if len(commitID) > 0 { + GitCommit = commitID + } + if len(tag) > 0 { + GitTag = tag + } defer func() { GitCommit = ""; GitTag = "" }() // // @@ -58,4 +61,4 @@ func runVersionCommand(t *testing.T, commitID, tag string) string { var buf bytes.Buffer io.Copy(&buf, r) return buf.String() -} \ No newline at end of file +}