Skip to content

Commit f769760

Browse files
authored
Data Prepper Unit Test & Test Refactoring (#1451)
* Added a unit test for the Data Prepper build. Signed-off-by: David Venable <[email protected]>
1 parent d0ac211 commit f769760

5 files changed

+118
-8
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package jenkins.tests
7+
8+
import jenkins.tests.CommonPipelineTest
9+
import org.junit.Before
10+
11+
/**
12+
* Base class for testing jobs which do not need the implementation
13+
* details of the Jenkins library exposed.
14+
*/
15+
abstract class BaseJobPipelineTest extends CommonPipelineTest {
16+
@Override
17+
@Before
18+
void setUp() {
19+
super.setUp()
20+
21+
binding.setVariable('scm', {})
22+
helper.registerAllowedMethod('legacySCM', [Closure.class], null)
23+
helper.registerAllowedMethod("library", [Map.class], {})
24+
}
25+
}

tests/jenkins/BuildPipelineTest.groovy

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ import com.lesfurets.jenkins.unit.declarative.*
1717
import static org.junit.Assert.*
1818
import org.yaml.snakeyaml.Yaml
1919

20-
abstract class BuildPipelineTest extends DeclarativePipelineTest {
20+
/**
21+
* Base test class for testing Jenkins library code. This base test
22+
* sets up the project directory as the library and will execute
23+
* library code.
24+
*/
25+
abstract class BuildPipelineTest extends CommonPipelineTest {
2126
@Override
2227
@Before
2328
void setUp() {
@@ -46,11 +51,4 @@ abstract class BuildPipelineTest extends DeclarativePipelineTest {
4651
return new LibClassLoader(helper, null)
4752
})
4853
}
49-
50-
void testPipeline(String jenkinsScript, String regressionFilename = null) {
51-
runScript(jenkinsScript)
52-
RegressionTestHelper.testNonRegression(helper, regressionFilename ?: jenkinsScript)
53-
assertJobStatusSuccess()
54-
printCallStack()
55-
}
5654
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package jenkins.tests
7+
8+
import com.lesfurets.jenkins.unit.RegressionTestHelper
9+
import com.lesfurets.jenkins.unit.declarative.DeclarativePipelineTest
10+
import org.junit.Before
11+
12+
13+
/**
14+
* This base test class holds common functions, but does not perform
15+
* any additional setup. Test authors can extend from this class if
16+
* they don't need common setup. Otherwise, please see the sub-classes.
17+
*/
18+
abstract class CommonPipelineTest extends DeclarativePipelineTest {
19+
@Override
20+
@Before
21+
void setUp() {
22+
super.setUp()
23+
}
24+
25+
void testPipeline(String jenkinsScript, String regressionFilename = null) {
26+
runScript(jenkinsScript)
27+
RegressionTestHelper.testNonRegression(helper, regressionFilename ?: jenkinsScript)
28+
assertJobStatusSuccess()
29+
printCallStack()
30+
}
31+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import jenkins.tests.BaseJobPipelineTest
7+
import org.junit.Before
8+
import org.junit.Test
9+
10+
class TestDataPrepperDistributionArtifacts extends BaseJobPipelineTest {
11+
12+
@Before
13+
void setUp() {
14+
super.setUp()
15+
16+
binding.setVariable('VERSION', '0.22.1')
17+
binding.setVariable('BRANCH', 'refs/tags/0.22.1')
18+
19+
binding.setVariable('JOB_BASE_NAME', 'data-prepper-distribution-artifacts')
20+
binding.setVariable('BUILD_NUMBER', '7654321')
21+
binding.setVariable('WORKSPACE', '/tmp/workspace')
22+
23+
binding.setVariable('ARTIFACT_BUCKET_NAME', 'job-s3-bucket-name')
24+
25+
helper.registerAllowedMethod('checkout', [Map], {})
26+
helper.registerAllowedMethod('signArtifacts', [Map], {})
27+
helper.registerAllowedMethod('uploadToS3', [Map], {})
28+
helper.registerAllowedMethod('printArtifactDownloadUrlsForStaging', [Map], {})
29+
helper.registerAllowedMethod('postCleanup', [], {})
30+
}
31+
32+
@Test
33+
void dataPrepperDistributionArtifacts_builds_consistently() {
34+
testPipeline('jenkins/data-prepper/distribution-artifacts.jenkinsfile',
35+
'tests/jenkins/jobs/data-prepper/distribution-artifacts.jenkinsfile')
36+
}
37+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
distribution-artifacts.run()
2+
distribution-artifacts.legacySCM(groovy.lang.Closure)
3+
distribution-artifacts.library({identifier=jenkins@20211123, retriever=null})
4+
distribution-artifacts.pipeline(groovy.lang.Closure)
5+
distribution-artifacts.echo(Executing on agent [docker:[image:opensearchstaging/ci-runner:ci-runner-centos7-v1, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:Jenkins-Agent-al2-x64-c54xlarge-Docker-Host]])
6+
distribution-artifacts.stage(Build Data Prepper, groovy.lang.Closure)
7+
distribution-artifacts.script(groovy.lang.Closure)
8+
distribution-artifacts.checkout({changelog=false, poll=false, scm={$class=GitSCM, branches=[{name=refs/tags/0.22.1}], userRemoteConfigs=[{url=https://github.com/opensearch-project/data-prepper.git}]}})
9+
distribution-artifacts.sh(./gradlew clean :release:archives:linux:linuxTar -Prelease)
10+
distribution-artifacts.sh({script=find /tmp/workspace/release/archives/linux/build/distributions | sed -n "s|^/tmp/workspace/release/archives/linux/build/distributions/||p", returnStdout=true})
11+
distribution-artifacts.stage(Sign Artifacts, groovy.lang.Closure)
12+
distribution-artifacts.script(groovy.lang.Closure)
13+
distribution-artifacts.signArtifacts({artifactPath=/tmp/workspace/release/archives/linux/build/distributions, signatureType=.sig, distributionPlatform=linux})
14+
distribution-artifacts.stage(Upload Artifacts to Staging Distribution Bucket, groovy.lang.Closure)
15+
distribution-artifacts.script(groovy.lang.Closure)
16+
distribution-artifacts.uploadToS3({sourcePath=/tmp/workspace/release/archives/linux/build/distributions, bucket=job-s3-bucket-name, path=data-prepper-distribution-artifacts/0.22.1/7654321/builds/signed})
17+
distribution-artifacts.printArtifactDownloadUrlsForStaging({artifactFileNames=[bbb, bbb.sig, ccc, ccc.sig], uploadPath=data-prepper-distribution-artifacts/0.22.1/7654321/builds/signed})
18+
distribution-artifacts.script(groovy.lang.Closure)
19+
distribution-artifacts.postCleanup()

0 commit comments

Comments
 (0)