From 8738f369d3043b48cb202cd4d77491ed1618b793 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Thu, 4 Apr 2024 11:55:45 +0200 Subject: [PATCH] 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. --- tests/integration/targets/firewall/tasks/test.yml | 2 +- tests/integration/targets/floating_ip/tasks/test.yml | 7 +++++-- tests/integration/targets/load_balancer/tasks/test.yml | 3 ++- tests/integration/targets/network/tasks/test.yml | 3 ++- tests/integration/targets/primary_ip/tasks/test.yml | 3 ++- tests/integration/targets/server/tasks/test_basic.yml | 9 ++++++--- .../integration/targets/server/tasks/test_firewalls.yml | 4 +++- .../integration/targets/server/tasks/test_validation.yml | 6 ++++-- tests/integration/targets/ssh_key/tasks/test.yml | 3 ++- tests/integration/targets/volume/tasks/test.yml | 6 ++++-- 10 files changed, 31 insertions(+), 15 deletions(-) diff --git a/tests/integration/targets/firewall/tasks/test.yml b/tests/integration/targets/firewall/tasks/test.yml index 57059848..8179bc61 100644 --- a/tests/integration/targets/firewall/tasks/test.yml +++ b/tests/integration/targets/firewall/tasks/test.yml @@ -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: diff --git a/tests/integration/targets/floating_ip/tasks/test.yml b/tests/integration/targets/floating_ip/tasks/test.yml index cf6330e0..23f29b22 100644 --- a/tests/integration/targets/floating_ip/tasks/test.yml +++ b/tests/integration/targets/floating_ip/tasks/test.yml @@ -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: diff --git a/tests/integration/targets/load_balancer/tasks/test.yml b/tests/integration/targets/load_balancer/tasks/test.yml index 343f1567..3b7de5b1 100644 --- a/tests/integration/targets/load_balancer/tasks/test.yml +++ b/tests/integration/targets/load_balancer/tasks/test.yml @@ -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: diff --git a/tests/integration/targets/network/tasks/test.yml b/tests/integration/targets/network/tasks/test.yml index 5f26d1f5..b814ceb1 100644 --- a/tests/integration/targets/network/tasks/test.yml +++ b/tests/integration/targets/network/tasks/test.yml @@ -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: diff --git a/tests/integration/targets/primary_ip/tasks/test.yml b/tests/integration/targets/primary_ip/tasks/test.yml index 09e9790a..84fd6a31 100644 --- a/tests/integration/targets/primary_ip/tasks/test.yml +++ b/tests/integration/targets/primary_ip/tasks/test.yml @@ -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: diff --git a/tests/integration/targets/server/tasks/test_basic.yml b/tests/integration/targets/server/tasks/test_basic.yml index 1e94d67a..879e2d67 100644 --- a/tests/integration/targets/server/tasks/test_basic.yml +++ b/tests/integration/targets/server/tasks/test_basic.yml @@ -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: diff --git a/tests/integration/targets/server/tasks/test_firewalls.yml b/tests/integration/targets/server/tasks/test_firewalls.yml index 896a6c5c..230df46d 100644 --- a/tests/integration/targets/server/tasks/test_firewalls.yml +++ b/tests/integration/targets/server/tasks/test_firewalls.yml @@ -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 }}" diff --git a/tests/integration/targets/server/tasks/test_validation.yml b/tests/integration/targets/server/tasks/test_validation.yml index d4e0ef8b..e051816f 100644 --- a/tests/integration/targets/server/tasks/test_validation.yml +++ b/tests/integration/targets/server/tasks/test_validation.yml @@ -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" diff --git a/tests/integration/targets/ssh_key/tasks/test.yml b/tests/integration/targets/ssh_key/tasks/test.yml index 41b9c351..e314266a 100644 --- a/tests/integration/targets/ssh_key/tasks/test.yml +++ b/tests/integration/targets/ssh_key/tasks/test.yml @@ -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: diff --git a/tests/integration/targets/volume/tasks/test.yml b/tests/integration/targets/volume/tasks/test.yml index 41637162..9b586e05 100644 --- a/tests/integration/targets/volume/tasks/test.yml +++ b/tests/integration/targets/volume/tasks/test.yml @@ -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: