test: check for api error code when possible (#486)

##### SUMMARY

Ensure the error code is correct and replace the error message check in
some cases.
This commit is contained in:
Jonas L 2024-04-04 11:55:45 +02:00 committed by GitHub
parent 7776905321
commit 8738f369d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 31 additions and 15 deletions

View file

@ -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:

View file

@ -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
@ -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:
@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:
@ -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:
@ -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:

View file

@ -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 }}"

View file

@ -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:
@ -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"

View file

@ -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:

View file

@ -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:
@ -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: