diff --git a/tests/jenkins/BuildPipelineTest.groovy b/tests/jenkins/BuildPipelineTest.groovy new file mode 100644 index 0000000000..f82c043684 --- /dev/null +++ b/tests/jenkins/BuildPipelineTest.groovy @@ -0,0 +1,56 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package jenkins.tests + +import org.junit.* +import java.util.* +import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library +import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource +import com.lesfurets.jenkins.unit.* +import com.lesfurets.jenkins.unit.declarative.* +import static org.junit.Assert.* +import org.yaml.snakeyaml.Yaml + +abstract class BuildPipelineTest extends DeclarativePipelineTest { + @Override + @Before + void setUp() { + super.setUp() + + helper.registerSharedLibrary( + library().name('jenkins') + .defaultVersion('') + .allowOverride(true) + .implicit(true) + .targetPath('') + .retriever(projectSource()) + .build() + ) + + helper.registerAllowedMethod("readYaml", [Map.class], { args -> + return new Yaml().load((args.file as File).text) + }) + + binding.setVariable('scm', {}) + + helper.registerAllowedMethod("legacySCM", [Closure.class], null) + + helper.registerAllowedMethod("library", [Map.class], { Map args -> + helper.getLibLoader().loadLibrary(args["identifier"]) + return new LibClassLoader(helper, null) + }) + } + + void testPipeline(String jenkinsScript) { + runScript(jenkinsScript) + RegressionTestHelper.testNonRegression(helper, jenkinsScript) + assertJobStatusSuccess() + printCallStack() + } +} diff --git a/tests/jenkins/TestBuild.groovy b/tests/jenkins/TestBuild.groovy index 20300c0f99..abc10edd1f 100644 --- a/tests/jenkins/TestBuild.groovy +++ b/tests/jenkins/TestBuild.groovy @@ -9,18 +9,11 @@ package jenkins.tests import org.junit.* -import com.lesfurets.jenkins.unit.BasePipelineTest -import com.lesfurets.jenkins.unit.MethodCall -import static org.assertj.core.api.Assertions.assertThat -class TestBuild extends BasePipelineTest { - def jenkinsScript = "tests/jenkins/jobs/build.groovy" - - @Override - @Before - void setUp() throws Exception { - super.setUp() +class TestBuild extends BuildPipelineTest { + @Test + @Ignore // TODO: needs fix for https://github.com/jenkinsci/JenkinsPipelineUnit/issues/419 and docker declarations + void testBuild() { + super.testPipeline("tests/jenkins/jobs/Build_Jenkinsfile") } - - // TODO: needs fix for https://github.com/jenkinsci/JenkinsPipelineUnit/issues/419 } diff --git a/tests/jenkins/TestBuildManifest.groovy b/tests/jenkins/TestBuildManifest.groovy index 44be1aa5d1..3666f3686c 100644 --- a/tests/jenkins/TestBuildManifest.groovy +++ b/tests/jenkins/TestBuildManifest.groovy @@ -9,42 +9,10 @@ package jenkins.tests import org.junit.* -import java.util.* -import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library -import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource -import com.lesfurets.jenkins.unit.* -import com.lesfurets.jenkins.unit.declarative.* -import static org.junit.Assert.* -import org.yaml.snakeyaml.Yaml - -class TestBuildManifest extends DeclarativePipelineTest { - def jenkinsScript = "tests/jenkins/jobs/BuildManifest_Jenkinsfile" - - @Override - @Before - void setUp() throws Exception { - super.setUp() - - helper.registerSharedLibrary( - library().name('jenkins') - .defaultVersion('') - .allowOverride(true) - .implicit(true) - .targetPath('') - .retriever(projectSource()) - .build() - ) - - helper.registerAllowedMethod("readYaml", [Map.class], { args -> - return new Yaml().load((args.file as File).text) - }) - } +class TestBuildManifest extends BuildPipelineTest { @Test - void testBuildManifest() throws Exception { - runScript(jenkinsScript) - RegressionTestHelper.testNonRegression(helper, jenkinsScript) - assertJobStatusSuccess() - printCallStack() + void testBuildManifest() { + super.testPipeline("tests/jenkins/jobs/BuildManifest_Jenkinsfile") } } diff --git a/tests/jenkins/TestHello.groovy b/tests/jenkins/TestHello.groovy index 13b0e49a9c..4174727440 100644 --- a/tests/jenkins/TestHello.groovy +++ b/tests/jenkins/TestHello.groovy @@ -9,23 +9,10 @@ package jenkins.tests import org.junit.* -import com.lesfurets.jenkins.unit.* -import static org.assertj.core.api.Assertions.* - -class TestHello extends BasePipelineTest { - def jenkinsScript = "tests/jenkins/jobs/Hello_Jenkinsfile" - - @Override - @Before - void setUp() throws Exception { - super.setUp() - } +class TestHello extends BuildPipelineTest { @Test void testHello() { - runScript(jenkinsScript) - RegressionTestHelper.testNonRegression(helper, jenkinsScript) - assertJobStatusSuccess() - printCallStack() + super.testPipeline("tests/jenkins/jobs/Hello_Jenkinsfile") } } diff --git a/tests/jenkins/TestInputManifest.groovy b/tests/jenkins/TestInputManifest.groovy index 6ca04a5206..f0c88c0ee5 100644 --- a/tests/jenkins/TestInputManifest.groovy +++ b/tests/jenkins/TestInputManifest.groovy @@ -9,42 +9,10 @@ package jenkins.tests import org.junit.* -import java.util.* -import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library -import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource -import com.lesfurets.jenkins.unit.* -import com.lesfurets.jenkins.unit.declarative.* -import static org.junit.Assert.* -import org.yaml.snakeyaml.Yaml - -class TestInputManifest extends DeclarativePipelineTest { - def jenkinsScript = "tests/jenkins/jobs/InputManifest_Jenkinsfile" - - @Override - @Before - void setUp() throws Exception { - super.setUp() - - helper.registerSharedLibrary( - library().name('jenkins') - .defaultVersion('') - .allowOverride(true) - .implicit(true) - .targetPath('') - .retriever(projectSource()) - .build() - ) - - helper.registerAllowedMethod("readYaml", [Map.class], { args -> - return new Yaml().load((args.file as File).text) - }) - } +class TestInputManifest extends BuildPipelineTest { @Test - void testInputManifest() throws Exception { - runScript(jenkinsScript) - RegressionTestHelper.testNonRegression(helper, jenkinsScript) - assertJobStatusSuccess() - printCallStack() + void testInputManifest() { + super.testPipeline("tests/jenkins/jobs/InputManifest_Jenkinsfile") } } diff --git a/tests/jenkins/TestMessages.groovy b/tests/jenkins/TestMessages.groovy index d15d6f667b..3962f436f5 100644 --- a/tests/jenkins/TestMessages.groovy +++ b/tests/jenkins/TestMessages.groovy @@ -10,38 +10,18 @@ package jenkins.tests import org.junit.* import java.util.* -import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library -import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource -import com.lesfurets.jenkins.unit.* -import com.lesfurets.jenkins.unit.declarative.* -import static org.junit.Assert.* - -class TestMessages extends DeclarativePipelineTest { - def jenkinsScript = "tests/jenkins/jobs/Messages_Jenkinsfile" +class TestMessages extends BuildPipelineTest { @Override @Before - void setUp() throws Exception { + void setUp() { super.setUp() - helper.registerAllowedMethod('findFiles', [Map.class], null) - - helper.registerSharedLibrary( - library().name('jenkins') - .defaultVersion('') - .allowOverride(true) - .implicit(true) - .targetPath('') - .retriever(projectSource()) - .build() - ) + helper.registerAllowedMethod('findFiles', [Map.class], null) } @Test - void testMessages() throws Exception { - runScript(jenkinsScript) - RegressionTestHelper.testNonRegression(helper, jenkinsScript) - assertJobStatusSuccess() - printCallStack() + public void testMessages() { + super.testPipeline("tests/jenkins/jobs/Messages_Jenkinsfile") } } diff --git a/tests/jenkins/TestParallelMessages.groovy b/tests/jenkins/TestParallelMessages.groovy index 813ee5bcbd..e55f425daf 100644 --- a/tests/jenkins/TestParallelMessages.groovy +++ b/tests/jenkins/TestParallelMessages.groovy @@ -9,50 +9,20 @@ package jenkins.tests import org.junit.* -import static org.junit.Assert.* import java.util.* -import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library -import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource -import com.lesfurets.jenkins.unit.LibClassLoader -import com.lesfurets.jenkins.unit.declarative.* -import com.lesfurets.jenkins.unit.MethodCall -import static org.assertj.core.api.Assertions.assertThat - -class TestParallelMessages extends DeclarativePipelineTest { - def jenkinsScript = "tests/jenkins/jobs/ParallelMessages_Jenkinsfile" +class TestParallelMessages extends BuildPipelineTest { @Override @Before - void setUp() throws Exception { + void setUp() { super.setUp() helper.registerAllowedMethod('findFiles', [Map.class], null) - - helper.registerSharedLibrary( - library().name('jenkins') - .defaultVersion('') - .allowOverride(true) - .implicit(true) - .targetPath('') - .retriever(projectSource()) - .build() - ) } @Test @Ignore // raises MissingMethodException on docker agent declaration, need to upgrade jenkins-pipeline-unit which has new problems - void testParallelMessages() throws Exception { - binding.setVariable('scm', {}) - helper.registerAllowedMethod("legacySCM", [Closure.class], null) - - helper.registerAllowedMethod("library", [Map.class], { Map args -> - helper.getLibLoader().loadLibrary(args["identifier"]) - return new LibClassLoader(helper, null) - }) - - runScript(jenkinsScript) - - assertJobStatusSuccess() - printCallStack() + void testParallelMessages() { + super.testPipeline("tests/jenkins/jobs/ParallelMessages_Jenkinsfile") } }