Esempio n. 1
0
    def test_run_command_recursion(self):
        yaml_template = """\
        tasks:           
          1:
            - echo 1
          2:
            - 1
            - echo 2
          3:
            - 2
            - echo 3
        """

        yaml_path: str = os.path.abspath(_CURRENT_DIR + "/" +
                                         CAOS_YAML_FILE_NAME)
        self.assertFalse(os.path.isfile(yaml_path))
        with open(file=yaml_path, mode="w") as yaml_file:
            yaml_file.write(yaml_template)

        self.assertTrue(os.path.isfile(yaml_path))

        exit_code: int = command_run.entry_point(args=["3"])
        self.assertEqual(0, exit_code)

        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn("1\n2\n3", messages)
Esempio n. 2
0
    def test_run_command_unknown_task(self):
        yaml_template = """\
        tasks:           
          hello:
            - echo Hello World
        """

        yaml_path: str = os.path.abspath(_CURRENT_DIR + "/" +
                                         CAOS_YAML_FILE_NAME)
        self.assertFalse(os.path.isfile(yaml_path))
        with open(file=yaml_path, mode="w") as yaml_file:
            yaml_file.write(yaml_template)

        self.assertTrue(os.path.isfile(yaml_path))

        with self.assertRaises(Exception) as context:
            command_run.entry_point(args=["bye"])
        self.assertIn("No task named 'bye' was found", str(context.exception))
Esempio n. 3
0
    def test_run_command_non_zero_exit(self):
        yaml_template = """\
        tasks:           
          hello:
            - exit 1
        """

        yaml_path: str = os.path.abspath(_CURRENT_DIR + "/" +
                                         CAOS_YAML_FILE_NAME)
        self.assertFalse(os.path.isfile(yaml_path))
        with open(file=yaml_path, mode="w") as yaml_file:
            yaml_file.write(yaml_template)

        self.assertTrue(os.path.isfile(yaml_path))

        with self.assertRaises(Exception) as context:
            command_run.entry_point(args=["hello"])

        self.assertIn(
            "Within the task 'hello' the step 'exit 1' returned a non zero exit code",
            str(context.exception))
Esempio n. 4
0
    def test_run_command_recursion_exceeded(self):
        yaml_template = """\
        tasks:           
          1:
            - 1
            - echo 1
        """

        yaml_path: str = os.path.abspath(_CURRENT_DIR + "/" +
                                         CAOS_YAML_FILE_NAME)
        self.assertFalse(os.path.isfile(yaml_path))
        with open(file=yaml_path, mode="w") as yaml_file:
            yaml_file.write(yaml_template)

        self.assertTrue(os.path.isfile(yaml_path))

        with self.assertRaises(RecursionError) as context:
            command_run.entry_point(args=["1"])

        self.assertIn("Maximum recursion depth exceeded",
                      str(context.exception))
Esempio n. 5
0
    def test_run_command_arguments_warning(self):
        yaml_template = """\
        tasks:           
          hello:
            - echo Hello World
        """

        yaml_path: str = os.path.abspath(_CURRENT_DIR + "/" +
                                         CAOS_YAML_FILE_NAME)
        self.assertFalse(os.path.isfile(yaml_path))
        with open(file=yaml_path, mode="w") as yaml_file:
            yaml_file.write(yaml_template)

        self.assertTrue(os.path.isfile(yaml_path))

        exit_code: int = command_run.entry_point(args=["hello", "arg"])
        self.assertEqual(0, exit_code)

        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn("WARNING: The tasks can't receive arguments", messages)