Esempio n. 1
0
def test_workflow_build_image(terminate_build: bool,
                              workflow: DockerBuildWorkflow, caplog):
    """
    Test workflow for base images
    """
    flexmock(DockerfileParser, content='df_content')
    this_file = inspect.getfile(UpdateMaintainerPlugin)
    watch_update_maintainer = Watcher()
    watch_push_image = Watcher()
    watch_cleanup = Watcher()

    workflow.plugins_conf = [
        {
            'name': UpdateMaintainerPluginWatched.key,
            'args': {
                'watcher': watch_update_maintainer
            },
        },
        {
            'name': PushImagePluginWatched.key,
            'args': {
                'watcher': watch_push_image
            }
        },
        {
            'name': CleanupPluginWatched.key,
            'args': {
                'watcher': watch_cleanup
            }
        },
    ]
    workflow.plugin_files = [this_file]

    # This test does not require a separate FSWatcher thread.
    fs_watcher = flexmock(workflow.fs_watcher)
    fs_watcher.should_receive('start')
    fs_watcher.should_receive('finish')

    if terminate_build:
        workflow.plugins_conf[1]['args']['watcher'] = WatcherWithSignal(
            signal=signal.SIGTERM)
        workflow.build_docker_image()
        assert "Build was canceled" in caplog.text
        assert workflow.data.build_canceled
    else:
        workflow.build_docker_image()

        assert watch_update_maintainer.was_called()
        assert watch_push_image.was_called()
        assert watch_cleanup.was_called()

        results = workflow.data.plugins_results
        assert results[UpdateMaintainerPluginWatched.key]
        assert "pushed image" == results[PushImagePluginWatched.key]
        assert results[CleanupPluginWatched.key] is None