test helper: adjusted unit tests using new features (#9563)

pull/9579/head
Alexei Znamensky 2025-01-12 17:40:48 +13:00 committed by GitHub
parent 568fcea15e
commit 3dcac2b030
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 88 additions and 48 deletions

View File

@ -14,7 +14,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import cpanm 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])

View File

@ -4,6 +4,10 @@
# SPDX-License-Identifier: GPL-3.0-or-later # 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 - id: install_dancer_compatibility
input: input:
name: Dancer name: Dancer
@ -14,14 +18,14 @@
mocks: mocks:
run_command: run_command:
- command: [/testbin/cpanm, --version] - command: [/testbin/cpanm, --version]
environ: &env-def-true {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} environ: *env-def-true
rc: 0 rc: 0
out: | out: |
cpanm (App::cpanminus) version 1.7047 (/usr/local/bin/cpanm) cpanm (App::cpanminus) version 1.7047 (/usr/local/bin/cpanm)
perl version 5.041005 (/usr/local/bin/perl) perl version 5.041005 (/usr/local/bin/perl)
err: "" err: ""
- command: [/testbin/perl, -le, 'use Dancer;'] - 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 rc: 2
out: "" out: ""
err: "error, not installed" err: "error, not installed"

View File

@ -7,7 +7,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import django_check 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])

View File

@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later # 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 - id: success
input: input:
settings: whatever.settings settings: whatever.settings
@ -12,7 +15,7 @@
mocks: mocks:
run_command: run_command:
- command: [/testbin/python, -m, django, --version] - command: [/testbin/python, -m, django, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} environ: *env-def
rc: 0 rc: 0
out: "5.1.2\n" out: "5.1.2\n"
err: "" err: ""

View File

@ -7,7 +7,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import django_command 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])

View File

@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later # 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 - id: command_success
input: input:
command: check command: check
@ -16,7 +19,7 @@
mocks: mocks:
run_command: run_command:
- command: [/testbin/python, -m, django, --version] - command: [/testbin/python, -m, django, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} environ: *env-def
rc: 0 rc: 0
out: "5.1.2\n" out: "5.1.2\n"
err: "" err: ""

View File

@ -7,7 +7,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import django_createcachetable 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])

View File

@ -4,13 +4,16 @@
# SPDX-License-Identifier: GPL-3.0-or-later # 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 - id: command_success
input: input:
settings: whatever.settings settings: whatever.settings
mocks: mocks:
run_command: run_command:
- command: [/testbin/python, -m, django, --version] - command: [/testbin/python, -m, django, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} environ: *env-def
rc: 0 rc: 0
out: "5.1.2\n" out: "5.1.2\n"
err: "" err: ""

View File

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import facter_facts 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])

View File

@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
--- ---
anchors:
environ: &env-def {check_rc: true}
test_cases:
- id: simple run - id: simple run
output: output:
ansible_facts: ansible_facts:
@ -14,7 +17,7 @@
mocks: mocks:
run_command: run_command:
- command: [/testbin/facter, --json] - command: [/testbin/facter, --json]
environ: &env-def {check_rc: true} environ: *env-def
rc: 0 rc: 0
out: > out: >
{ "a": 1, "b": 2, "c": 3 } { "a": 1, "b": 2, "c": 3 }

View File

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import gconftool2 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])

View File

@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later # 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 - id: test_simple_element_set
input: input:
state: present state: present
@ -17,7 +20,7 @@
mocks: mocks:
run_command: run_command:
- command: [/testbin/gconftool-2, --version] - command: [/testbin/gconftool-2, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} environ: *env-def
rc: 0 rc: 0
out: "3.2.6\n" out: "3.2.6\n"
err: "" err: ""

View File

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import gconftool2_info 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])

View File

@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later # 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 - id: test_simple_element_get
input: input:
key: /desktop/gnome/background/picture_filename key: /desktop/gnome/background/picture_filename
@ -12,7 +15,7 @@
mocks: mocks:
run_command: run_command:
- command: [/testbin/gconftool-2, --version] - command: [/testbin/gconftool-2, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} environ: *env-def
rc: 0 rc: 0
out: "3.2.6\n" out: "3.2.6\n"
err: "" err: ""

View File

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import gio_mime 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])

View File

@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later # 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 - id: test_set_handler
input: input:
handler: google-chrome.desktop handler: google-chrome.desktop
@ -14,7 +17,7 @@
mocks: mocks:
run_command: run_command:
- command: [/testbin/gio, --version] - command: [/testbin/gio, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} environ: *env-def
rc: 0 rc: 0
out: "2.80.0\n" out: "2.80.0\n"
err: "" err: ""

View File

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import krb_ticket 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])

View File

@ -4,6 +4,11 @@
# SPDX-License-Identifier: GPL-3.0-or-later # 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 - id: test_kinit_default
input: input:
state: present state: present
@ -13,12 +18,12 @@
mocks: mocks:
run_command: run_command:
- command: [/testbin/klist] - command: [/testbin/klist]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} environ: *env-def
rc: 1 rc: 1
out: "" out: ""
err: "" err: ""
- command: [/testbin/kinit] - command: [/testbin/kinit]
environ: &env-data {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true, data: cool_password} environ: *env-data
rc: 0 rc: 0
out: "" out: ""
err: "" err: ""
@ -54,7 +59,7 @@
out: "" out: ""
err: "" err: ""
- command: [/testbin/kdestroy] - command: [/testbin/kdestroy]
environ: &env-norc {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} environ: *env-norc
rc: 0 rc: 0
out: "" out: ""
err: "" err: ""

View File

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import opkg 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])

View File

@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later # 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 - id: install_zlibdev
input: input:
name: zlib-dev name: zlib-dev
@ -13,7 +16,7 @@
mocks: mocks:
run_command: run_command:
- command: [/testbin/opkg, --version] - command: [/testbin/opkg, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} environ: *env-def
rc: 0 rc: 0
out: "" out: ""
err: "" err: ""

View File

@ -14,7 +14,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import puppet 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])

View File

@ -4,6 +4,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later # 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 - id: puppet_agent_plain
input: {} input: {}
output: output:
@ -11,7 +14,7 @@
mocks: mocks:
run_command: run_command:
- command: [/testbin/puppet, config, print, agent_disabled_lockfile] - 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 rc: 0
out: "blah, anything" out: "blah, anything"
err: "" err: ""

View File

@ -9,7 +9,7 @@ __metaclass__ = type
import sys import sys
from ansible_collections.community.general.plugins.modules import snap 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 issue_6803_status_out = """Name Version Rev Tracking Publisher Notes
@ -475,4 +475,4 @@ TEST_CASES = [
), ),
] ]
Helper.from_spec(sys.modules[__name__], snap, TEST_CASES) Helper.from_spec(sys.modules[__name__], snap, TEST_CASES, mocks=[RunCommandMock])

View File

@ -14,7 +14,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import xfconf 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])

View File

@ -4,6 +4,16 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
--- ---
anchors:
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
version_out: &version-output |
xfconf-query 4.18.1
Copyright (c) 2008-2023
The Xfce development team. All rights reserved.
Please report bugs to <https://gitlab.xfce.org/xfce/xfconf>.
test_cases:
- id: test_missing_input - id: test_missing_input
input: {} input: {}
output: output:
@ -25,15 +35,9 @@
mocks: mocks:
run_command: run_command:
- command: [/testbin/xfconf-query, --version] - command: [/testbin/xfconf-query, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} environ: *env-def
rc: 0 rc: 0
out: &version-output | out: *version-output
xfconf-query 4.18.1
Copyright (c) 2008-2023
The Xfce development team. All rights reserved.
Please report bugs to <https://gitlab.xfce.org/xfce/xfconf>.
err: "" err: ""
- command: [/testbin/xfconf-query, --channel, xfwm4, --property, /general/inactive_opacity] - command: [/testbin/xfconf-query, --channel, xfwm4, --property, /general/inactive_opacity]
environ: *env-def environ: *env-def