mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-30 05:59:39 +02:00
5bf7cda940
* add new step for notification publication * add test cases * add helper method * correct import * Update pom.xml * add step to post section * add step piperPublishNotifications * move step to end of pipeline to gather all findings * use handlePipelineStepErrors step * use commonPipelineEnvironment * correct reporting * add configuration * fix typos * fix rule setup * remove test scope * add method to fetch full build log * add methods for warnings-ng parser creation * remove warnings plugin coding * add default parser settings * change parameter handling for parser creation * adapt step * fix parser creation * use ParserConfig.contains * use correct parameter name * correct parser regex * change issue creation * use classloader * fix typo * Revert "fix typo" This reverts commit 446a201ae44ae0bf6bcfedd17e583183ceaabfaa. * Revert "use classloader" This reverts commit a89648703239f8cf3da465bfa570500608dc14f2. * rename step to piperPublishWarnings * extract recordIssuesSettings to defaults * make addWarningsNGParser non-static * remove node * adjust test case * add docs * rename log file * fix tests * fix typos * rename parameter * add import for IOUtils * check plugin activation * add comment for class loader usage
86 lines
3.1 KiB
Groovy
86 lines
3.1 KiB
Groovy
#!groovy
|
|
package steps
|
|
|
|
import com.sap.piper.JenkinsUtils
|
|
|
|
import static org.hamcrest.Matchers.allOf
|
|
import static org.hamcrest.Matchers.any
|
|
import static org.hamcrest.Matchers.containsString
|
|
import static org.hamcrest.Matchers.hasItem
|
|
import static org.hamcrest.Matchers.hasEntry
|
|
import static org.hamcrest.Matchers.hasKey
|
|
|
|
import org.junit.Before
|
|
import org.junit.Rule
|
|
import org.junit.Test
|
|
import org.junit.rules.RuleChain
|
|
import static org.junit.Assert.assertThat
|
|
|
|
import util.BasePiperTest
|
|
import util.Rules
|
|
import util.JenkinsLoggingRule
|
|
import util.JenkinsReadYamlRule
|
|
import util.JenkinsStepRule
|
|
import util.JenkinsShellCallRule
|
|
|
|
import static com.lesfurets.jenkins.unit.MethodSignature.method
|
|
|
|
class PiperPublishWarningsTest extends BasePiperTest {
|
|
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
|
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
|
|
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
|
|
|
|
def warningsParserSettings
|
|
def groovyScriptParserSettings
|
|
def warningsPluginOptions
|
|
|
|
@Rule
|
|
public RuleChain ruleChain = Rules
|
|
.getCommonRules(this)
|
|
.around(new JenkinsReadYamlRule(this))
|
|
.around(loggingRule)
|
|
.around(shellRule)
|
|
.around(stepRule)
|
|
|
|
@Before
|
|
void init() throws Exception {
|
|
warningsParserSettings = [:]
|
|
groovyScriptParserSettings = [:]
|
|
warningsPluginOptions = [:]
|
|
|
|
// add handler for generic step call
|
|
helper.registerAllowedMethod("writeFile", [Map.class], null)
|
|
helper.registerAllowedMethod("recordIssues", [Map.class], {
|
|
parameters -> warningsPluginOptions = parameters
|
|
})
|
|
helper.registerAllowedMethod("groovyScript", [Map.class], {
|
|
parameters -> groovyScriptParserSettings = parameters
|
|
})
|
|
JenkinsUtils.metaClass.addWarningsNGParser = { String s1, String s2, String s3, String s4 ->
|
|
warningsParserSettings = [id: s1, name: s2, regex: s3, script: s4]
|
|
return true
|
|
}
|
|
JenkinsUtils.metaClass.static.getFullBuildLog = { def currentBuild -> return ""}
|
|
JenkinsUtils.metaClass.static.isPluginActive = { id -> return true}
|
|
}
|
|
|
|
@Test
|
|
void testPublishWarnings() throws Exception {
|
|
stepRule.step.piperPublishWarnings(script: nullScript)
|
|
// asserts
|
|
assertThat(loggingRule.log, containsString('[piperPublishWarnings] Added warnings-ng plugin parser \'Piper\' configuration.'))
|
|
assertThat(warningsParserSettings, hasEntry('id', 'piper'))
|
|
assertThat(warningsParserSettings, hasEntry('name', 'Piper'))
|
|
assertThat(warningsParserSettings, hasEntry('regex', '\\[(INFO|WARNING|ERROR)\\] (.*) \\(([^) ]*)\\/([^) ]*)\\)'))
|
|
assertThat(warningsParserSettings, hasKey('script'))
|
|
assertThat(warningsPluginOptions, allOf(
|
|
hasEntry('enabledForFailure', true),
|
|
hasEntry('blameDisabled', true)
|
|
))
|
|
assertThat(warningsPluginOptions, hasKey('tools'))
|
|
|
|
assertThat(groovyScriptParserSettings, hasEntry('parserId', 'piper'))
|
|
assertThat(groovyScriptParserSettings, hasEntry('pattern', 'build.log'))
|
|
}
|
|
}
|