community.general/tests/unit/plugins/modules/test_cpanm.yaml
Alexei Znamensky 8ef77d8664
unit test helper: big revamp (#8894)
* initial commit

* multiple changes:

- TestCaseContext fixture no longer need to autouse=True
- Helper.from_module() allows extra param to specify yaml file
- test_django_check: adjusted .py and .yaml

* set fixtures per testcase

* set fixtures per testcase

* rollback to original state

* patch_ansible_module fixture

- now it works not only in parametrized functions but also directly with args

* tests/unit/plugins/modules/helper.py

- improved encapsulation, class Helper no longer knows details about test cases
- test functions no longer parametrized, that allows using test case fixtures per test function
- renamed 'context' to 'mock'

* enable Helper.from_list(), better param name 'ansible_module'

* adjusted test fiels to new helper

* remove unnecessary .license file

* fix bracket

* fix reference name

* Update tests/unit/plugins/modules/helper.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* revert to parametrized test func instead of multiple funcs

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
2024-09-28 08:17:36 +03:00

239 lines
5.3 KiB
YAML

# -*- coding: utf-8 -*-
# Copyright (c) Alexei Znamensky (russoz@gmail.com)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
---
- id: install_dancer_compatibility
input:
name: Dancer
mode: compatibility
output:
changed: true
mocks:
run_command:
- command: [/testbin/perl, -le, 'use Dancer;']
environ: &env-def-false {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
rc: 2
out: ""
err: "error, not installed"
- command: [/testbin/cpanm, Dancer]
environ: &env-def-true {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
rc: 0
out: ""
err: ""
- id: install_dancer_already_installed_compatibility
input:
name: Dancer
mode: compatibility
output:
changed: false
mocks:
run_command:
- command: [/testbin/perl, -le, 'use Dancer;']
environ: *env-def-false
rc: 0
out: ""
err: ""
- id: install_dancer
input:
name: Dancer
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, Dancer]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_distribution_file_compatibility
input:
name: MIYAGAWA/Plack-0.99_05.tar.gz
mode: compatibility
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, MIYAGAWA/Plack-0.99_05.tar.gz]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_distribution_file
input:
name: MIYAGAWA/Plack-0.99_05.tar.gz
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, MIYAGAWA/Plack-0.99_05.tar.gz]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_into_locallib
input:
name: Dancer
mode: new
locallib: /srv/webapps/my_app/extlib
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, --local-lib, /srv/webapps/my_app/extlib, Dancer]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_from_local_directory
input:
from_path: /srv/webapps/my_app/src/
mode: new
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, /srv/webapps/my_app/src/]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_into_locallib_no_unit_testing
input:
name: Dancer
notest: true
mode: new
locallib: /srv/webapps/my_app/extlib
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, --notest, --local-lib, /srv/webapps/my_app/extlib, Dancer]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_from_mirror
input:
name: Dancer
mode: new
mirror: "http://cpan.cpantesters.org/"
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, --mirror, "http://cpan.cpantesters.org/", Dancer]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_into_system_lib
input:
name: Dancer
mode: new
system_lib: true
output:
failed: true
mocks:
run_command: []
- id: install_minversion_implicit
input:
name: Dancer
mode: new
version: "1.0"
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, Dancer~1.0]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_minversion_explicit
input:
name: Dancer
mode: new
version: "~1.5"
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, Dancer~1.5]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_specific_version
input:
name: Dancer
mode: new
version: "@1.7"
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, Dancer@1.7]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_specific_version_from_file_error
input:
name: MIYAGAWA/Plack-0.99_05.tar.gz
mode: new
version: "@1.7"
output:
failed: true
msg: parameter 'version' must not be used when installing from a file
mocks:
run_command: []
- id: install_specific_version_from_directory_error
input:
from_path: ~/
mode: new
version: "@1.7"
output:
failed: true
msg: parameter 'version' must not be used when installing from a directory
mocks:
run_command: []
- id: install_specific_version_from_git_url_explicit
input:
name: "git://github.com/plack/Plack.git"
mode: new
version: "@1.7"
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, "git://github.com/plack/Plack.git@1.7"]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_specific_version_from_git_url_implicit
input:
name: "git://github.com/plack/Plack.git"
mode: new
version: "2.5"
output:
changed: true
mocks:
run_command:
- command: [/testbin/cpanm, "git://github.com/plack/Plack.git@2.5"]
environ: *env-def-true
rc: 0
out: ""
err: ""
- id: install_version_operator_from_git_url_error
input:
name: "git://github.com/plack/Plack.git"
mode: new
version: "~2.5"
output:
failed: true
msg: operator '~' not allowed in version parameter when installing from git repository
mocks:
run_command: []