| |
@@ -0,0 +1,74 @@
|
| |
+ import org.junit.*
|
| |
+ import com.lesfurets.jenkins.unit.cps.BasePipelineTestCPS
|
| |
+ import static groovy.test.GroovyAssert.*
|
| |
+
|
| |
+ class PipelineaasTest extends BasePipelineTestCPS implements Serializable {
|
| |
+ def pipelineaas
|
| |
+
|
| |
+ @Before
|
| |
+ void setUp() {
|
| |
+ super.setUp()
|
| |
+ pipelineaas = loadScript('vars/pipelineaas.groovy')
|
| |
+ helper.registerAllowedMethod('withCluster', [Closure.class], null)
|
| |
+ helper.registerAllowedMethod('withProject', [String.class, Closure.class], null)
|
| |
+ // for getVars
|
| |
+ helper.registerAllowedMethod('selector', [String.class, String.class], { new SelectorMock(test: this, objs: [
|
| |
+ [data: ['PIPELINE_NAMESPACE': "testnamespace"]]
|
| |
+ ])})
|
| |
+ // for destroy
|
| |
+ helper.registerAllowedMethod('selector', [String.class, Map.class], { new SelectorMock(test: this)})
|
| |
+
|
| |
+ binding.setVariable('script', pipelineaas)
|
| |
+ binding.setVariable('openshift', pipelineaas)
|
| |
+ }
|
| |
+
|
| |
+ @Test
|
| |
+ void testGetVars() {
|
| |
+ pipelineaas.getVars(script: pipelineaas, pipeline_id: 'abc-12', namespace: 'originnamespace')
|
| |
+ printCallStack()
|
| |
+ assertEquals(1, helper.methodCallCount("withCluster"))
|
| |
+ assertEquals(2, helper.methodCallCount("withProject"))
|
| |
+ def withProjectCalls = helper.callStack.findAll {call -> call.methodName == 'withProject'}
|
| |
+ assertEquals('originnamespace', withProjectCalls[0].args[0])
|
| |
+ assertEquals('testnamespace', withProjectCalls[1].args[0])
|
| |
+ }
|
| |
+
|
| |
+ @Test
|
| |
+ void testGetVarsDefaultNamespace() {
|
| |
+ pipelineaas.getVars(script: pipelineaas, pipeline_id: 'abc-12')
|
| |
+ printCallStack()
|
| |
+ assertEquals(1, helper.methodCallCount("withCluster"))
|
| |
+ assertEquals(2, helper.methodCallCount("withProject"))
|
| |
+ def withProjectCalls = helper.callStack.findAll {call -> call.methodName == 'withProject'}
|
| |
+ assertEquals('', withProjectCalls[0].args[0])
|
| |
+ assertEquals('testnamespace', withProjectCalls[1].args[0])
|
| |
+ }
|
| |
+
|
| |
+ @Test
|
| |
+ void testDestroyC3IAAS() {
|
| |
+ helper.registerAllowedMethod('getVars', [Map.class], {['C3IAAS': "true"]})
|
| |
+ pipelineaas.destroy(script: pipelineaas, pipeline_id: 'abc-12')
|
| |
+ printCallStack()
|
| |
+ assertTrue(helper.callStack.any { call ->
|
| |
+ call.methodName == 'selector' && call.args[0] == 'project'
|
| |
+ })
|
| |
+ assertEquals(1, helper.methodCallCount("withCluster"))
|
| |
+ assertEquals(0, helper.methodCallCount("withProject"))
|
| |
+ assertEquals(2, helper.methodCallCount("delete"))
|
| |
+ }
|
| |
+
|
| |
+ @Test
|
| |
+ void testDestroyNamespace() {
|
| |
+ helper.registerAllowedMethod('getVars', [Map.class], {['C3IAAS': "false"]})
|
| |
+ pipelineaas.destroy(script: pipelineaas, pipeline_id: 'abc-12')
|
| |
+ printCallStack()
|
| |
+ assertTrue(helper.callStack.any { call ->
|
| |
+ call.methodName == 'selector' && call.args[1] == ["c3i.redhat.com/pipeline": "abc-12"]
|
| |
+ })
|
| |
+ assertEquals(1, helper.methodCallCount("withCluster"))
|
| |
+ assertEquals(1, helper.methodCallCount("withProject"))
|
| |
+ assertEquals(2, helper.methodCallCount("delete"))
|
| |
+ }
|
| |
+
|
| |
+
|
| |
+ }
|
| |
Function for getting metadata of pipeline as a service and destroying pipeline.