Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
  • Loading branch information
gaiksaya committed Feb 27, 2025
1 parent c33eafd commit a5d6f8a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
58 changes: 56 additions & 2 deletions tests/jenkins/TestCheckReleaseIssues.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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.containsString
import static org.hamcrest.CoreMatchers.not
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.MatcherAssert.assertThat

Expand Down Expand Up @@ -93,6 +93,60 @@ class TestCheckReleaseIssues extends BuildPipelineTest {
assertThat(getCommands('sh', 'workflow'), hasItem("{script=gh workflow run os-release-issues.yml -R opensearch-project/opensearch-build && gh workflow run osd-release-issues.yml -R opensearch-project/opensearch-build, returnStdout=true}"))
}

@Test
void testGHtriggerCallError() {
this.registerLibTester(new CheckReleaseIssuesLibTester('2.19.0', ['tests/data/opensearch-1.3.0.yml'], 'create'))
helper.addShMock("""gh workflow run os-release-issues.yml -R opensearch-project/opensearch-build && gh workflow run osd-release-issues.yml -R opensearch-project/opensearch-build""") { script ->
return [stdout: 'script returned exit code 1', exitValue: 1]
}
runScript('tests/jenkins/jobs/CheckReleaseIssues_Jenkinsfile')
assertThat(getCommands('error', 'GitHub'), hasItem("Error in triggering GitHub Actions workflows. Script returned error code: 1"))
}

@Test
void testCreateActionIsNotCalled() {
this.registerLibTester(new CheckReleaseIssuesLibTester('2.19.0', ['tests/data/opensearch-1.3.0.yml'], 'create'))
def response = '''
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 30,
"relation": "eq"
},
"max_score": null,
"hits": [
{
"_index": "opensearch_release_metrics",
"_id": "76527151-e5e4-35bf-9763-3617d2898b82",
"_score": null,
"_source": {
"release_issue_exists": true,
"release_owners": []
},
"sort": [
1740605121281
]
}
]
}
}
'''


helper.addShMock("""\n set -e\n set +x\n curl -s -XGET \"sample.url/opensearch_release_metrics/_search\" --aws-sigv4 \"aws:amz:us-east-1:es\" --user \"abc:xyz\" -H \"x-amz-security-token:sampleToken\" -H 'Content-Type: application/json' -d \"{\\"size\\":1,\\"_source\\":[\\"release_owners\\",\\"release_issue_exists\\"],\\"query\\":{\\"bool\\":{\\"filter\\":[{\\"match_phrase\\":{\\"version\\":\\"1.3.0\\"}},{\\"match_phrase\\":{\\"component.keyword\\":\\"OpenSearch\\"}}]}},\\"sort\\":[{\\"current_date\\":{\\"order\\":\\"desc\\"}}]}\" | jq '.'\n """) { script ->
return [stdout: response, exitValue: 0]
}
runScript('tests/jenkins/jobs/CheckReleaseIssues_Jenkinsfile')
assertThat(getCommands('sh', 'workflow'), not(hasItem("{script=gh workflow run os-release-issues.yml -R opensearch-project/opensearch-build && gh workflow run osd-release-issues.yml -R opensearch-project/opensearch-build, returnStdout=true}")))}

def getCommands(method, text) {
def shCommands = helper.callStack.findAll { call ->
call.methodName == method
Expand All @@ -103,4 +157,4 @@ class TestCheckReleaseIssues extends BuildPipelineTest {
}
return shCommands
}
}
}
2 changes: 1 addition & 1 deletion vars/checkReleaseIssues.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void call(Map args = [:]) {
returnStdout: true
)
} catch (Exception ex) {
error("Error in triggering create-release-issue GitHub workflow ${ex.getMessage()}")
error("Error in triggering GitHub Actions workflows. ${ex.getMessage()}")
}
}
}
Expand Down

0 comments on commit a5d6f8a

Please sign in to comment.