forked from opensearch-project/opensearch-build-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestGetCompareBenchmarkIds.groovy
72 lines (63 loc) · 2.38 KB
/
TestGetCompareBenchmarkIds.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
/*
* 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.hamcrest.CoreMatchers
import org.hamcrest.Matcher
import org.junit.Before
import org.junit.Test
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.containsString
import static org.hamcrest.CoreMatchers.equalTo
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.CoreMatchers.hasItems
import static org.hamcrest.MatcherAssert.assertThat
import static org.hamcrest.MatcherAssert.assertTrue
class TestGetCompareBenchmarkIds extends BuildPipelineTest {
@Before
void setUp() {
this.registerLibTester(new GetCompareBenchmarkIdsLibTester(
'test-baseline-config',
'3.0.0',
'big5',
'12345'))
super.setUp()
}
@Test
public void testGetCompareBenchmarkIds_default() {
super.testPipeline("tests/jenkins/jobs/CompareBenchmarkRun_Jenkinsfile")
}
@Test
void testCallCurlCommands() {
runScript("tests/jenkins/jobs/CompareBenchmarkRun_Jenkinsfile")
def curlCommands = getCommandExecutions('sh', 'curl').findAll {
shCommand -> shCommand.contains('curl')
}
assertThat(curlCommands.size(), equalTo(2))
def baselineCurlCommand = curlCommands[0]
assertThat(baselineCurlCommand, containsString('"user-tags.cluster-config": "test-baseline-config"'))
assertThat(baselineCurlCommand, containsString('"workload": "big5"'))
assertThat(baselineCurlCommand, containsString('"distribution-version": "3.0.0"'))
def contenderCurlCommand = curlCommands[1]
assertThat(contenderCurlCommand, containsString('"user-tags.pull_request_number": "12345"'))
}
def getCommandExecutions(methodName, command) {
def shCommands = helper.callStack.findAll {
call ->
call.methodName == methodName
}.
collect {
call ->
callArgsToString(call)
}.findAll {
shCommand ->
shCommand.contains(command)
}
return shCommands
}
}