-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Prudhvi Godithi <[email protected]>
- Loading branch information
1 parent
8776b89
commit f479255
Showing
22 changed files
with
437 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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 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 TestCloseBuildSuccessGithubIssue extends BuildPipelineTest { | ||
|
||
@Override | ||
@Before | ||
void setUp() { | ||
this.registerLibTester(new CloseBuildSuccessGithubIssueLibTester(['Build successful OpenSearch'])) | ||
super.setUp() | ||
} | ||
|
||
|
||
@Test | ||
public void testExistingGithubIssue() { | ||
super.testPipeline('tests/jenkins/jobs/CloseBuildSuccessGithubIssue_Jenkinsfile') | ||
assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/OpenSearch.git -S \"[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0 in:title\" --label autocut,v2.0.0 --json number --jq '.[0].number', returnStdout=true}")) | ||
assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue close bbb\nccc -R opensearch-project/OpenSearch --comment \"Closing the issue as the distribution build for OpenSearch has passed for version: **2.0.0**.\n Please see build log at www.example.com/jobs/test/123/consoleFull\", returnStdout=true}")) | ||
} | ||
|
||
def getCommands(method, text) { | ||
def shCommands = helper.callStack.findAll { call -> | ||
call.methodName == method | ||
}.collect { call -> | ||
callArgsToString(call) | ||
}.findAll { command -> | ||
command.contains(text) | ||
} | ||
return shCommands | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 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 TestCloseGithubIssue extends BuildPipelineTest { | ||
|
||
@Override | ||
@Before | ||
void setUp() { | ||
super.setUp() | ||
} | ||
|
||
|
||
@Test | ||
void testCloseExistingGithubIssue() { | ||
this.registerLibTester(new CloseGithubIssueLibTester( | ||
'https://github.com/opensearch-project/opensearch-build', | ||
'Test GH issue title', | ||
'Test GH issue close comment', | ||
'label101', | ||
)) | ||
super.testPipeline('tests/jenkins/jobs/CloseGithubIssue_JenkinsFile') | ||
assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S \"Test GH issue title in:title\" --label label101 --json number --jq '.[0].number', returnStdout=true}")) | ||
assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue close bbb\nccc -R opensearch-project/opensearch-build --comment \"Test GH issue close comment\", returnStdout=true}")) | ||
} | ||
|
||
def getCommands(method, text) { | ||
def shCommands = helper.callStack.findAll { call -> | ||
call.methodName == method | ||
}.collect { call -> | ||
callArgsToString(call) | ||
}.findAll { command -> | ||
command.contains(text) | ||
} | ||
return shCommands | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BuildMessage_Jenkinsfile.run() | ||
BuildMessage_Jenkinsfile.pipeline(groovy.lang.Closure) | ||
BuildMessage_Jenkinsfile.echo(Executing on agent [label:none]) | ||
BuildMessage_Jenkinsfile.stage(notify, groovy.lang.Closure) | ||
BuildMessage_Jenkinsfile.script(groovy.lang.Closure) | ||
BuildMessage_Jenkinsfile.buildMessage({search=pass}) |
24 changes: 24 additions & 0 deletions
24
tests/jenkins/jobs/CloseBuildSuccessGithubIssue_Jenkinsfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
pipeline { | ||
agent none | ||
stages { | ||
stage('notify') { | ||
steps { | ||
script { | ||
closeBuildSuccessGithubIssue( | ||
message: ["Build successful OpenSearch"], | ||
inputManifestPath: 'tests/data/opensearch-2.0.0.yml' | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/jenkins/jobs/CloseBuildSuccessGithubIssue_Jenkinsfile.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CloseBuildSuccessGithubIssue_Jenkinsfile.run() | ||
CloseBuildSuccessGithubIssue_Jenkinsfile.pipeline(groovy.lang.Closure) | ||
CloseBuildSuccessGithubIssue_Jenkinsfile.echo(Executing on agent [label:none]) | ||
CloseBuildSuccessGithubIssue_Jenkinsfile.stage(notify, groovy.lang.Closure) | ||
CloseBuildSuccessGithubIssue_Jenkinsfile.script(groovy.lang.Closure) | ||
CloseBuildSuccessGithubIssue_Jenkinsfile.closeBuildSuccessGithubIssue({message=[Build successful OpenSearch], inputManifestPath=tests/data/opensearch-2.0.0.yml}) | ||
closeBuildSuccessGithubIssue.legacySCM(groovy.lang.Closure) | ||
closeBuildSuccessGithubIssue.library({identifier=jenkins@main, retriever=null}) | ||
closeBuildSuccessGithubIssue.readYaml({file=tests/data/opensearch-2.0.0.yml}) | ||
closeBuildSuccessGithubIssue.closeGithubIssue({repoUrl=https://github.com/opensearch-project/OpenSearch.git, issueTitle=[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0, closeComment=Closing the issue as the distribution build for OpenSearch has passed for version: **2.0.0**. | ||
Please see build log at www.example.com/jobs/test/123/consoleFull, label=autocut,v2.0.0}) | ||
closeGithubIssue.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER}) | ||
closeGithubIssue.withCredentials([[GITHUB_USER, GITHUB_TOKEN]], groovy.lang.Closure) | ||
closeGithubIssue.sh({script=gh issue list --repo https://github.com/opensearch-project/OpenSearch.git -S "[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0 in:title" --label autocut,v2.0.0 --json number --jq '.[0].number', returnStdout=true}) | ||
closeGithubIssue.sh({script=gh issue close bbb | ||
ccc -R opensearch-project/OpenSearch --comment "Closing the issue as the distribution build for OpenSearch has passed for version: **2.0.0**. | ||
Please see build log at www.example.com/jobs/test/123/consoleFull", returnStdout=true}) | ||
closeBuildSuccessGithubIssue.sleep({time=3, unit=SECONDS}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CloseGithubIssue_JenkinsFile.run() | ||
CloseGithubIssue_JenkinsFile.pipeline(groovy.lang.Closure) | ||
CloseGithubIssue_JenkinsFile.echo(Executing on agent [label:none]) | ||
CloseGithubIssue_JenkinsFile.stage(closeGithubIssue, groovy.lang.Closure) | ||
CloseGithubIssue_JenkinsFile.script(groovy.lang.Closure) | ||
CloseGithubIssue_JenkinsFile.closeGithubIssue({repoUrl=https://github.com/opensearch-project/opensearch-build, issueTitle=Test GH issue title, closeComment=Test GH issue close comment, label=label101}) | ||
closeGithubIssue.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER}) | ||
closeGithubIssue.withCredentials([[GITHUB_USER, GITHUB_TOKEN]], groovy.lang.Closure) | ||
closeGithubIssue.sh({script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S "Test GH issue title in:title" --label label101 --json number --jq '.[0].number', returnStdout=true}) | ||
closeGithubIssue.sh({script=gh issue close bbb | ||
ccc -R opensearch-project/opensearch-build --comment "Test GH issue close comment", returnStdout=true}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
pipeline { | ||
agent none | ||
stages { | ||
stage('closeGithubIssue') { | ||
steps { | ||
script { | ||
closeGithubIssue( | ||
repoUrl: 'https://github.com/opensearch-project/opensearch-build', | ||
issueTitle: 'Test GH issue title', | ||
closeComment: 'Test GH issue close comment', | ||
label: 'label101' | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
tests/jenkins/lib-testers/BuildFailureMessageLibTester.groovy
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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 static org.hamcrest.CoreMatchers.notNullValue | ||
import static org.hamcrest.CoreMatchers.nullValue | ||
import static org.hamcrest.MatcherAssert.assertThat | ||
|
||
class BuildMessageLibTester extends LibFunctionTester { | ||
|
||
private String search | ||
|
||
public BuildMessageLibTester(search) { | ||
this.search = search | ||
} | ||
|
||
|
||
void parameterInvariantsAssertions(call) { | ||
assertThat(call.args.search.first(), notNullValue()) | ||
} | ||
|
||
boolean expectedParametersMatcher(call) { | ||
return call.args.search.first().toString().equals(this.search) | ||
} | ||
|
||
String libFunctionName() { | ||
return 'buildMessage' | ||
} | ||
|
||
void configure(helper, binding){ | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
tests/jenkins/lib-testers/CloseBuildSuccessGithubIssueLibTester.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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 static org.hamcrest.CoreMatchers.notNullValue | ||
import static org.hamcrest.CoreMatchers.nullValue | ||
import static org.hamcrest.MatcherAssert.assertThat | ||
|
||
class CloseBuildSuccessGithubIssueLibTester extends LibFunctionTester{ | ||
private List<String> message | ||
|
||
public CloseBuildSuccessGithubIssueLibTester(message){ | ||
this.message = message | ||
} | ||
|
||
@Override | ||
String libFunctionName() { | ||
return 'closeBuildSuccessGithubIssue' | ||
} | ||
|
||
@Override | ||
void parameterInvariantsAssertions(Object call) { | ||
assertThat(call.args.message.first(), notNullValue()) | ||
} | ||
|
||
@Override | ||
boolean expectedParametersMatcher(Object call) { | ||
return call.args.message.first().equals(this.message) | ||
} | ||
|
||
@Override | ||
void configure(Object helper, Object binding) { | ||
helper.registerAllowedMethod('withCredentials', [Map]) | ||
helper.registerAllowedMethod('sleep', [Map]) | ||
binding.setVariable('BUILD_URL', 'www.example.com/jobs/test/123/') | ||
} | ||
} |
Oops, something went wrong.