From 630e00705bbb05bf72c7248e961c2d00c16a5e8a Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 13 Feb 2024 02:39:23 +0100 Subject: [PATCH] tests: add error tests --- providers/dns/abion/internal/client_test.go | 43 +++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/providers/dns/abion/internal/client_test.go b/providers/dns/abion/internal/client_test.go index e6a2d70f14a..b81c7e9d851 100644 --- a/providers/dns/abion/internal/client_test.go +++ b/providers/dns/abion/internal/client_test.go @@ -137,6 +137,33 @@ func TestUpdateZone(t *testing.T) { assert.Equal(t, expected, zone) } +func TestUpdateZone_error(t *testing.T) { + domain := "example.com" + + client := setupTest(t, http.MethodPatch, "/v1/zones/"+domain, http.StatusUnauthorized, "error.json") + + patch := ZoneRequest{ + Data: Zone{ + Type: "zone", + ID: domain, + Attributes: Attributes{ + Records: map[string]map[string][]Record{ + "_acme-challenge.test": { + "TXT": []Record{ + {Data: "test"}, + {Data: "test1"}, + {Data: "test2"}, + }, + }, + }, + }, + }, + } + + _, err := client.UpdateZone(context.Background(), domain, patch) + require.EqualError(t, err, "could not update zone example.com: api error: status=401, message=Authentication Error") +} + func TestGetZones(t *testing.T) { client := setupTest(t, http.MethodGet, "/v1/zones/", http.StatusOK, "zones.json") @@ -171,6 +198,13 @@ func TestGetZones(t *testing.T) { assert.Equal(t, expected, zones) } +func TestGetZones_error(t *testing.T) { + client := setupTest(t, http.MethodGet, "/v1/zones/", http.StatusUnauthorized, "error.json") + + _, err := client.GetZones(context.Background(), nil) + require.EqualError(t, err, "could not get zones: api error: status=401, message=Authentication Error") +} + func TestGetZone(t *testing.T) { domain := "example.com" @@ -227,3 +261,12 @@ func TestGetZone(t *testing.T) { assert.Equal(t, expected, zones) } + +func TestGetZone_error(t *testing.T) { + domain := "example.com" + + client := setupTest(t, http.MethodGet, "/v1/zones/"+domain, http.StatusUnauthorized, "error.json") + + _, err := client.GetZone(context.Background(), domain) + require.EqualError(t, err, "could not get zone example.com: api error: status=401, message=Authentication Error") +}