1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/test/groovy/JenkinsMaterializeLogTest.groovy
Florian Wilhelm 941eba0472
Fix Could not find matching constructor for: hudson.FilePath (#1134)
The constructor for hudson.FilePath does not take a file, but rather a
string containing the path to the file.
2020-02-03 12:28:16 +01:00

58 lines
1.9 KiB
Groovy

import hudson.FilePath
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.BasePiperTest
import util.JenkinsLoggingRule
import util.JenkinsReadYamlRule
import util.JenkinsStepRule
import util.JenkinsWriteFileRule
import util.Rules
import com.sap.piper.JenkinsUtils
class JenkinsMaterializeLogTest extends BasePiperTest {
private ExpectedException thrown = ExpectedException.none()
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
private JenkinsWriteFileRule writeFileRule = new JenkinsWriteFileRule(this)
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
class JenkinsUtilsMock extends JenkinsUtils {
def getInstance() {
def map = [getComputer:{return null}];
return map
}
}
@Rule
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(new JenkinsReadYamlRule(this))
.around(thrown)
.around(loggingRule)
.around(writeFileRule)
.around(stepRule)
@Test
void testMaterializeLog() {
def map = [script: nullScript, jenkinsUtilsStub: new JenkinsUtilsMock()]
def body = { name -> def msg = "hello " + name }
binding.setVariable('currentBuild', [result: 'UNSTABLE', rawBuild: [getLogInputStream: {return new StringBufferInputStream("this is the input")}]])
binding.setVariable('env', [NODE_NAME: 'anynode', WORKSPACE: '.'])
stepRule.step.jenkinsMaterializeLog(map, body)
}
@Test
void getFilePath_returnsValidFilePathObject() {
final fileName = "mylog.txt"
def expected = new FilePath(null, fileName)
def script = loadScript("vars/jenkinsMaterializeLog.groovy")
binding.setVariable('env', [NODE_NAME: 'anynode', WORKSPACE: '.'])
def filePath = script.invokeMethod("getFilePath", fileName, new JenkinsUtilsMock())
Assert.assertEquals(expected, filePath)
}
}