Exemplo n.º 1
0
 def setUp(self):
     self._listener = MagicMock(ExecutorListener)
     self._tested = Component(name="Foo",
                              test_settings=TestSettings(
                                  "green tests", "junit", "./", ".xml"))
     self._log = BytesIO()
     self._engine = Engine(self._tested, SimulatedShell(self._log, "."),
                           self._listener)
     self._configurations = [("config_1", "useless"),
                             ("config_2", "useless")]
Exemplo n.º 2
0
    def execute(self, arguments):
        self._ui.welcome()
        self._prepare_directories(arguments)
        try:
            model = self._load_model()
            testing = model.tests
            configurations = self._load_configurations(model)
            selected_configurations = self._filter(arguments,
                                                   list(configurations))
            with open("camp_execute.log", "wb") as log_file:
                shell = self._select_shell(arguments, log_file)
                engine = Engine(testing, shell, arguments, self._ui)
                reports = engine.execute(selected_configurations)
                self._output.save_reports(reports)
                self._ui.summarize_execution(reports)

        except InvalidYAMLModel as error:
            self._ui.invalid_yaml_model(error)

        except InvalidModel as error:
            self._ui.invalid_model(error)

        except MissingModel as error:
            self._ui.missing_model(error)

        except NoConfigurationFound as error:
            self._ui.no_configuration_found(error)

        except ShellCommandFailed as error:
            self._ui.shell_command_failed(error)

        except ServiceNotReady as error:
            self._ui.service_not_ready(error)

        except ReportFormatNotSupported as error:
            self._ui.report_format_not_supported(error)

        except Exception as error:
            stack_trace = extract_tb(exc_info()[2])
            self._ui.unexpected_error(error, stack_trace)

        finally:
            self._ui.goodbye()
Exemplo n.º 3
0
class TheExecutorShould(TestCase):
    def setUp(self):
        self._options = Execute()
        self._listener = MagicMock(ExecutorListener)
        self._tested = Component(name="Foo",
                                 test_settings=TestSettings(
                                     "green tests", "junit", "./", ".xml"))
        self._log = BytesIO()
        self._engine = Engine(self._tested, SimulatedShell(self._log, "."),
                              self._options, self._listener)
        self._configurations = [("config_1", "useless"),
                                ("config_2", "useless")]

    def test_notify_listener(self):
        self._call_execute()

        expected_calls = []
        for each, _ in self._configurations:
            expected_calls.append(call.execution_started_for(each))
            expected_calls.append(call.building_images_for(each))
            expected_calls.append(call.starting_services_for(each))
            expected_calls.append(call.running_tests_for(each))
            expected_calls.append(call.collecting_reports_for(each))
            expected_calls.append(call.collecting_logs_for(each))
            expected_calls.append(call.stopping_services_for(each))

        self._listener.assert_has_calls(expected_calls)

    def test_build_all_images_for_all_configurations(self):
        self._call_execute()

        for each_path, _ in self._configurations:
            path = join_paths(each_path, "images")
            expected_command = Engine._BUILD_IMAGES
            self._verify(path, expected_command)

    def test_start_services_for_all_configurations(self):
        self._call_execute()

        for each_path, _ in self._configurations:
            expected_command = Engine._START_SERVICES
            self._verify(each_path, expected_command)

    def test_run_tests_for_all_configurations(self):
        self._call_execute()

        for each_path, _ in self._configurations:
            expected_command = Engine.RUN_TESTS.format(
                path=join_paths(getcwd(), each_path),
                container=Engine._CONTAINER_NAME,
                component=self._tested.name,
                command=self._tested.test_settings.test_command)
            SimulatedShell.LOG_OUTPUT.format(each_path, expected_command)
            self._verify(each_path, expected_command)

    def test_fetch_test_reports(self):
        self._call_execute()

        for each_path, _ in self._configurations:
            docker_cp = Engine.FETCH_TEST_REPORTS.format(
                container=Engine._CONTAINER_NAME,
                component=self._tested.name,
                location=self._tested.test_settings.report_location)
            self._verify(each_path, docker_cp)

    def test_collect_logfiles_for_each_service(self):
        self._call_execute()

        for each_path, _ in self._configurations:
            expected = Engine.FETCH_LOG_FILE.format(
                path=Execute.DEFAULT_LOGS_PATH)
            self._verify(each_path, expected)

    def test_stop_services_for_all_configurations(self):
        self._call_execute()

        for each_path, _ in self._configurations:
            expected_command = Engine._STOP_SERVICES
            self._verify(each_path, expected_command)

    def _call_execute(self):
        self._engine.execute(self._configurations)

    def _verify(self, path, command):
        expected = SimulatedShell.LOG_OUTPUT.format(path, command)
        self.assertIn(expected, self._log.getvalue().decode())