Skip to content

Commit

Permalink
Add simple tests for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos authored and audgirka committed Oct 3, 2023
1 parent 5e4d9fe commit b1baf26
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions plugins/modules/fake_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
15 changes: 15 additions & 0 deletions test/test_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit b1baf26

Please sign in to comment.