Ejemplo n.º 1
0
    def test_failed_two_blocks(self):
        """Testing cleanup when a task has failed (ordered with two blocks)."""
        hooks = Hooks()
        hooks.cleanup = '''echo cleanup hello'''
        pipeline = FakePipeline(hooks=hooks)
        tasks = Tasks(pipeline, parallel=False)

        definition = [{
            'shell': {
                'script': '''exit 123''',
                'when': ''
            }
        }, {
            'shell': {
                'script': '''echo hello1''',
                'when': ''
            }
        }, {
            'env': {
                'block': 'two'
            }
        }, {
            'shell': {
                'script': '''echo hello2''',
                'when': ''
            }
        }]
        result = tasks.process(definition)
        output = [line for line in result['output'] if line.find("hello") >= 0]

        assert_that(result['success'], equal_to(False))
        assert_that(len(output), equal_to(1))
        assert_that(output[0], equal_to('cleanup hello'))
Ejemplo n.º 2
0
    def test_failed_parallel(self):
        """Testing cleanup when a task has failed (parallel)."""
        hooks = Hooks()
        hooks.cleanup = '''echo cleanup 123'''
        pipeline = FakePipeline(hooks=hooks)
        tasks = Tasks(pipeline, parallel=True)

        definition = [{
            'shell': {
                'script': '''exit 123''',
                'when': ''
            }
        }, {
            'shell': {
                'script': '''echo hello''',
                'when': ''
            }
        }]
        result = tasks.process(definition)
        output = sorted([
            line for line in result['output']
            if line.find("hello") >= 0 or line.find("cleanup") >= 0
        ])

        assert_that(result['success'], equal_to(False))
        assert_that(len(output), equal_to(2))
        assert_that(output[0], equal_to('cleanup 123'))
        assert_that(output[1], equal_to('hello'))
Ejemplo n.º 3
0
    def test_simple_failed_pipeline(self):
        """Testing of a simple failed pipeline."""
        definition = [{
            'stage(test)': [{
                'tasks': [{
                    'shell': {
                        'script': '''echo tasks1:hello1''',
                        'when': ''
                    }
                }, {
                    'shell': {
                        'script': '''exit 123''',
                        'when': ''
                    }
                }, {
                    'shell': {
                        'script': '''echo tasks1:hello3''',
                        'when': ''
                    }
                }]
            }]
        }]
        hooks = Hooks()
        hooks.cleanup = '''echo cleanup hello'''
        pipeline = Pipeline(options=ApplicationOptions(definition='fake.yaml'))
        pipeline.hooks = hooks
        result = pipeline.process(definition)
        output = [line for line in result['output'] if line.find("hello") >= 0]

        assert_that(result['success'], equal_to(False))
        assert_that(len(output), equal_to(2))
        assert_that(output[0], equal_to('tasks1:hello1'))
        assert_that(output[1], equal_to('cleanup hello'))
        assert_that(pipeline.hooks, equal_to(hooks))
Ejemplo n.º 4
0
    def test_environment_variables(self):
        """Testing of a simple valid pipeline with environment variables."""
        definition = [{
            'env': {
                'message': 'pipeline hello'
            }
        }, {
            'stage(test)': [{
                'tasks': [{
                    'shell': {
                        'script': '''echo $message''',
                        'when': ''
                    }
                }, {
                    'shell': {
                        'script': '''echo tasks1:hello''',
                        'when': ''
                    }
                }]
            }]
        }]
        hooks = Hooks()
        hooks.cleanup = '''echo cleanup hello'''
        pipeline = Pipeline(options=ApplicationOptions(definition='fake.yaml'))
        pipeline.hooks = hooks
        result = pipeline.process(definition)
        output = [line for line in result['output'] if line.find("hello") >= 0]

        assert_that(result['success'], equal_to(True))
        assert_that(len(output), equal_to(3))
        assert_that(output[0], equal_to('pipeline hello'))
        assert_that(output[1], equal_to('tasks1:hello'))
        assert_that(output[2], equal_to('cleanup hello'))
Ejemplo n.º 5
0
    def test_failed(self):
        """Testing for failed stage."""
        hooks = Hooks()
        hooks.cleanup = '''echo cleanup hello'''
        pipeline = FakePipeline(hooks=hooks)
        stage = Stage(pipeline, 'test')

        definition = [{
            'tasks': [{
                'shell': {
                    'script': '''echo tasks1:hello1''',
                    'when': ''
                }
            }, {
                'shell': {
                    'script': '''exit 123''',
                    'when': ''
                }
            }]
        }, {
            'tasks': [{
                'shell': {
                    'script': '''echo tasks2:hello1''',
                    'when': ''
                }
            }, {
                'shell': {
                    'script': '''echo tasks2:hello2''',
                    'when': ''
                }
            }]
        }]
        result = stage.process(definition)
        output = [line for line in result['output'] if line.find("hello") >= 0]

        assert_that(result['success'], equal_to(False))
        assert_that(len(output), equal_to(2))
        assert_that(output[0], equal_to('tasks1:hello1'))
        assert_that(output[1], equal_to('cleanup hello'))