From b1baf26864f64c23c151fe4add91d35041daa6fb Mon Sep 17 00:00:00 2001 From: Kate Case Date: Thu, 21 Sep 2023 12:21:49 -0400 Subject: [PATCH] Add simple tests for plugins --- .github/workflows/tox.yml | 2 +- plugins/modules/fake_module.py | 8 ++++++++ test/test_file_utils.py | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 77810bdf0a..74a036f202 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -70,7 +70,7 @@ jobs: env: # Number of expected test passes, safety measure for accidental skip of # tests. Update value if you add/remove tests. - PYTEST_REQPASS: 829 + PYTEST_REQPASS: 831 steps: - uses: actions/checkout@v4 with: diff --git a/plugins/modules/fake_module.py b/plugins/modules/fake_module.py index bdff5c7e4d..1c4ab424fd 100644 --- a/plugins/modules/fake_module.py +++ b/plugins/modules/fake_module.py @@ -4,6 +4,14 @@ """ from ansible.module_utils.basic import AnsibleModule +EXAMPLES = r""" +- name: "playbook" + tasks: + - name: Hello + debug: + msg: 'world' +""" + def main() -> None: """Return the module instance.""" diff --git a/test/test_file_utils.py b/test/test_file_utils.py index 81faa3253a..d94b631bdf 100644 --- a/test/test_file_utils.py +++ b/test/test_file_utils.py @@ -258,6 +258,11 @@ def test_discover_lintables_umlaut(monkeypatch: MonkeyPatch) -> None: "playbook", id="43", ), # content should determine it as a play + pytest.param( + "plugins/modules/fake_module.py", + "plugin", + id="44", + ), ), ) def test_kinds(path: str, kind: FileType) -> None: @@ -536,3 +541,13 @@ def test_bug_2513( results = Runner(filename, rules=default_rules_collection).run() assert len(results) == 1 assert results[0].rule.id == "name" + + +def test_examples_content() -> None: + """Test that a module loads the correct content.""" + filename = Path("plugins/modules/fake_module.py") + lintable = Lintable(filename) + # Lintable is now correctly purporting to be a YAML file + assert lintable.base_kind == "text/yaml" + # Lintable content should be contents of EXAMPLES + assert lintable.content == "---" + BASIC_PLAYBOOK