forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestDataPrepperReleaseArtifacts.groovy
152 lines (123 loc) · 7.11 KB
/
TestDataPrepperReleaseArtifacts.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.equalTo
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.CoreMatchers.hasItems
import static org.hamcrest.CoreMatchers.notNullValue
import static org.hamcrest.MatcherAssert.assertThat
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource
class TestDataPrepperReleaseArtifacts extends BuildPipelineTest {
private String version
@Override
@Before
void setUp() {
helper.registerSharedLibrary(
library().name('jenkins')
.defaultVersion('1.0.4')
.allowOverride(true)
.implicit(true)
.targetPath('vars')
.retriever(gitSource('https://github.com/opensearch-project/opensearch-build-libraries.git'))
.build()
)
version = '0.22.1'
String sourceImageRepository = 'http://public.ecr.aws/data-prepper-container-repository'
// this.registerLibTester(new SignArtifactsLibTester( '.sig', 'linux', "${workspace}/archive", null, null))
binding.setVariable('GITHUB_BOT_TOKEN_NAME', 'github_bot_token_name')
helper.registerAllowedMethod('git', [Map])
helper.registerAllowedMethod('withCredentials', [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
})
helper.registerAllowedMethod('withAWS', [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
})
super.setUp()
binding.setVariable('VERSION', version)
binding.setVariable('DATA_PREPPER_BUILD_NUMBER', '997908')
binding.setVariable('DATA_PREPPER_ARTIFACT_STAGING_SITE', 'http://staging-artifacts.cloudfront.net')
binding.setVariable('DATA_PREPPER_STAGING_CONTAINER_REPOSITORY', sourceImageRepository)
binding.setVariable('ARTIFACT_PRODUCTION_BUCKET_NAME', 'production-s3-bucket-name')
binding.setVariable('ARTIFACT_PROMOTION_ROLE_NAME', 'production-role-name')
binding.setVariable('AWS_ACCOUNT_ARTIFACT', 'aws-account-artifact')
helper.registerAllowedMethod('withAWS', [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
})
helper.registerAllowedMethod('s3Upload', [Map], {})
}
@Test
void 'release-data-prepper-all-artifacts builds consistently with same inputs'() {
testPipeline('jenkins/data-prepper/release-data-prepper-all-artifacts.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/data-prepper/release-data-prepper-all-artifacts.jenkinsfile')
}
@Test
public void releaseMajorVersionTag(){
String majorTag = true
binding.setVariable('RELEASE_MAJOR_TAG', majorTag)
testPipeline('jenkins/data-prepper/release-data-prepper-all-artifacts.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/data-prepper/release-data-prepper-major-version.jenkinsfile')
}
@Test
public void releaseLatestVersionTag(){
String latestTag = true
binding.setVariable('RELEASE_LATEST_TAG', latestTag)
testPipeline('jenkins/data-prepper/release-data-prepper-all-artifacts.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/data-prepper/release-data-prepper-latest-version.jenkinsfile')
}
@Test
void 'downloads archives from the correct URLs'() {
runScript('jenkins/data-prepper/release-data-prepper-all-artifacts.jenkinsfile')
def archiveCommands = getCurlCommands().findAll {
shCommand -> shCommand.contains('tar')
}
assertThat(archiveCommands.size(), equalTo(2))
assertThat(archiveCommands, hasItem(
"curl -sSL http://staging-artifacts.cloudfront.net/${version}/997908/archive/opensearch-data-prepper-${version}-linux-x64.tar.gz -o opensearch-data-prepper-${version}-linux-x64.tar.gz".toString()
))
assertThat(archiveCommands, hasItem(
"curl -sSL http://staging-artifacts.cloudfront.net/${version}/997908/archive/opensearch-data-prepper-jdk-${version}-linux-x64.tar.gz -o opensearch-data-prepper-jdk-${version}-linux-x64.tar.gz".toString()
))
}
@Test
void 'downloads Maven artifacts from the correct URLs'() {
runScript('jenkins/data-prepper/release-data-prepper-all-artifacts.jenkinsfile')
def mavenCommands = getCurlCommands().findAll {
shCommand -> shCommand.contains('maven/org/opensearch/dataprepper')
}
assertThat(mavenCommands, hasItems(
"curl -sSL http://staging-artifacts.cloudfront.net/${version}/997908/maven/org/opensearch/dataprepper/data-prepper-api/${version}/data-prepper-api-${version}-javadoc.jar -o org/opensearch/dataprepper/data-prepper-api/${version}/data-prepper-api-${version}-javadoc.jar".toString(),
"curl -sSL http://staging-artifacts.cloudfront.net/${version}/997908/maven/org/opensearch/dataprepper/data-prepper-api/${version}/data-prepper-api-${version}.jar.md5 -o org/opensearch/dataprepper/data-prepper-api/${version}/data-prepper-api-${version}.jar.md5".toString(),
"curl -sSL http://staging-artifacts.cloudfront.net/${version}/997908/maven/org/opensearch/dataprepper/data-prepper-api/${version}/data-prepper-api-${version}.pom.sha1 -o org/opensearch/dataprepper/data-prepper-api/${version}/data-prepper-api-${version}.pom.sha1".toString(),
"curl -sSL http://staging-artifacts.cloudfront.net/${version}/997908/maven/org/opensearch/dataprepper/data-prepper-api/${version}/data-prepper-api-${version}-sources.jar.sha256 -o org/opensearch/dataprepper/data-prepper-api/${version}/data-prepper-api-${version}-sources.jar.sha256".toString(),
"curl -sSL http://staging-artifacts.cloudfront.net/${version}/997908/maven/org/opensearch/dataprepper/data-prepper-api/${version}/data-prepper-api-${version}.module.sha512 -o org/opensearch/dataprepper/data-prepper-api/${version}/data-prepper-api-${version}.module.sha512".toString()
))
}
@Test
void 's3Upload uploads to the correct path'() {
runScript('jenkins/data-prepper/release-data-prepper-all-artifacts.jenkinsfile')
def actualS3Upload = helper.callStack.findAll { call ->
call.methodName == 's3Upload'
}.first()
assertThat(actualS3Upload, notNullValue())
assertThat(actualS3Upload.args[0].get('path'), equalTo("data-prepper/${version}/"))
}
def getCurlCommands() {
def shCurlCommands = helper.callStack.findAll { call ->
call.methodName == 'sh'
}.collect { call ->
callArgsToString(call)
}.findAll { curlCommand ->
curlCommand.contains('curl')
}
return shCurlCommands
}
}