summaryrefslogtreecommitdiffstats
path: root/test/test_list_rules.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:56 +0000
commitd964cec5e6aa807b75c7a4e7cdc5f11e54b2eda2 (patch)
tree794bc3738a00b5e599f06d1f2f6d79048d87ff8e /test/test_list_rules.py
parentInitial commit. (diff)
downloadansible-lint-d964cec5e6aa807b75c7a4e7cdc5f11e54b2eda2.tar.xz
ansible-lint-d964cec5e6aa807b75c7a4e7cdc5f11e54b2eda2.zip
Adding upstream version 6.13.1.upstream/6.13.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/test_list_rules.py')
-rw-r--r--test/test_list_rules.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/test_list_rules.py b/test/test_list_rules.py
new file mode 100644
index 0000000..eab512b
--- /dev/null
+++ b/test/test_list_rules.py
@@ -0,0 +1,76 @@
+"""Tests related to our logging/verbosity setup."""
+
+import os
+
+import pytest
+
+from ansiblelint.testing import run_ansible_lint
+
+
+def test_list_rules_includes_opt_in_rules() -> None:
+ """Checks that listing rules also includes the opt-in rules."""
+ # Piggyback off the .yamllint in the root of the repo, just for testing.
+ # We'll "override" it with the one in the fixture.
+ cwd = os.path.realpath(
+ os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
+ )
+ fakerole = os.path.join("test", "fixtures", "list-rules-tests")
+
+ result_list_rules = run_ansible_lint("-L", fakerole, cwd=cwd)
+
+ assert ("opt-in" in result_list_rules.stdout) is True
+
+
+@pytest.mark.parametrize(
+ ("result", "returncode", "format_string"),
+ (
+ (False, 0, "brief"),
+ (False, 0, "full"),
+ (False, 0, "md"),
+ (True, 2, "json"),
+ (True, 2, "codeclimate"),
+ (True, 2, "quiet"),
+ (True, 2, "pep8"),
+ (True, 2, "foo"),
+ ),
+ ids=(
+ "plain",
+ "full",
+ "md",
+ "json",
+ "codeclimate",
+ "quiet",
+ "pep8",
+ "foo",
+ ),
+)
+def test_list_rules_with_format_option(
+ result: bool, returncode: int, format_string: str
+) -> None:
+ """Checks that listing rules with format options works."""
+ # Piggyback off the .yamllint in the root of the repo, just for testing.
+ # We'll "override" it with the one in the fixture.
+ cwd = os.path.realpath(
+ os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
+ )
+ fakerole = os.path.join("test", "fixtures", "list-rules-tests")
+
+ result_list_rules = run_ansible_lint("-f", format_string, "-L", fakerole, cwd=cwd)
+
+ assert (f"invalid choice: '{format_string}'" in result_list_rules.stderr) is result
+ assert ("syntax-check" in result_list_rules.stdout) is not result
+ assert result_list_rules.returncode is returncode
+
+
+def test_list_tags_includes_opt_in_rules() -> None:
+ """Checks that listing tags also includes the opt-in rules."""
+ # Piggyback off the .yamllint in the root of the repo, just for testing.
+ # We'll "override" it with the one in the fixture.
+ cwd = os.path.realpath(
+ os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
+ )
+ fakerole = os.path.join("test", "fixtures", "list-rules-tests")
+
+ result_list_tags = run_ansible_lint("-L", fakerole, cwd=cwd)
+
+ assert ("opt-in" in result_list_tags.stdout) is True