forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestPromoteArtifacts.groovy
184 lines (158 loc) · 7.91 KB
/
TestPromoteArtifacts.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* 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 java.nio.file.*
class TestPromoteArtifacts extends BuildPipelineTest {
private Path targetOpenSearchTar;
private Path targetOpenSearchDashboardsTar;
private Path targetOpenSearchTarQualifier;
private Path targetOpenSearchDashboardsTarQualifier;
private Path targetOpenSearchRpm;
private Path targetOpenSearchDashboardsRpm;
private Path targetOpenSearchRpmQualifier;
private Path targetOpenSearchDashboardsRpmQualifier;
@Override
@Before
void setUp() {
super.setUp()
binding.setVariable('PUBLIC_ARTIFACT_URL', 'https://ci.opensearch.org/dbc')
binding.setVariable('DISTRIBUTION_JOB_NAME', 'vars-build')
binding.setVariable('STAGE_NAME', 'stage')
binding.setVariable('BUILD_URL', 'http://jenkins.us-east-1.elb.amazonaws.com/job/vars/42')
binding.setVariable('DISTRIBUTION_BUILD_NUMBER', '33')
binding.setVariable('DISTRIBUTION_PLATFORM', 'linux')
binding.setVariable('DISTRIBUTION_ARCHITECTURE', 'x64')
binding.setVariable('WORKSPACE', 'tests/jenkins')
binding.setVariable('GITHUB_BOT_TOKEN_NAME', 'github_bot_token_name')
def configs = ["role": "dummy_role",
"external_id": "dummy_ID",
"unsigned_bucket": "dummy_unsigned_bucket",
"signed_bucket": "dummy_signed_bucket"]
binding.setVariable('configs', configs)
helper.registerAllowedMethod("readJSON", [Map.class], {c -> configs})
helper.registerAllowedMethod("git", [Map])
helper.registerAllowedMethod("s3Download", [Map])
helper.registerAllowedMethod("s3Upload", [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)
})
helper.registerAllowedMethod('getPath', { args ->
return "tests/jenkins/file/found.zip"
})
helper.registerAllowedMethod('findFiles', [Map], { args ->
return [{}]
})
helper.addFileExistsMock('tests/jenkins/artifacts/tar/vars-build/1.3.0/33/linux/x64/tar/builds/opensearch/core-plugins', true)
helper.addShMock('find tests/jenkins/artifacts/tar/vars-build/1.3.0/33/linux/x64/tar/builds/opensearch/core-plugins -type f') { script ->
return [stdout: "tar_dummy_artifact_1.3.0.tar.gz zip_dummy_artifact_1.3.0.zip dummy_artifact_1.3.0.dummy", exitValue: 0]
}
helper.addShMock('sha512sum tar_dummy_artifact_1.3.0.tar.gz') { script ->
return [stdout: "shaHashDummy_tar_dummy_artifact_1.3.0.tar.gz tests/jenkins/artifacts/tar/vars-build/1.3.0/33/linux/x64/tar/builds/opensearch/core-plugins/tar_dummy_artifact_1.3.0.tar.gz", exitValue: 0]
}
helper.addShMock('sha512sum zip_dummy_artifact_1.3.0.zip') { script ->
return [stdout: "shaHashDummy_zip_dummy_artifact_1.3.0.zip tests/jenkins/artifacts/tar/vars-build/1.3.0/33/linux/x64/tar/builds/opensearch/core-plugins/zip_dummy_artifact_1.3.0.zip", exitValue: 0]
}
helper.addShMock('basename tests/jenkins/artifacts/tar/vars-build/1.3.0/33/linux/x64/tar/builds/opensearch/core-plugins/tar_dummy_artifact_1.3.0.tar.gz') { script ->
return [stdout: "tar_dummy_artifact_1.3.0.tar.gz", exitValue: 0]
}
helper.addShMock('basename tests/jenkins/artifacts/tar/vars-build/1.3.0/33/linux/x64/tar/builds/opensearch/core-plugins/zip_dummy_artifact_1.3.0.zip') { script ->
return [stdout: "zip_dummy_artifact_1.3.0.zip", exitValue: 0]
}
targetOpenSearchTar = copy(
"tests/data/opensearch-build-1.3.0.yml",
"tests/jenkins/artifacts/tar/vars-build/1.3.0/33/linux/x64/tar/builds/opensearch/manifest.yml"
);
targetOpenSearchDashboardsTar = copy(
"tests/data/opensearch-dashboards-build-1.3.0.yml",
"tests/jenkins/artifacts/tar/vars-build/1.3.0/33/linux/x64/tar/builds/opensearch-dashboards/manifest.yml"
);
targetOpenSearchTarQualifier = copy(
"tests/data/opensearch-build-2.0.0-rc1.yml",
"tests/jenkins/artifacts/tar/vars-build/2.0.0-rc1/33/linux/x64/tar/builds/opensearch/manifest.yml"
);
targetOpenSearchDashboardsTarQualifier = copy(
"tests/data/opensearch-dashboards-build-2.0.0-rc1.yml",
"tests/jenkins/artifacts/tar/vars-build/2.0.0-rc1/33/linux/x64/tar/builds/opensearch-dashboards/manifest.yml"
);
targetOpenSearchRpm = copy(
"tests/data/opensearch-build-1.3.0-rpm.yml",
"tests/jenkins/artifacts/rpm/vars-build/1.3.0/33/linux/x64/rpm/builds/opensearch/manifest.yml"
);
targetOpenSearchDashboardsRpm = copy(
"tests/data/opensearch-dashboards-build-1.3.0-rpm.yml",
"tests/jenkins/artifacts/rpm/vars-build/1.3.0/33/linux/x64/rpm/builds/opensearch-dashboards/manifest.yml"
);
targetOpenSearchRpmQualifier = copy(
"tests/data/opensearch-build-2.0.0-rc1-rpm.yml",
"tests/jenkins/artifacts/rpm/vars-build/2.0.0-rc1/33/linux/x64/rpm/builds/opensearch/manifest.yml"
);
targetOpenSearchDashboardsRpmQualifier = copy(
"tests/data/opensearch-dashboards-build-2.0.0-rc1-rpm.yml",
"tests/jenkins/artifacts/rpm/vars-build/2.0.0-rc1/33/linux/x64/rpm/builds/opensearch-dashboards/manifest.yml"
);
}
private Path copy(String sourcePath, String targetPath){
Path source = Path.of(sourcePath);
Path target = Path.of(targetPath);
Files.createDirectories(target.getParent());
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
return target;
}
@After
void after() {
super.setUp()
// Test file needs to be cleaned up
Files.delete(targetOpenSearchTar)
Files.delete(targetOpenSearchDashboardsTar)
Files.delete(targetOpenSearchTarQualifier)
Files.delete(targetOpenSearchDashboardsTarQualifier)
Files.delete(targetOpenSearchRpm)
Files.delete(targetOpenSearchDashboardsRpm)
Files.delete(targetOpenSearchRpmQualifier)
Files.delete(targetOpenSearchDashboardsRpmQualifier)
}
@Test
public void testDefault() {
super.testPipeline("tests/jenkins/jobs/PromoteArtifacts_Jenkinsfile")
}
@Test
public void testDefault_OpenSearch_Dashboards() {
super.testPipeline("tests/jenkins/jobs/PromoteArtifacts_OpenSearch_Dashboards_Jenkinsfile")
}
@Test
public void testDefaultQualifier() {
super.testPipeline("tests/jenkins/jobs/PromoteArtifactsQualifier_Jenkinsfile")
}
@Test
public void testDefaultQualifier_OpenSearch_Dashboards() {
super.testPipeline("tests/jenkins/jobs/PromoteArtifactsQualifier_OpenSearch_Dashboards_Jenkinsfile")
}
@Test
public void testWithActions() {
super.testPipeline("tests/jenkins/jobs/PromoteArtifacts_actions_Jenkinsfile")
}
@Test
public void testWithActions_OpenSearch_Dashboards() {
super.testPipeline("tests/jenkins/jobs/PromoteArtifacts_actions_OpenSearch_Dashboards_Jenkinsfile")
}
@Test
public void testWithActionsQualifier() {
super.testPipeline("tests/jenkins/jobs/PromoteArtifactsQualifier_actions_Jenkinsfile")
}
@Test
public void testWithActionsQualifier_OpenSearch_Dashboards() {
super.testPipeline("tests/jenkins/jobs/PromoteArtifactsQualifier_actions_OpenSearch_Dashboards_Jenkinsfile")
}
}