Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test helper: adjusted unit tests using new features #9563

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_cpanm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


from ansible_collections.community.general.plugins.modules import cpanm
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(cpanm, __name__)
Helper.from_module(cpanm, __name__, mocks=[RunCommandMock])
8 changes: 6 additions & 2 deletions tests/unit/plugins/modules/test_cpanm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# SPDX-License-Identifier: GPL-3.0-or-later

---
anchors:
environ_true: &env-def-true {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
environ_false: &env-def-false {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
test_cases:
- id: install_dancer_compatibility
input:
name: Dancer
Expand All @@ -14,14 +18,14 @@
mocks:
run_command:
- command: [/testbin/cpanm, --version]
environ: &env-def-true {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
environ: *env-def-true
rc: 0
out: |
cpanm (App::cpanminus) version 1.7047 (/usr/local/bin/cpanm)
perl version 5.041005 (/usr/local/bin/perl)
err: ""
- command: [/testbin/perl, -le, 'use Dancer;']
environ: &env-def-false {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
environ: *env-def-false
rc: 2
out: ""
err: "error, not installed"
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_django_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


from ansible_collections.community.general.plugins.modules import django_check
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(django_check, __name__)
Helper.from_module(django_check, __name__, mocks=[RunCommandMock])
5 changes: 4 additions & 1 deletion tests/unit/plugins/modules/test_django_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later

---
anchors:
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
test_cases:
- id: success
input:
settings: whatever.settings
Expand All @@ -12,7 +15,7 @@
mocks:
run_command:
- command: [/testbin/python, -m, django, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
environ: *env-def
rc: 0
out: "5.1.2\n"
err: ""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_django_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


from ansible_collections.community.general.plugins.modules import django_command
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(django_command, __name__)
Helper.from_module(django_command, __name__, mocks=[RunCommandMock])
5 changes: 4 additions & 1 deletion tests/unit/plugins/modules/test_django_command.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later

---
anchors:
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
test_cases:
- id: command_success
input:
command: check
Expand All @@ -16,7 +19,7 @@
mocks:
run_command:
- command: [/testbin/python, -m, django, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
environ: *env-def
rc: 0
out: "5.1.2\n"
err: ""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_django_createcachetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


from ansible_collections.community.general.plugins.modules import django_createcachetable
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(django_createcachetable, __name__)
Helper.from_module(django_createcachetable, __name__, mocks=[RunCommandMock])
5 changes: 4 additions & 1 deletion tests/unit/plugins/modules/test_django_createcachetable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
# SPDX-License-Identifier: GPL-3.0-or-later

---
anchors:
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
test_cases:
- id: command_success
input:
settings: whatever.settings
mocks:
run_command:
- command: [/testbin/python, -m, django, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
environ: *env-def
rc: 0
out: "5.1.2\n"
err: ""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_facter_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


from ansible_collections.community.general.plugins.modules import facter_facts
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(facter_facts, __name__)
Helper.from_module(facter_facts, __name__, mocks=[RunCommandMock])
5 changes: 4 additions & 1 deletion tests/unit/plugins/modules/test_facter_facts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later

---
anchors:
environ: &env-def {check_rc: true}
test_cases:
- id: simple run
output:
ansible_facts:
Expand All @@ -14,7 +17,7 @@
mocks:
run_command:
- command: [/testbin/facter, --json]
environ: &env-def {check_rc: true}
environ: *env-def
rc: 0
out: >
{ "a": 1, "b": 2, "c": 3 }
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_gconftool2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


from ansible_collections.community.general.plugins.modules import gconftool2
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(gconftool2, __name__)
Helper.from_module(gconftool2, __name__, mocks=[RunCommandMock])
5 changes: 4 additions & 1 deletion tests/unit/plugins/modules/test_gconftool2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later

---
anchors:
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
test_cases:
- id: test_simple_element_set
input:
state: present
Expand All @@ -17,7 +20,7 @@
mocks:
run_command:
- command: [/testbin/gconftool-2, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
environ: *env-def
rc: 0
out: "3.2.6\n"
err: ""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_gconftool2_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


from ansible_collections.community.general.plugins.modules import gconftool2_info
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(gconftool2_info, __name__)
Helper.from_module(gconftool2_info, __name__, mocks=[RunCommandMock])
5 changes: 4 additions & 1 deletion tests/unit/plugins/modules/test_gconftool2_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later

---
anchors:
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
test_cases:
- id: test_simple_element_get
input:
key: /desktop/gnome/background/picture_filename
Expand All @@ -12,7 +15,7 @@
mocks:
run_command:
- command: [/testbin/gconftool-2, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
environ: *env-def
rc: 0
out: "3.2.6\n"
err: ""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_gio_mime.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


from ansible_collections.community.general.plugins.modules import gio_mime
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(gio_mime, __name__)
Helper.from_module(gio_mime, __name__, mocks=[RunCommandMock])
5 changes: 4 additions & 1 deletion tests/unit/plugins/modules/test_gio_mime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later

---
anchors:
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
test_cases:
- id: test_set_handler
input:
handler: google-chrome.desktop
Expand All @@ -14,7 +17,7 @@
mocks:
run_command:
- command: [/testbin/gio, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
environ: *env-def
rc: 0
out: "2.80.0\n"
err: ""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_krb_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


from ansible_collections.community.general.plugins.modules import krb_ticket
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(krb_ticket, __name__)
Helper.from_module(krb_ticket, __name__, mocks=[RunCommandMock])
11 changes: 8 additions & 3 deletions tests/unit/plugins/modules/test_krb_ticket.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
# SPDX-License-Identifier: GPL-3.0-or-later

---
anchors:
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
environ_data: &env-data {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true, data: cool_password}
environ_norc: &env-norc {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
test_cases:
- id: test_kinit_default
input:
state: present
Expand All @@ -13,12 +18,12 @@
mocks:
run_command:
- command: [/testbin/klist]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
environ: *env-def
rc: 1
out: ""
err: ""
- command: [/testbin/kinit]
environ: &env-data {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true, data: cool_password}
environ: *env-data
rc: 0
out: ""
err: ""
Expand Down Expand Up @@ -54,7 +59,7 @@
out: ""
err: ""
- command: [/testbin/kdestroy]
environ: &env-norc {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
environ: *env-norc
rc: 0
out: ""
err: ""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_opkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


from ansible_collections.community.general.plugins.modules import opkg
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(opkg, __name__)
Helper.from_module(opkg, __name__, mocks=[RunCommandMock])
5 changes: 4 additions & 1 deletion tests/unit/plugins/modules/test_opkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later

---
anchors:
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
test_cases:
- id: install_zlibdev
input:
name: zlib-dev
Expand All @@ -13,7 +16,7 @@
mocks:
run_command:
- command: [/testbin/opkg, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
environ: *env-def
rc: 0
out: ""
err: ""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


from ansible_collections.community.general.plugins.modules import puppet
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(puppet, __name__)
Helper.from_module(puppet, __name__, mocks=[RunCommandMock])
5 changes: 4 additions & 1 deletion tests/unit/plugins/modules/test_puppet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
# SPDX-License-Identifier: GPL-3.0-or-later

---
anchors:
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
test_cases:
- id: puppet_agent_plain
input: {}
output:
changed: false
mocks:
run_command:
- command: [/testbin/puppet, config, print, agent_disabled_lockfile]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
environ: *env-def
rc: 0
out: "blah, anything"
err: ""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys

from ansible_collections.community.general.plugins.modules import snap
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


issue_6803_status_out = """Name Version Rev Tracking Publisher Notes
Expand Down Expand Up @@ -475,4 +475,4 @@
),
]

Helper.from_spec(sys.modules[__name__], snap, TEST_CASES)
Helper.from_spec(sys.modules[__name__], snap, TEST_CASES, mocks=[RunCommandMock])
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/test_xfconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


from ansible_collections.community.general.plugins.modules import xfconf
from .helper import Helper, RunCommandMock # pylint: disable=unused-import
from .helper import Helper, RunCommandMock


Helper.from_module(xfconf, __name__)
Helper.from_module(xfconf, __name__, mocks=[RunCommandMock])
Loading
Loading