def test_build_pwsh_test(): """Build Pytest command with json""" from demisto_sdk.commands.lint.commands_builder import \ build_pwsh_test_command command = 'pwsh -Command Invoke-Pester -Configuration \'@{Run=@{Exit=$true}; Output=@{Verbosity="Detailed"}}\'' assert command == build_pwsh_test_command()
def _docker_run_pwsh_test(self, test_image: str, keep_container: bool) -> Tuple[int, str]: """ Run Powershell tests in created test image Args: test_image(str): test image id/name keep_container(bool): True if to keep container after excution finished Returns: int: 0 on successful, errors 1, neet to retry 2 str: Container log """ log_prompt = f'{self._pack_name} - Powershell test - Image {test_image}' logger.info(f"{log_prompt} - Start") container_name = f"{self._pack_name}-pwsh-test" # Check if previous run left container a live if it do, we remove it container_obj: docker.models.containers.Container try: container_obj = self._docker_client.containers.get(container_name) container_obj.remove(force=True) except docker.errors.NotFound: pass # Run container exit_code = SUCCESS output = "" try: container_obj = self._docker_client.containers.run( name=container_name, image=test_image, command=build_pwsh_test_command(), user=f"{os.getuid()}:4000", detach=True, environment=self._facts["env_vars"]) stream_docker_container_output(container_obj.logs(stream=True)) # wait for container to finish container_status = container_obj.wait(condition="exited") # Get container exit code container_exit_code = container_status.get("StatusCode") # Getting container logs container_log = container_obj.logs().decode("utf-8") logger.info(f"{log_prompt} - exit-code: {container_exit_code}") if container_exit_code: # 1-fatal message issued # 2-Error message issued logger.info(f"{log_prompt} - Finished errors found") output = container_log exit_code = FAIL else: logger.info(f"{log_prompt} - Successfully finished") # Keeping container if needed or remove it if keep_container: print(f"{log_prompt} - container name {container_name}") else: try: container_obj.remove(force=True) except docker.errors.NotFound as e: logger.critical( f"{log_prompt} - Unable to delete container - {e}") except (docker.errors.ImageNotFound, docker.errors.APIError) as e: logger.critical( f"{log_prompt} - Unable to run powershell test - {e}") exit_code = RERUN return exit_code, output
def test_build_pwsh_test(): """Build Pytest command with json""" from demisto_sdk.commands.lint.commands_builder import build_pwsh_test_command command = "pwsh -Command Invoke-Pester -EnableExit" assert command == build_pwsh_test_command()