예제 #1
0
 def __init__(self,
              docker=Docker(),
              runner=Runner(),
              file_wrapper=FileWrapper()):
     self.docker = docker
     self.runner = runner
     self.file_wrapper = file_wrapper
예제 #2
0
class RunnerTest(unittest.TestCase):

    def setUp(self):
        self.docker_mock = MagicMock(Docker)

        self.sut = Runner(docker=self.docker_mock)

    def test_run_script_in_env(self):
        # Fixture
        module_config = {'environmentReq': ['req']}
        tb_config = {'environments': {'imageName': ['req']}}
        module_root_in_docker_host = "path"
        script = "script"
        script_args = ['a', 'b']

        # Test
        self.sut.run_script_in_env(tb_config, module_config, script,
                                   module_root_in_docker_host, script_args)

        # Assert
        self.docker_mock.run_script_in_container.assert_called_once_with(
                'imageName', script, script_args,
                volumes=[(module_root_in_docker_host, '/module')])

    def test_run_script_in_env_no_env_found_should_raise(self):
        # Fixture
        module_config = {'environmentReq': ['unmatched_req']}
        tb_config = {'environments': {'imageName': ['req']}}
        module_root_in_docker_host = "path"
        script = "script"
        script_args = []

        # Assert
        with self.assertRaises(ToolbeltException):

            # Test
            self.sut.run_script_in_env(tb_config, module_config, script,
                                       module_root_in_docker_host, script_args)

    def test_use_matching_env(self):
        # Fixture
        module_config = {'environmentReq': ['req1', 'req2']}
        tb_config = {'environments': {'imageName': ['req1', 'req2'],
                                      'wrongImage': ['req1']}}
        module_root_in_docker_host = "path"
        script = "script"
        script_args = ['a', 'b']

        # Test
        self.sut.run_script_in_env(tb_config, module_config, script,
                                   module_root_in_docker_host, script_args)

        # Assert
        self.docker_mock.run_script_in_container.assert_called_once_with(
                'imageName', script, script_args,
                volumes=[(module_root_in_docker_host, '/module')])
예제 #3
0
    def __init__(self):
        self.sub_proc = SubProc()
        self.docker = Docker(self.sub_proc)
        self.runner = Runner(self.docker)
        self.file_wrapper = FileWrapper()
        self.bc_module = BcModule(self.docker, self.runner, self.file_wrapper)
        self.git = Git(self.sub_proc)
        self.ui = Ui()

        self.tools = [
            help.Help(self.bc_module),
            update.Update(self.docker),
            version.Version(self.docker),
            ghrn.Ghrn(self.docker),
            docs.Docs(self.docker),
        ]

        self.config_reader = ConfigReader(self.file_wrapper, self.bc_module,
                                          self.tools)
예제 #4
0
    def setUp(self):
        self.docker_mock = MagicMock(Docker)

        self.sut = Runner(docker=self.docker_mock)
예제 #5
0
class RunnerTest(unittest.TestCase):
    def setUp(self):
        self.docker_mock = MagicMock(Docker)

        self.sut = Runner(docker=self.docker_mock)

    def test_run_script_in_env(self):
        # Fixture
        module_config = {'environmentReq': ['req']}
        tb_config = {'environments': {'imageName': ['req']}, 'uid': '123'}
        module_root_in_docker_host = "path"
        script = "script"
        script_args = ['a', 'b']

        # Test
        self.sut.run_script_in_env(tb_config, module_config, script,
                                   module_root_in_docker_host, script_args)

        # Assert
        self.docker_mock.run_script_in_container.assert_called_once_with(
            '123',
            'imageName',
            script,
            script_args,
            volumes=[(module_root_in_docker_host, '/module')])

    def test_run_script_in_env_no_env_found_should_raise(self):
        # Fixture
        module_config = {'environmentReq': ['unmatched_req']}
        tb_config = {'environments': {'imageName': ['req']}}
        module_root_in_docker_host = "path"
        script = "script"
        script_args = []

        # Assert
        with self.assertRaises(ToolbeltException):

            # Test
            self.sut.run_script_in_env(tb_config, module_config, script,
                                       module_root_in_docker_host, script_args)

    def test_use_matching_env(self):
        # Fixture
        module_config = {'environmentReq': ['req1', 'req2']}
        tb_config = {
            'environments': {
                'imageName': ['req1', 'req2'],
                'wrongImage': ['req1']
            },
            'uid': '123'
        }
        module_root_in_docker_host = "path"
        script = "script"
        script_args = ['a', 'b']

        # Test
        self.sut.run_script_in_env(tb_config, module_config, script,
                                   module_root_in_docker_host, script_args)

        # Assert
        self.docker_mock.run_script_in_container.assert_called_once_with(
            '123',
            'imageName',
            script,
            script_args,
            volumes=[(module_root_in_docker_host, '/module')])
예제 #6
0
    def setUp(self):
        self.docker_mock = MagicMock(Docker)

        self.sut = Runner(docker=self.docker_mock)