summaryrefslogtreecommitdiffstats
path: root/awx_collection
diff options
context:
space:
mode:
authormatt <l3acon@gmail.com>2023-03-23 22:44:00 +0100
committermatt <l3acon@gmail.com>2023-03-23 22:44:00 +0100
commitb0c416334fb3abc5e820667d65167fb374164c39 (patch)
tree66f1a76ff35f0f6bdfdf8e8805b12bf4d388d9cf /awx_collection
parentexit from module (diff)
downloadawx-b0c416334fb3abc5e820667d65167fb374164c39.tar.xz
awx-b0c416334fb3abc5e820667d65167fb374164c39.zip
add test coverage
Diffstat (limited to 'awx_collection')
-rw-r--r--awx_collection/test/awx/test_credential.py17
-rw-r--r--awx_collection/tests/integration/targets/credential/tasks/main.yml54
2 files changed, 71 insertions, 0 deletions
diff --git a/awx_collection/test/awx/test_credential.py b/awx_collection/test/awx/test_credential.py
index f12594bee8..65e68538f1 100644
--- a/awx_collection/test/awx/test_credential.py
+++ b/awx_collection/test/awx/test_credential.py
@@ -132,3 +132,20 @@ def test_secret_field_write_twice(run_module, organization, admin_user, cred_typ
else:
assert result.get('changed') is False, result
assert Credential.objects.get(id=result['id']).get_input('token') == val1
+
+@pytest.mark.django_db
+@pytest.mark.parametrize('state', ('present', 'absent', 'exists'))
+def test_credential_state(run_module, organization, admin_user, cred_type, state):
+ for state in ('present', 'absent', 'exists'):
+ result = run_module(
+ 'credential',
+ dict(
+ name='Galaxy Token for Steve',
+ organization=organization.name,
+ credential_type=cred_type.name,
+ inputs={'token': '7rEZK38DJl58A7RxA6EC7lLvUHbBQ1'},
+ state=state,
+ ),
+ admin_user,
+ )
+ assert not result.get('failed', False), result.get('msg', result)
diff --git a/awx_collection/tests/integration/targets/credential/tasks/main.yml b/awx_collection/tests/integration/targets/credential/tasks/main.yml
index 57b2168f25..42d22d8bc7 100644
--- a/awx_collection/tests/integration/targets/credential/tasks/main.yml
+++ b/awx_collection/tests/integration/targets/credential/tasks/main.yml
@@ -178,6 +178,60 @@
that:
- result is changed
+- name: Delete an SSH credential
+ credential:
+ name: "{{ ssh_cred_name2 }}"
+ organization: Default
+ state: absent
+ credential_type: Machine
+ register: result
+
+- assert:
+ that:
+ - "result is changed"
+
+- name: Ensure existence of SSH credential
+ credential:
+ name: "{{ ssh_cred_name2 }}"
+ organization: Default
+ state: exists
+ credential_type: Machine
+ description: An example SSH awx.awx.credential
+ inputs:
+ username: joe
+ password: secret
+ become_method: sudo
+ become_username: superuser
+ become_password: supersecret
+ ssh_key_data: "{{ ssh_key_data }}"
+ ssh_key_unlock: "passphrase"
+ register: result
+
+- assert:
+ that:
+ - result is changed
+
+- name: Ensure existence of SSH credential, not updating any inputs
+ credential:
+ name: "{{ ssh_cred_name2 }}"
+ organization: Default
+ state: exists
+ credential_type: Machine
+ description: An example SSH awx.awx.credential
+ inputs:
+ username: joe
+ password: no-update-secret
+ become_method: sudo
+ become_username: some-other-superuser
+ become_password: some-other-secret
+ ssh_key_data: "{{ ssh_key_data }}"
+ ssh_key_unlock: "another-pass-phrase"
+ register: result
+
+- assert:
+ that:
+ - result is not changed
+
- name: Create an invalid SSH credential (passphrase required)
credential:
name: SSH Credential