forked from opensearch-project/opensearch-build-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestDownloadFromS3.groovy
74 lines (64 loc) · 2.37 KB
/
TestDownloadFromS3.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
/*
* Copyright OpenSearch Contributors
* 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.
*/
import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.MatcherAssert.assertThat
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
class TestDownloadFromS3 extends BuildPipelineTest {
@Before
void setUp() {
this.registerLibTester(new DownloadFromS3LibTester(
'tmp-role',
'role-credential-id',
'/download/path',
'dummy_bucket',
"/tmp"
))
this.registerLibTester(new DownloadFromS3LibTester(
'tmp-role',
'role-credential-id',
'/download/path',
'dummy_bucket',
"/tmp",
false,
'us-west-2'
))
super.setUp()
}
@Test
public void testDownloadFromS3() {
super.testPipeline('tests/jenkins/jobs/DownloadFromS3_Jenkinsfile')
}
@Test
void verify_default_args(){
runScript('tests/jenkins/jobs/DownloadFromS3_Jenkinsfile')
def aws = getMethodCall('withAWS')
assertThat(aws, hasItem('{role=tmp-role, roleAccount=AWS_ACCOUNT_NUMBER, duration=900, roleSessionName=jenkins-session, region=us-east-1}, groovy.lang.Closure'))
def download = getMethodCall('s3Download')
assertThat(download, hasItem('{file=/tmp, bucket=dummy_bucket, path=/download/path, force=false}'))
}
@Test
void verify_optional_args(){
runScript('tests/jenkins/jobs/DownloadFromS3_Jenkinsfile')
def aws = getMethodCall('withAWS')
assertThat(aws, hasItem('{role=tmp-role, roleAccount=AWS_ACCOUNT_NUMBER, duration=900, roleSessionName=jenkins-session, region=us-west-2}, groovy.lang.Closure'))
def download = getMethodCall('s3Download')
assertThat(download, hasItem('{file=/tmp, bucket=dummy_bucket, path=/download/path, force=true}'))
}
def getMethodCall(methodName) {
def shCommands = helper.callStack.findAll { call ->
call.methodName == methodName
}.collect { call ->
callArgsToString(call)
}
return shCommands
}
}