mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-14 11:57:40 +00:00
[PR #12084/8468fea3 backport][stable-12] composer: config file hash to evaluate whether a change occurred (#12131)
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
* whitespace fixes + changelog fragment
* Update changelogs/fragments/composer-working-dir-and-config-sha256.yaml
* Update changelogs/fragments/composer-working-dir-and-config-sha256.yaml
* Update plugins/modules/composer.py
* fragment
* ruff format plugins/modules/composer.py
---------
(cherry picked from commit 8468fea3b0)
Co-authored-by: Raphaël Droz <raphael@droz.eu>
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
fee35e6ec2
commit
410383e95f
4 changed files with 143 additions and 8 deletions
|
|
@ -22,4 +22,31 @@ class OsPathExistsMock(TestCaseMock):
|
|||
pass
|
||||
|
||||
|
||||
UTHelper.from_module(composer, __name__, mocks=[RunCommandMock, OsPathExistsMock])
|
||||
class OsPathIsfileMock(TestCaseMock):
|
||||
name = "os_path_isfile"
|
||||
|
||||
def setup(self, mocker):
|
||||
mocker.patch("os.path.isfile", return_value=self.mock_specs.get("return_value", False))
|
||||
|
||||
def check(self, test_case, results):
|
||||
pass
|
||||
|
||||
|
||||
class Sha256Mock(TestCaseMock):
|
||||
name = "sha256"
|
||||
|
||||
def setup(self, mocker):
|
||||
values = list(self.mock_specs.get("return_values", []))
|
||||
|
||||
def _sha256_side_effect(path):
|
||||
if values:
|
||||
return values.pop(0)
|
||||
return "default_hash"
|
||||
|
||||
mocker.patch("ansible.module_utils.basic.AnsibleModule.sha256", side_effect=_sha256_side_effect)
|
||||
|
||||
def check(self, test_case, results):
|
||||
pass
|
||||
|
||||
|
||||
UTHelper.from_module(composer, __name__, mocks=[RunCommandMock, OsPathExistsMock, OsPathIsfileMock, Sha256Mock])
|
||||
|
|
|
|||
|
|
@ -5,22 +5,28 @@
|
|||
---
|
||||
anchors:
|
||||
help_install: &help_install
|
||||
command: ["/testbin/php", "/testbin/composer", "help", "install", "--working-dir", "/var/www/foo", "--no-interaction", "--format=json"]
|
||||
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", "help", "create-project", "--working-dir", "/var/www/foo", "--no-interaction", "--format=json"]
|
||||
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", "create-project", "--working-dir", "/var/www/foo", "vendor/package"]
|
||||
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
|
||||
|
|
@ -32,7 +38,7 @@ test_cases:
|
|||
mocks:
|
||||
run_command:
|
||||
- *help_install
|
||||
- command: ["/testbin/php", "/testbin/composer", "install", "--working-dir", "/var/www/foo"]
|
||||
- command: ["/testbin/php", "/testbin/composer", "--working-dir", "/var/www/foo", "install"]
|
||||
rc: 0
|
||||
out: ''
|
||||
err: ''
|
||||
|
|
@ -78,3 +84,41 @@ test_cases:
|
|||
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: ''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue