forked from opensearch-project/opensearch-build-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestCreateReleaseTag.groovy
58 lines (48 loc) · 1.9 KB
/
TestCreateReleaseTag.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
/*
* 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 com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.MatcherAssert.assertThat
class TestCreateReleaseTag extends BuildPipelineTest {
@Before
void setUp() {
this.registerLibTester(new CreateReleaseTagLibTester('tests/data/opensearch-build-1.1.0.yml', '1.1.0'))
super.setUp()
super.testPipeline("tests/jenkins/jobs/CreateReleaseTag_Jenkinsfile")
}
@Test
void testCreateReleaseTag_verifyGitCommands() {
def gitCheckoutCommands = getCommandExecutions('checkout', 'GitSCM').findAll {
shCommand -> shCommand.contains('git')
}
def gitshellCommands = getCommandExecutions('sh', 'git').findAll {
shCommand -> shCommand.contains('git')
}
assertThat(gitCheckoutCommands, hasItem("{\$class=GitSCM, branches=[{name=3913d7097934cbfe1fdcf919347f22a597d00b76}], userRemoteConfigs=[{url=https://github.com/opensearch-project/common-utils.git}]}".toString()))
assertThat(gitshellCommands, hasItem("git tag 1.1.0".toString()))
assertThat(gitshellCommands, hasItem("git push https://[email protected]/opensearch-project/OpenSearch.git 1.1.0".toString()))
}
def getCommandExecutions(methodName, command=null) {
def shCommands = helper.callStack.findAll {
call ->
call.methodName == methodName
}.
collect {
call ->
callArgsToString(call)
}.findAll {
shCommand ->
shCommand.contains(command)
}
return shCommands
}
}