1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/test/groovy/com/sap/piper/GitUtilsTest.groovy
Florian Wilhelm ff46bb0f00 Make commit of new version optional in artifactSetVersion step (#112)
* Make commit of new version optional in `artifactSetVersion` step

You might not want to add a new commit for each version, when versions
are automatically created. This commit makes this feature optional, but
enabled by default to maintain API compatibility.

* Set `gitCommitId` if null

* Improve documentation of `commitVersion` parameter

* Allow to operate in a code checkout without `.git` directory
2018-03-05 09:04:53 +01:00

54 lines
1.5 KiB
Groovy

package com.sap.piper
import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.JenkinsShellCallRule
import util.MockHelper
import util.Rules
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNull
class GitUtilsTest extends BasePipelineTest {
JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
ExpectedException thrown = ExpectedException.none()
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this).around(jscr).around(thrown)
GitUtils gitUtils
@Before
void init() throws Exception {
gitUtils = new GitUtils()
prepareObjectInterceptors(gitUtils)
gitUtils.fileExists = MockHelper
jscr.setReturnValue('git rev-parse HEAD', 'testCommitId')
}
void prepareObjectInterceptors(object) {
object.metaClass.invokeMethod = helper.getMethodInterceptor()
object.metaClass.static.invokeMethod = helper.getMethodInterceptor()
object.metaClass.methodMissing = helper.getMethodMissingInterceptor()
}
@Test
void testGetGitCommitId() {
this.helper.registerAllowedMethod('fileExists', [String.class], {true})
assertEquals('testCommitId', gitUtils.getGitCommitIdOrNull())
}
@Test
void testGetGitCommitIdNotAGitRepo() {
this.helper.registerAllowedMethod('fileExists', [String.class], {false})
assertNull(gitUtils.getGitCommitIdOrNull())
}
}