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 committed Sep 21, 2023
1 parent 30bae80 commit e803f3d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ MYTAG
PYTHONBREAKPOINT
PYTHONIOENCODING
PYTHONPYCACHEPREFIX
Qalthos
REQPASS
RULEDIRS
RUNLEVEL
Expand Down
24 changes: 24 additions & 0 deletions examples/plugins/modules/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Copyright: (c) 2023 Kate Case (@Qalthos)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""An example module for testing purposes"""

from __future__ import absolute_import, division, print_function
__metaclass__ = type


DOCUMENTATION = r"""
---
module: example
short_description: Does nothing
description:
- This module exists solely as an example
"""

EXAMPLES = r"""
- name: "playbook"
tasks:
- name: Hello
debug:
msg: 'world'
"""
20 changes: 20 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(
"examples/plugins/modules/example.py",
"plugin",
id="44",
),
),
)
def test_kinds(path: str, kind: FileType) -> None:
Expand Down Expand Up @@ -536,3 +541,18 @@ 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.
Test that when CWD is outside ~, and argument is like ~/playbook.yml
we will still be able to process the files.
See: https://github.com/ansible/ansible-lint/issues/2513
"""
filename = Path("examples/plugins/modules/example.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 e803f3d

Please sign in to comment.