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
Oliver Nocon f8e5733486 speed up tests
* use new base class for testing
* initialize jenkins unit test framework only once for all test classes
* minor test cleanups
2018-06-06 11:19:19 +02:00

41 lines
1.1 KiB
Groovy

package com.sap.piper
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.BasePiperTest
import util.JenkinsShellCallRule
import util.Rules
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNull
class GitUtilsTest extends BasePiperTest {
JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
ExpectedException thrown = ExpectedException.none()
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this).around(jscr).around(thrown)
@Before
void init() throws Exception {
jscr.setReturnValue('git rev-parse HEAD', 'testCommitId')
}
@Test
void testGetGitCommitId() {
jscr.setReturnValue('git rev-parse --is-inside-work-tree 1>/dev/null 2>&1', 0)
assertEquals('testCommitId', gitUtils.getGitCommitIdOrNull())
}
@Test
void testGetGitCommitIdNotAGitRepo() {
jscr.setReturnValue('git rev-parse --is-inside-work-tree 1>/dev/null 2>&1', 128)
assertNull(gitUtils.getGitCommitIdOrNull())
}
}