Beispiel #1
0
    def test_scan(self):
        role_names = th.create_roles(self.test_path, 3)

        for i, role in enumerate(role_names):
            defaults_path = os.path.join(self.test_path, role, "defaults",
                                         "main.yml")
            tasks_path = os.path.join(self.test_path, role, "tasks",
                                      "main.yml")
            meta_path = os.path.join(self.test_path, role, "meta", "main.yml")
            utils.string_to_file(defaults_path, th.DEFAULTS_TEMPLATE)
            utils.string_to_file(tasks_path, th.TASKS_TEMPLATE)

            # remove 1 of the meta files
            if i == 2:
                os.remove(meta_path)

        (out, err) = utils.capture_shell("ansigenome scan {0}".format(
            self.test_path))

        th.print_out("Scan output without terminal colors:", out)

        self.assertIn("3 roles", out)
        self.assertIn("3 defaults", out)
        self.assertIn("9 defaults", out)
        self.assertIn("2 facts", out)
        self.assertIn("6 facts", out)
        self.assertIn("8 files", out)
        self.assertIn("26 files", out)
        self.assertIn("88 lines", out)
        self.assertIn("230 lines", out)

        self.assertIn(
            "0 ok       3 missing readme(s)       " + "0 missing meta(s)", out)

        self.assertEqual(err, "")
    def test_gendoc(self):
        all_metas = {}
        idempotency_tag = "_idem"
        relative_readme_path = "README.rst"
        relative_meta_path = os.path.join("meta", "main.yml")

        role_names = th.create_roles(self.test_path, 3)

        # ----------------------------------------------------------------
        # add meta files to the roles
        # ----------------------------------------------------------------
        for i, role in enumerate(role_names):
            defaults_path = os.path.join(self.test_path, role,
                                         "defaults", "main.yml")
            tasks_path = os.path.join(self.test_path, role,
                                      "tasks", "main.yml")
            utils.string_to_file(defaults_path, th.DEFAULTS_TEMPLATE)
            utils.string_to_file(tasks_path, th.TASKS_TEMPLATE)

        # ----------------------------------------------------------------
        # run the genmeta command and check its output
        # ----------------------------------------------------------------
        (out, err) = utils.capture_shell(
            "ansigenome genmeta {0}".format(self.test_path))

        if os.path.exists(relative_meta_path):
            th.populate_dict_with_files(self.test_path, role_names, all_metas,
                                        relative_readme_path)

        th.print_out("Genmeta output without terminal colors:", out)

        self.assertIn("meta files    0 ok       0 skipped       " +
                      "3 changed", out)

        # ----------------------------------------------------------------
        # run the genmeta command on the same roles to test idempotency
        # ----------------------------------------------------------------
        (out, err) = utils.capture_shell(
            "ansigenome genmeta {0}".format(self.test_path))

        if os.path.exists(relative_meta_path):
            th.populate_dict_with_files(self.test_path, role_names, all_metas,
                                        relative_readme_path,
                                        idempotency_tag)

        # run a diff to help debug idempotency issues
        th.run_diff_on(all_metas, relative_meta_path, idempotency_tag)

        th.print_out("Genmeta output idempotency test:", out)

        self.assertIn("meta files    0 ok       3 skipped       " +
                      "0 changed", out)
Beispiel #3
0
    def test_scan(self):
        role_names = th.create_roles(self.test_path, 3)

        for i, role in enumerate(role_names):
            defaults_path = os.path.join(self.test_path, role,
                                         "defaults", "main.yml")
            tasks_path = os.path.join(self.test_path, role,
                                      "tasks", "main.yml")
            meta_path = os.path.join(self.test_path, role,
                                     "meta", "main.yml")
            utils.string_to_file(defaults_path, th.DEFAULTS_TEMPLATE)
            utils.string_to_file(tasks_path, th.TASKS_TEMPLATE)

            # remove 1 of the meta files
            if i == 2:
                os.remove(meta_path)

        (out, err) = utils.capture_shell(
            "ansigenome scan {0}".format(self.test_path))

        th.print_out("Scan output without terminal colors:", out)

        self.assertIn("3 roles", out)
        self.assertIn("3 defaults", out)
        self.assertIn("9 defaults", out)
        self.assertIn("2 facts", out)
        self.assertIn("6 facts", out)
        self.assertIn("8 files", out)
        self.assertIn("26 files", out)
        self.assertIn("88 lines", out)
        self.assertIn("230 lines", out)

        self.assertIn("0 ok       3 missing readme(s)       " +
                      "0 missing meta(s)", out)

        self.assertEqual(err, "")
Beispiel #4
0
    def test_gendoc(self):
        all_readmes = {}
        idempotency_tag = "_idem"
        relative_readme_path = "README.rst"
        relative_meta_path = os.path.join("meta", "main.yml")

        role_names = th.create_roles(self.test_path, 3)

        # ----------------------------------------------------------------
        # add readme files to the roles
        # ----------------------------------------------------------------
        for i, role in enumerate(role_names):
            defaults_path = os.path.join(self.test_path, role, "defaults",
                                         "main.yml")
            tasks_path = os.path.join(self.test_path, role, "tasks",
                                      "main.yml")
            utils.string_to_file(defaults_path, th.DEFAULTS_TEMPLATE)
            utils.string_to_file(tasks_path, th.TASKS_TEMPLATE)

        # ----------------------------------------------------------------
        # run the gendoc command and check its output
        # ----------------------------------------------------------------
        (out, err) = utils.capture_shell("ansigenome gendoc {0}".format(
            self.test_path))

        if os.path.exists(relative_meta_path):
            th.populate_dict_with_files(self.test_path, role_names,
                                        all_readmes, relative_readme_path)

        th.print_out("Gendoc output without terminal colors:", out)

        self.assertIn(
            "readme files    3 ok       0 skipped       " + "0 changed", out)

        # ----------------------------------------------------------------
        # run the gendoc command on the same roles to test idempotency
        # ----------------------------------------------------------------
        (out, err) = utils.capture_shell("ansigenome gendoc {0}".format(
            self.test_path))

        if os.path.exists(relative_meta_path):
            th.populate_dict_with_files(self.test_path, role_names,
                                        all_readmes, relative_readme_path,
                                        idempotency_tag)

        # run a diff to help debug idempotency issues
        th.run_diff_on(all_readmes, relative_readme_path, idempotency_tag)

        th.print_out("Gendoc output idempotency test:", out)

        self.assertIn(
            "readme files    0 ok       3 skipped       " + "0 changed", out)

        # ----------------------------------------------------------------
        # run the gendoc command on the same roles to test failures
        # ----------------------------------------------------------------
        broken_meta = "{{"
        first_role = role_names[0]
        fail_path = os.path.join(self.test_path, first_role,
                                 relative_meta_path)
        utils.string_to_file(fail_path, broken_meta)

        (out, err) = utils.capture_shell("ansigenome gendoc {0}".format(
            self.test_path))
        th.print_out("Gendoc output failed test:", out)

        self.assertIn("^", out)

        assert err == "", "expected empty err but got:\n{0}".format(err)