1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-06-11 02:25:36 +00:00
community.general/tests/unit/plugins/modules/test_composer.yaml
Raphaël Droz 8468fea3b0
composer: config file hash to evaluate whether a change occurred (#12084)
* composer: Use config file hash to evaluate whether a change occurred (instead of unreliable output). Ensure `--working-dir` option consistently comes first (sudo-friendly)

* Update plugins/modules/composer.py

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>

* whitespace fixes + changelog fragment

* Update changelogs/fragments/composer-working-dir-and-config-sha256.yaml

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

* Update changelogs/fragments/composer-working-dir-and-config-sha256.yaml

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

* Update plugins/modules/composer.py

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>

* fragment

* ruff format  plugins/modules/composer.py

---------

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
2026-05-30 13:47:09 +02:00

124 lines
3.5 KiB
YAML

# 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
---
anchors:
help_install: &help_install
command: ["/testbin/php", "/testbin/composer", "--working-dir", "/var/www/foo", "help", "install", "--no-interaction", "--format=json"]
rc: 0
out: |
{"definition": {"options": ["a", "b", "c"]}}
err: ''
help_create_project: &help_create_project
command: ["/testbin/php", "/testbin/composer", "--working-dir", "/var/www/foo", "help", "create-project", "--no-interaction", "--format=json"]
rc: 0
out: |
{"definition": {"options": ["a", "b", "c"]}}
err: ''
run_create_project: &run_create_project
command: ["/testbin/php", "/testbin/composer", "--working-dir", "/var/www/foo", "create-project", "vendor/package"]
rc: 0
out: ''
err: ''
help_config: &help_config
command: ["/testbin/php", "/testbin/composer", "--working-dir", "/var/www/foo", "help", "config", "--no-interaction", "--format=json"]
rc: 0
out: |
{"definition": {"options": ["a", "b", "c"]}}
err: ''
test_cases:
- id: composer
input:
command: install
working_dir: "/var/www/foo"
output:
changed: true
mocks:
run_command:
- *help_install
- command: ["/testbin/php", "/testbin/composer", "--working-dir", "/var/www/foo", "install"]
rc: 0
out: ''
err: ''
- id: create_project_runs
input:
command: create-project
arguments: "vendor/package"
working_dir: "/var/www/foo"
output:
changed: true
mocks:
os_path_exists:
return_value: false
run_command:
- *help_create_project
- *run_create_project
- id: create_project_skips_when_exists
input:
command: create-project
arguments: "vendor/package"
working_dir: "/var/www/foo"
output:
changed: false
mocks:
os_path_exists:
return_value: true
run_command:
- *help_create_project
- id: create_project_force
input:
command: create-project
arguments: "vendor/package"
working_dir: "/var/www/foo"
force: true
output:
changed: true
mocks:
os_path_exists:
return_value: true
run_command:
- *help_create_project
- *run_create_project
- id: config_no_change
input:
command: config
arguments: "setting-key setting-value"
working_dir: "/var/www/foo"
output:
changed: false
mocks:
os_path_isfile:
return_value: true
sha256:
return_values: ["hash1", "hash2", "hash1", "hash2"]
run_command:
- *help_config
- command: ["/testbin/php", "/testbin/composer", "--working-dir", "/var/www/foo", "config", "setting-key", "setting-value"]
rc: 0
out: ''
err: ''
- id: config_changed
input:
command: config
arguments: "setting-key setting-value"
working_dir: "/var/www/foo"
output:
changed: true
mocks:
os_path_isfile:
return_value: true
sha256:
return_values: ["hash1", "hash2", "hash1_changed", "hash2"]
run_command:
- *help_config
- command: ["/testbin/php", "/testbin/composer", "--working-dir", "/var/www/foo", "config", "setting-key", "setting-value"]
rc: 0
out: ''
err: ''