def execute_integtest_sh(self, endpoint: str, port: int, security: bool, test_config: str) -> int: script = ScriptFinder.find_integ_test_script( self.component.name, self.repo.working_directory) if os.path.exists(script): cmd = f"{script} -b {endpoint} -p {port} -s {str(security).lower()} -v {self.bundle_manifest.build.version}" self.repo_work_dir = os.path.join( self.repo.dir, self.test_config.working_directory ) if self.test_config.working_directory is not None else self.repo.dir (status, stdout, stderr) = execute(cmd, self.repo_work_dir, True, False) test_result_data = TestResultData(self.component.name, test_config, status, stdout, stderr, self.test_artifact_files) self.save_logs.save_test_result_data(test_result_data) if stderr: logging.info("Integration test run failed for component " + self.component.name) logging.info(stderr) return status else: logging.info( f"{script} does not exist. Skipping integ tests for {self.component.name}" ) return 0
def execute_bwctest_sh(self, config: str) -> int: security = self.is_security_enabled(config) script = ScriptFinder.find_bwc_test_script(self.component.name, self.repo.working_directory) if os.path.exists(script): cmd = self.get_cmd(script, security, self.manifest.build.location) self.repo_work_dir = os.path.join( self.repo.dir, self.test_config.working_directory ) if self.test_config.working_directory is not None else self.repo.dir (status, stdout, stderr) = execute(cmd, self.repo_work_dir, True, False) test_result_data = TestResultData(self.component.name, config, status, stdout, stderr, self.test_artifact_files) self.save_logs.save_test_result_data(test_result_data) if stderr: logging.info("BWC test run failed for component " + self.component.name) logging.info(stderr) return status else: logging.info( f"{script} does not exist. Skipping integ tests for {self.component.name}" ) return 0
def test_execute_status_capture_false_raise_false(self) -> None: (status, stdout, stderr) = execute("echo output && exit 128", "/", capture=False, raise_on_failure=False) # (128, None, None) self.assertEqual(status, 128) self.assertEqual(stdout, None) self.assertEqual(stderr, None)
def test_execute_status_capture_true_raise_false(self) -> None: (status, stdout, stderr) = execute("echo output && exit 128", "/", capture=True, raise_on_failure=False) # (128, 'output', '') self.assertEqual(status, 128) self.assertEqual(stdout.strip(), "output") self.assertEqual(stderr.strip(), "")
def test_execute_status_capture_true_raise_True(self) -> None: with self.assertRaises(subprocess.CalledProcessError) as context: (status, stdout, stderr) = execute("echo output && exit 128", "/", capture=True, raise_on_failure=True) # (128, 'error', '') self.assertEqual( "Command 'echo output && exit 128' returned non-zero exit status 128.", str(context.exception), )
def run_tests(self, work_dir, component_name): script = ScriptFinder.find_bwc_test_script(component_name, work_dir) (status, stdout, stderr) = execute(script, work_dir, True, False) return (status, stdout, stderr)
def test_execute_stderr(self) -> None: (status, stdout, stderr) = execute(">&2 echo error", "/") # (0, '', 'error\n') self.assertEqual(status, 0) self.assertEqual(stdout.strip(), "") self.assertEqual(stderr.strip(), "error")
def test_execute_stdout(self) -> None: (status, stdout, stderr) = execute("echo success", "/") # (0, 'success\n', '') self.assertEqual(status, 0) self.assertEqual(stdout.strip(), "success") self.assertEqual(stderr.strip(), "")