2018-02-07 14:17:33 +02:00
|
|
|
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
|
2018-03-05 10:04:53 +02:00
|
|
|
import util.MockHelper
|
2018-02-07 14:17:33 +02:00
|
|
|
import util.Rules
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals
|
2018-03-05 10:04:53 +02:00
|
|
|
import static org.junit.Assert.assertNull
|
2018-02-07 14:17:33 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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() {
|
2018-05-07 14:46:51 +02:00
|
|
|
jscr.setReturnValue('git rev-parse --is-inside-work-tree 1>/dev/null 2>&1', 0)
|
2018-03-05 10:04:53 +02:00
|
|
|
assertEquals('testCommitId', gitUtils.getGitCommitIdOrNull())
|
|
|
|
}
|
2018-02-07 14:17:33 +02:00
|
|
|
|
2018-03-05 10:04:53 +02:00
|
|
|
@Test
|
|
|
|
void testGetGitCommitIdNotAGitRepo() {
|
2018-05-07 14:46:51 +02:00
|
|
|
jscr.setReturnValue('git rev-parse --is-inside-work-tree 1>/dev/null 2>&1', 128)
|
2018-03-05 10:04:53 +02:00
|
|
|
assertNull(gitUtils.getGitCommitIdOrNull())
|
2018-02-07 14:17:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|