github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/DebugReportArchiveTest.groovy (about) 1 import org.junit.Before 2 import org.junit.Rule 3 import org.junit.Test 4 import org.junit.rules.RuleChain 5 import util.BasePiperTest 6 import util.JenkinsLoggingRule 7 import util.JenkinsReadYamlRule 8 import util.JenkinsStepRule 9 import util.JenkinsWriteFileRule 10 import util.Rules 11 12 import static org.hamcrest.Matchers.containsString 13 import static org.junit.Assert.assertThat 14 15 class DebugReportArchiveTest extends BasePiperTest { 16 17 private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) 18 private JenkinsStepRule stepRule = new JenkinsStepRule(this) 19 private JenkinsWriteFileRule writeFileRule = new JenkinsWriteFileRule(this) 20 21 @Rule 22 public RuleChain ruleChain = Rules 23 .getCommonRules(this) 24 .around(new JenkinsReadYamlRule(this)) 25 .around(loggingRule) 26 .around(writeFileRule) 27 .around(stepRule) 28 29 @Before 30 void init() { 31 helper.registerAllowedMethod("libraryResource", [String.class], { path -> 32 33 File resource = new File(new File('resources'), path) 34 if (resource.exists()) { 35 return resource.getText() 36 } 37 38 return '' 39 }) 40 } 41 42 @Test 43 void testDebugReportArchive() { 44 stepRule.step.debugReportArchive( 45 script: nullScript, 46 juStabUtils: utils, 47 stageName: 'test', 48 printToConsole: true 49 ) 50 51 String debugReportSnippet = 'The debug log is generated with each build and should be included in every support request' 52 53 assertThat(loggingRule.log, containsString('Successfully archived debug report')) 54 assertThat(loggingRule.log, containsString(debugReportSnippet)) 55 56 assertThat(writeFileRule.files.find({ it.toString().contains('debug_log') }) as String, containsString(debugReportSnippet)) 57 } 58 }