2018-01-24 10:55:38 +02:00
|
|
|
#!groovy
|
2018-01-26 16:39:04 +02:00
|
|
|
import com.sap.piper.DefaultValueCache
|
2018-01-24 10:55:38 +02:00
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.RuleChain
|
2018-06-06 11:19:19 +02:00
|
|
|
import util.BasePiperTest
|
2018-01-24 10:55:38 +02:00
|
|
|
import util.JenkinsLoggingRule
|
2018-02-28 14:11:09 +02:00
|
|
|
import util.JenkinsStepRule
|
2018-01-26 15:55:15 +02:00
|
|
|
import util.Rules
|
2018-01-24 10:55:38 +02:00
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue
|
|
|
|
import static org.junit.Assert.assertEquals
|
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
class InfluxWriteDataTest extends BasePiperTest {
|
2018-02-28 14:11:09 +02:00
|
|
|
public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
|
|
|
|
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
2018-01-24 10:55:38 +02:00
|
|
|
|
2018-02-28 14:11:09 +02:00
|
|
|
@Rule
|
|
|
|
public RuleChain ruleChain = Rules
|
|
|
|
.getCommonRules(this)
|
|
|
|
.around(loggingRule)
|
|
|
|
.around(jsr)
|
2018-01-24 10:55:38 +02:00
|
|
|
|
|
|
|
Map fileMap = [:]
|
|
|
|
Map stepMap = [:]
|
|
|
|
String echoLog = ''
|
|
|
|
|
|
|
|
@Before
|
|
|
|
void init() throws Exception {
|
2018-01-26 16:39:04 +02:00
|
|
|
// Currently we have dependencies between the tests since
|
|
|
|
// DefaultValueCache is a singleton which keeps its status
|
|
|
|
// for all the tests. Depending on the test order we fail.
|
|
|
|
// As long as this status remains we need:
|
|
|
|
DefaultValueCache.reset()
|
2018-01-24 10:55:38 +02:00
|
|
|
//reset stepMap
|
|
|
|
stepMap = [:]
|
|
|
|
//reset fileMap
|
|
|
|
fileMap = [:]
|
|
|
|
|
|
|
|
helper.registerAllowedMethod('readYaml', [Map.class], { map ->
|
|
|
|
return [
|
|
|
|
general: [productiveBranch: 'develop'],
|
|
|
|
steps : [influxWriteData: [influxServer: 'testInflux']]
|
|
|
|
]
|
|
|
|
})
|
|
|
|
helper.registerAllowedMethod('writeFile', [Map.class],{m -> fileMap[m.file] = m.text})
|
|
|
|
helper.registerAllowedMethod('step', [Map.class],{m -> stepMap = m})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testInfluxWriteDataWithDefault() throws Exception {
|
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
nullScript.commonPipelineEnvironment.setArtifactVersion('1.2.3')
|
|
|
|
jsr.step.call(script: nullScript)
|
2018-01-24 10:55:38 +02:00
|
|
|
|
|
|
|
assertTrue(loggingRule.log.contains('Artifact version: 1.2.3'))
|
|
|
|
|
|
|
|
assertEquals('testInflux', stepMap.selectedTarget)
|
|
|
|
assertEquals(null, stepMap.customPrefix)
|
|
|
|
assertEquals([:], stepMap.customData)
|
2018-05-30 12:58:52 +02:00
|
|
|
assertEquals([pipeline_data: [:], step_data: [:]], stepMap.customDataMap)
|
2018-01-24 10:55:38 +02:00
|
|
|
|
|
|
|
assertTrue(fileMap.containsKey('jenkins_data.json'))
|
|
|
|
assertTrue(fileMap.containsKey('pipeline_data.json'))
|
|
|
|
|
|
|
|
assertJobStatusSuccess()
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testInfluxWriteDataNoInflux() throws Exception {
|
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
nullScript.commonPipelineEnvironment.setArtifactVersion('1.2.3')
|
|
|
|
jsr.step.call(script: nullScript, influxServer: '')
|
2018-01-24 10:55:38 +02:00
|
|
|
|
|
|
|
assertEquals(0, stepMap.size())
|
|
|
|
|
|
|
|
assertTrue(fileMap.containsKey('jenkins_data.json'))
|
|
|
|
assertTrue(fileMap.containsKey('pipeline_data.json'))
|
|
|
|
|
|
|
|
assertJobStatusSuccess()
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testInfluxWriteDataNoArtifactVersion() throws Exception {
|
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
jsr.step.call(script: nullScript)
|
2018-01-24 10:55:38 +02:00
|
|
|
|
|
|
|
assertEquals(0, stepMap.size())
|
|
|
|
assertEquals(0, fileMap.size())
|
|
|
|
|
|
|
|
assertTrue(loggingRule.log.contains('no artifact version available -> exiting writeInflux without writing data'))
|
|
|
|
|
|
|
|
assertJobStatusSuccess()
|
|
|
|
}
|
|
|
|
}
|