forked from opensearch-project/opensearch-build-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestPublishToNuget.groovy
81 lines (71 loc) · 4.71 KB
/
TestPublishToNuget.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
/*
* 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.
*/
package jenkins.tests
import jenkins.tests.BuildPipelineTest
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.CoreMatchers.hasItems
import static org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Test
class TestPublishToNuget extends BuildPipelineTest {
@Override
@Before
void setUp() {
this.registerLibTester(new PublishToNugetLibTester(
'https://github.com/opensearch-project/opensearch-net',
'1.2.0',
'net-api-key',
'test-solution-file.sln'))
super.setUp()
}
@Test
public void test() {
super.testPipeline("tests/jenkins/jobs/PublishToNuget_Jenkinsfile")
}
@Test
void verify_build_command(){
runScript('tests/jenkins/jobs/PublishToNuget_Jenkinsfile')
def buildCommand = getShellCommands('dotnet build')
assertThat(buildCommand, hasItem('\n dotnet build /tmp/workspace/test-solution-file.sln --configuration Release\n find src/OpenSearch.*/bin/Release/*/*.dll -type f -regextype posix-extended -regex \"src/([^/]+)/bin/Release/[^/]+/\\1\\.dll\">/tmp/workspace/dlls.txt\n '))
}
@Test
void verify_pack_command(){
runScript('tests/jenkins/jobs/PublishToNuget_Jenkinsfile')
def packCommand = getShellCommands('pack')
assertThat(packCommand, hasItem('\n dotnet pack /tmp/workspace/test-solution-file.sln --configuration Release --no-build\n find src -name OpenSearch*.nupkg > /tmp/workspace/nupkg.txt\n '))
}
@Test
void verify_signer_call(){
runScript('tests/jenkins/jobs/PublishToNuget_Jenkinsfile')
def signcommand = getShellCommands('sign.sh')
assertThat(signcommand, hasItems('#!/bin/bash\n set +x\n export ROLE=SIGNER_WINDOWS_ROLE\n export EXTERNAL_ID=SIGNER_WINDOWS_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_WINDOWS_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_WINDOWS_SIGNED_BUCKET\n export PROFILE_IDENTIFIER=SIGNER_WINDOWS_PROFILE_IDENTIFIER\n export PLATFORM_IDENTIFIER=SIGNER_WINDOWS_PLATFORM_IDENTIFIER\n\n /tmp/workspace/opensearch-build/sign.sh /tmp/workspace/one.dll --platform windows --overwrite \n ',
'#!/bin/bash\n set +x\n export ROLE=SIGNER_WINDOWS_ROLE\n export EXTERNAL_ID=SIGNER_WINDOWS_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_WINDOWS_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_WINDOWS_SIGNED_BUCKET\n export PROFILE_IDENTIFIER=SIGNER_WINDOWS_PROFILE_IDENTIFIER\n export PLATFORM_IDENTIFIER=SIGNER_WINDOWS_PLATFORM_IDENTIFIER\n\n /tmp/workspace/opensearch-build/sign.sh /tmp/workspace/two.dll --platform windows --overwrite \n ',
'#!/bin/bash\n set +x\n export ROLE=SIGNER_WINDOWS_ROLE\n export EXTERNAL_ID=SIGNER_WINDOWS_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_WINDOWS_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_WINDOWS_SIGNED_BUCKET\n export PROFILE_IDENTIFIER=SIGNER_WINDOWS_PROFILE_IDENTIFIER\n export PLATFORM_IDENTIFIER=SIGNER_WINDOWS_PLATFORM_IDENTIFIER\n\n /tmp/workspace/opensearch-build/sign.sh /tmp/workspace/three.dll --platform windows --overwrite \n '))
}
@Test
void verify_push_command(){
runScript('tests/jenkins/jobs/PublishToNuget_Jenkinsfile')
def pushCommand = getShellCommands('push')
assertThat(pushCommand, hasItems(
'dotnet nuget push /tmp/workspace/src/net/one.nupkg --api-key API_KEY --source https://api.nuget.org/v3/index.json',
'dotnet nuget push /tmp/workspace/src/net/two.nupkg --api-key API_KEY --source https://api.nuget.org/v3/index.json',
'dotnet nuget push /tmp/workspace/src/net/three.nupkg --api-key API_KEY --source https://api.nuget.org/v3/index.json'))
}
def getShellCommands(searchString) {
def shCommands = helper.callStack.findAll { call ->
call.methodName == 'sh'
}.collect { call ->
callArgsToString(call)
}.findAll { command ->
command.contains(searchString)
}
return shCommands
}
}