|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * The OpenSearch Contributors require contributions made to |
| 6 | + * this file be licensed under the Apache-2.0 license or a |
| 7 | + * compatible open source license. |
| 8 | + */ |
| 9 | + |
| 10 | +import jenkins.tests.BuildPipelineTest |
| 11 | +import org.junit.Before |
| 12 | +import org.junit.Test |
| 13 | + |
| 14 | +import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString |
| 15 | +import static org.hamcrest.CoreMatchers.hasItem |
| 16 | +import static org.hamcrest.MatcherAssert.assertThat |
| 17 | + |
| 18 | +import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library |
| 19 | +import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource |
| 20 | + |
| 21 | +class TestReleaseChores extends BuildPipelineTest { |
| 22 | + |
| 23 | + @Override |
| 24 | + @Before |
| 25 | + void setUp() { |
| 26 | + helper.registerSharedLibrary( |
| 27 | + library().name('jenkins') |
| 28 | + .defaultVersion('8.2.0') |
| 29 | + .allowOverride(true) |
| 30 | + .implicit(true) |
| 31 | + .targetPath('vars') |
| 32 | + .retriever(gitSource('https://github.com/opensearch-project/opensearch-build-libraries.git')) |
| 33 | + .build() |
| 34 | + ) |
| 35 | + |
| 36 | + super.setUp() |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testVerifyParameters() { |
| 41 | + addParam('RELEASE_VERSION', '') |
| 42 | + addParam('RELEASE_CHORE', 'add_rc_details_comment') |
| 43 | + runScript('jenkins/release-workflows/release-chores.jenkinsfile') |
| 44 | + assertThat(getCommandExecutions('error', ''), hasItem('Required parameters are missing. Please provide the mandatory arguments RELEASE_VERSION and RELEASE_CHORE')) |
| 45 | + } |
| 46 | + |
| 47 | + def getCommandExecutions(methodName, command) { |
| 48 | + def shCommands = helper.callStack.findAll { |
| 49 | + call -> |
| 50 | + call.methodName == methodName |
| 51 | + }. |
| 52 | + collect { |
| 53 | + call -> |
| 54 | + callArgsToString(call) |
| 55 | + }.findAll { |
| 56 | + shCommand -> |
| 57 | + shCommand.contains(command) |
| 58 | + } |
| 59 | + return shCommands |
| 60 | + } |
| 61 | +} |
0 commit comments