Skip to content

Commit

Permalink
test: check for api error code when possible (ansible-collections#486)
Browse files Browse the repository at this point in the history
##### SUMMARY

Ensure the error code is correct and replace the error message check in
some cases.
  • Loading branch information
jooola authored Apr 4, 2024
1 parent 7776905 commit 8738f36
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/integration/targets/firewall/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
ansible.builtin.assert:
that:
- result is failed
- '"is still in use" in result.msg'
- result.failure.code == "resource_in_use"

- name: Test delete with force
hetzner.hcloud.firewall:
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/targets/floating_ip/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
assert:
that:
- result is failed
- result.failure.code == "invalid_input"
- result.msg == "invalid input in fields 'server', 'home_location'"

- name: test create Floating IP with check mode
Expand Down Expand Up @@ -371,7 +372,8 @@
assert:
that:
- result is failed
- 'result.msg == "Floating IP deletion is protected"'
- result.failure.code == "protected"
- result.msg == "Floating IP deletion is protected"

- name: test update Floating IP delete protection
hetzner.hcloud.floating_ip:
Expand Down Expand Up @@ -459,7 +461,8 @@
assert:
that:
- result is failed
- 'result.msg == "Floating IP deletion is protected"'
- result.failure.code == "protected"
- result.msg == "Floating IP deletion is protected"

- name: test update Floating IP delete protection
hetzner.hcloud.floating_ip:
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/targets/load_balancer/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
ansible.builtin.assert:
that:
- result is failed
- 'result.msg == "load balancer deletion is protected"'
- result.failure.code == "protected"
- result.msg == "load balancer deletion is protected"

- name: Test update delete_protection
hetzner.hcloud.load_balancer:
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/targets/network/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
ansible.builtin.assert:
that:
- result is failed
- 'result.msg == "network deletion is protected"'
- result.failure.code == "protected"
- result.msg == "network deletion is protected"

- name: Test update delete protection
hetzner.hcloud.network:
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/targets/primary_ip/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
ansible.builtin.assert:
that:
- result is failed
- '"Primary IP deletion is protected" in result.msg'
- result.failure.code == "protected"
- result.msg == "Primary IP deletion is protected"

- name: Test update delete protection
hetzner.hcloud.primary_ip:
Expand Down
9 changes: 6 additions & 3 deletions tests/integration/targets/server/tasks/test_basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@
assert:
that:
- result is failed
- 'result.msg == "server deletion is protected"'
- result.failure.code == "protected"
- result.msg == "server deletion is protected"

- name: test rebuild server fails if it is protected
hetzner.hcloud.server:
Expand All @@ -328,7 +329,8 @@
assert:
that:
- result is failed
- 'result.msg == "server rebuild is protected"'
- result.failure.code == "protected"
- result.msg == "server rebuild is protected"

- name: test remove server protection
hetzner.hcloud.server:
Expand Down Expand Up @@ -585,7 +587,8 @@
assert:
that:
- result is failed
- 'result.msg == "server deletion is protected"'
- result.failure.code == "protected"
- result.msg == "server deletion is protected"

- name: remove protection from server
hetzner.hcloud.server:
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/targets/server/tasks/test_firewalls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
assert:
that:
- result is failed
- 'result.msg == "firewall not-existing was not found"'
- result.failure.code == "not_found"
- result.msg == "firewall not-existing was not found"

- name: setup create firewalls
hetzner.hcloud.firewall:
name: "{{ item }}"
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/targets/server/tasks/test_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
assert:
that:
- result is failed
- 'result.msg == "server_type not-existing-server-type was not found"'
- result.failure.code == "not_found"
- result.msg == "server_type not-existing-server-type was not found"

- name: test create server with not existing image
hetzner.hcloud.server:
Expand All @@ -48,4 +49,5 @@
assert:
that:
- result is failed
- 'result.msg == "Image my-not-existing-image-20.04 was not found"'
- result.failure.code == "not_found"
- result.msg == "Image my-not-existing-image-20.04 was not found"
3 changes: 2 additions & 1 deletion tests/integration/targets/ssh_key/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@
assert:
that:
- result is failed
- 'result.msg == "SSH key with the same fingerprint already exists"'
- result.failure.code == "uniqueness_error"
- result.msg == "SSH key with the same fingerprint already exists"

- name: test delete ssh key
hetzner.hcloud.ssh_key:
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/targets/volume/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@
assert:
that:
- result is failed
- 'result.msg == "volume deletion is protected"'
- result.failure.code == "protected"
- result.msg == "volume deletion is protected"

- name: test update Volume delete protection
hetzner.hcloud.volume:
Expand Down Expand Up @@ -254,7 +255,8 @@
assert:
that:
- result is failed
- 'result.msg == "volume deletion is protected"'
- result.failure.code == "protected"
- result.msg == "volume deletion is protected"

- name: test update Volume delete protection
hetzner.hcloud.volume:
Expand Down

0 comments on commit 8738f36

Please sign in to comment.