From 95af323f667e4355a87e273194ae254d381120e9 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 8 Mar 2026 21:05:57 +0100 Subject: [PATCH] tests: improve fixtures --- providers/dns/eurodns/eurodns_test.go | 2 +- providers/dns/eurodns/internal/client_test.go | 260 +++++++++++------- .../eurodns/internal/fixtures/zone_add.json | 95 +------ .../fixtures/zone_add_empty_forwards.json | 13 +- .../fixtures/zone_add_validate_ko.json | 139 ++++++++++ .../fixtures/zone_add_validate_ok.json | 49 ++++ .../eurodns/internal/fixtures/zone_get.json | 107 +------ .../internal/fixtures/zone_remove.json | 95 +------ providers/dns/eurodns/internal/types.go | 14 +- 9 files changed, 378 insertions(+), 396 deletions(-) create mode 100644 providers/dns/eurodns/internal/fixtures/zone_add_validate_ko.json create mode 100644 providers/dns/eurodns/internal/fixtures/zone_add_validate_ok.json diff --git a/providers/dns/eurodns/eurodns_test.go b/providers/dns/eurodns/eurodns_test.go index e9644535c..abbb4717e 100644 --- a/providers/dns/eurodns/eurodns_test.go +++ b/providers/dns/eurodns/eurodns_test.go @@ -180,7 +180,7 @@ func TestDNSProvider_Present(t *testing.T) { servermock.ResponseFromInternal("zone_get.json"), ). Route("POST /example.com/check", - servermock.ResponseFromInternal("zone_get.json"), + servermock.ResponseFromInternal("zone_add_validate_ok.json"), servermock.CheckRequestJSONBodyFromInternal("zone_add.json"), ). Route("PUT /example.com", diff --git a/providers/dns/eurodns/internal/client_test.go b/providers/dns/eurodns/internal/client_test.go index ca21cac40..691ed9a41 100644 --- a/providers/dns/eurodns/internal/client_test.go +++ b/providers/dns/eurodns/internal/client_test.go @@ -44,7 +44,15 @@ func TestClient_GetZone(t *testing.T) { zone, err := client.GetZone(context.Background(), "example.com") require.NoError(t, err) - assert.Equal(t, fakeZone(), zone) + expected := &Zone{ + Name: "example.com", + DomainConnect: true, + Records: slices.Concat([]Record{fakeARecord()}), + URLForwards: []URLForward{fakeURLForward()}, + MailForwards: []MailForward{fakeMailForward()}, + } + + assert.Equal(t, expected, zone) } func TestClient_GetZone_error(t *testing.T) { @@ -77,7 +85,15 @@ func TestClient_SaveZone(t *testing.T) { TTL: 600, } - err := client.SaveZone(context.Background(), "example.com", fakeZone(record)) + zone := &Zone{ + Name: "example.com", + DomainConnect: true, + Records: []Record{fakeARecord(), record}, + URLForwards: []URLForward{fakeURLForward()}, + MailForwards: []MailForward{fakeMailForward()}, + } + + err := client.SaveZone(context.Background(), "example.com", zone) require.NoError(t, err) } @@ -97,7 +113,13 @@ func TestClient_SaveZone_emptyForwards(t *testing.T) { TTL: 600, } - err := client.SaveZone(context.Background(), "example.com", fakeZoneSlim(record)) + zone := &Zone{ + Name: "example.com", + DomainConnect: true, + Records: slices.Concat([]Record{fakeARecord(), record}), + } + + err := client.SaveZone(context.Background(), "example.com", zone) require.NoError(t, err) } @@ -109,7 +131,15 @@ func TestClient_SaveZone_error(t *testing.T) { ). Build(t) - err := client.SaveZone(context.Background(), "example.com", fakeZone()) + zone := &Zone{ + Name: "example.com", + DomainConnect: true, + Records: []Record{fakeARecord()}, + URLForwards: []URLForward{fakeURLForward()}, + MailForwards: []MailForward{fakeMailForward()}, + } + + err := client.SaveZone(context.Background(), "example.com", zone) require.Error(t, err) require.EqualError(t, err, "401: INVALID_API_KEY: Invalid API Key") @@ -118,7 +148,7 @@ func TestClient_SaveZone_error(t *testing.T) { func TestClient_ValidateZone(t *testing.T) { client := mockBuilder(). Route("POST /example.com/check", - servermock.ResponseFromFixture("zone_add.json"), + servermock.ResponseFromFixture("zone_add_validate_ok.json"), servermock.CheckRequestJSONBodyFromFixture("zone_add.json"), ). Build(t) @@ -130,10 +160,65 @@ func TestClient_ValidateZone(t *testing.T) { TTL: 600, } - zone, err := client.ValidateZone(context.Background(), "example.com", fakeZone(record)) + zone := &Zone{ + Name: "example.com", + DomainConnect: true, + Records: []Record{fakeARecord(), record}, + URLForwards: []URLForward{fakeURLForward()}, + MailForwards: []MailForward{fakeMailForward()}, + } + + zone, err := client.ValidateZone(context.Background(), "example.com", zone) require.NoError(t, err) - assert.Equal(t, fakeZone(record), zone) + expected := &Zone{ + Name: "example.com", + DomainConnect: true, + Records: []Record{fakeARecord(), record}, + URLForwards: []URLForward{fakeURLForward()}, + MailForwards: []MailForward{fakeMailForward()}, + Report: &Report{IsValid: true}, + } + + assert.Equal(t, expected, zone) +} + +func TestClient_ValidateZone_report(t *testing.T) { + client := mockBuilder(). + Route("POST /example.com/check", + servermock.ResponseFromFixture("zone_add_validate_ko.json"), + servermock.CheckRequestJSONBodyFromFixture("zone_add.json"), + ). + Build(t) + + record := Record{ + Type: "TXT", + Host: "_acme-challenge", + RData: "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY", + TTL: 600, + } + + zone := &Zone{ + Name: "example.com", + DomainConnect: true, + Records: []Record{fakeARecord(), record}, + URLForwards: []URLForward{fakeURLForward()}, + MailForwards: []MailForward{fakeMailForward()}, + } + + zone, err := client.ValidateZone(context.Background(), "example.com", zone) + require.NoError(t, err) + + expected := &Zone{ + Name: "example.com", + DomainConnect: true, + Records: []Record{fakeARecord(), record}, + URLForwards: []URLForward{fakeURLForward()}, + MailForwards: []MailForward{fakeMailForward()}, + Report: fakeReport(), + } + + assert.Equal(t, expected, zone) } func TestClient_ValidateZone_error(t *testing.T) { @@ -144,119 +229,80 @@ func TestClient_ValidateZone_error(t *testing.T) { ). Build(t) - _, err := client.ValidateZone(context.Background(), "example.com", fakeZone()) + zone := &Zone{ + Name: "example.com", + DomainConnect: true, + Records: []Record{fakeARecord()}, + URLForwards: []URLForward{fakeURLForward()}, + MailForwards: []MailForward{fakeMailForward()}, + } + + _, err := client.ValidateZone(context.Background(), "example.com", zone) require.Error(t, err) require.EqualError(t, err, "401: INVALID_API_KEY: Invalid API Key") } -func fakeZone(records ...Record) *Zone { - rs := []Record{{ +func fakeARecord() Record { + return Record{ + ID: 1000, Type: "A", - Host: "string", + Host: "@", + TTL: 600, RData: "string", Updated: ptr.Pointer(true), Locked: ptr.Pointer(true), IsDynDNS: ptr.Pointer(true), Proxy: "ON", - }} - - return &Zone{ - Name: "string", - DomainConnect: true, - Records: slices.Concat(rs, records), - URLForwards: []URLForward{{ - ForwardType: "FRAME", - Host: "string", - URL: "string", - Title: "string", - Keywords: "string", - Description: "string", - Updated: ptr.Pointer(true), - }}, - MailForwards: []MailForward{{ - Source: "string", - Destination: "string", - Updated: ptr.Pointer(true), - }}, - Report: &Report{ - IsValid: true, - RecordErrors: []RecordError{{ - Messages: []string{"string"}, - Severity: "ERROR", - Record: &Record{ - Type: "A", - Host: "string", - RData: "string", - Updated: ptr.Pointer(true), - Locked: ptr.Pointer(true), - IsDynDNS: ptr.Pointer(true), - Proxy: "ON", - }, - }}, - URLForwardErrors: []URLForwardError{{ - Messages: []string{"string"}, - Severity: "ERROR", - URLForward: &URLForward{ - ForwardType: "FRAME", - Host: "string", - URL: "string", - Title: "string", - Keywords: "string", - Description: "string", - Updated: ptr.Pointer(true), - }, - }}, - MailForwardErrors: []MailForwardError{{ - Messages: []string{"string"}, - MailForward: &MailForward{ - Source: "string", - Destination: "string", - Updated: ptr.Pointer(true), - }, - Severity: "ERROR", - }}, - ZoneErrors: []ZoneError{{ - Message: "string", - Severity: "ERROR", - Records: []Record{{ - Type: "A", - Host: "string", - RData: "string", - Updated: ptr.Pointer(true), - Locked: ptr.Pointer(true), - IsDynDNS: ptr.Pointer(true), - Proxy: "ON", - }}, - URLForwards: []URLForward{{ - ForwardType: "FRAME", - Host: "string", - URL: "string", - Title: "string", - Keywords: "string", - Description: "string", - Updated: ptr.Pointer(true), - }}, - MailForwards: []MailForward{{ - Source: "string", - Destination: "string", - Updated: ptr.Pointer(true), - }}, - }}, - }, } } -func fakeZoneSlim(records ...Record) *Zone { - rs := []Record{{ - Type: "A", - Host: "string", - RData: "string", - }} - - return &Zone{ - Name: "string", - DomainConnect: true, - Records: slices.Concat(rs, records), +func fakeURLForward() URLForward { + return URLForward{ + ID: 2000, + ForwardType: "FRAME", + Host: "string", + URL: "string", + Title: "string", + Keywords: "string", + Description: "string", + Updated: ptr.Pointer(true), + } +} + +func fakeMailForward() MailForward { + return MailForward{ + ID: 3000, + Source: "string", + Destination: "string", + Updated: ptr.Pointer(true), + } +} + +func fakeReport() *Report { + return &Report{ + IsValid: false, + RecordErrors: []RecordError{{ + Messages: []string{"string"}, + Severity: "ERROR", + Record: fakeARecord(), + }}, + URLForwardErrors: []URLForwardError{{ + Messages: []string{"string"}, + Severity: "ERROR", + URLForward: fakeURLForward(), + }}, + MailForwardErrors: []MailForwardError{{ + Messages: []string{"string"}, + MailForward: fakeMailForward(), + Severity: "ERROR", + }}, + ZoneErrors: []ZoneError{{ + Message: "string", + Severity: "ERROR", + Records: []Record{fakeARecord()}, + URLForwards: []URLForward{fakeURLForward()}, + MailForwards: []MailForward{fakeMailForward()}, + }}, } } diff --git a/providers/dns/eurodns/internal/fixtures/zone_add.json b/providers/dns/eurodns/internal/fixtures/zone_add.json index 1b75a8914..db8142357 100644 --- a/providers/dns/eurodns/internal/fixtures/zone_add.json +++ b/providers/dns/eurodns/internal/fixtures/zone_add.json @@ -1,10 +1,12 @@ { - "name": "string", + "name": "example.com", "domainConnect": true, "records": [ { + "id": 1000, "type": "A", - "host": "string", + "host": "@", + "ttl": 600, "rdata": "string", "updated": true, "locked": true, @@ -23,6 +25,7 @@ ], "urlForwards": [ { + "id": 2000, "forwardType": "FRAME", "host": "string", "url": "string", @@ -34,94 +37,10 @@ ], "mailForwards": [ { + "id": 3000, "source": "string", "destination": "string", "updated": true } - ], - "report": { - "isValid": true, - "recordErrors": [ - { - "messages": [ - "string" - ], - "record": { - "type": "A", - "host": "string", - "rdata": "string", - "updated": true, - "locked": true, - "isDynDns": true, - "proxy": "ON" - }, - "severity": "ERROR" - } - ], - "urlForwardErrors": [ - { - "messages": [ - "string" - ], - "urlForward": { - "forwardType": "FRAME", - "host": "string", - "url": "string", - "title": "string", - "keywords": "string", - "description": "string", - "updated": true - }, - "severity": "ERROR" - } - ], - "mailForwardErrors": [ - { - "messages": [ - "string" - ], - "mailForward": { - "source": "string", - "destination": "string", - "updated": true - }, - "severity": "ERROR" - } - ], - "zoneErrors": [ - { - "message": "string", - "records": [ - { - "type": "A", - "host": "string", - "rdata": "string", - "updated": true, - "locked": true, - "isDynDns": true, - "proxy": "ON" - } - ], - "urlForwards": [ - { - "forwardType": "FRAME", - "host": "string", - "url": "string", - "title": "string", - "keywords": "string", - "description": "string", - "updated": true - } - ], - "mailForwards": [ - { - "source": "string", - "destination": "string", - "updated": true - } - ], - "severity": "ERROR" - } - ] - } + ] } diff --git a/providers/dns/eurodns/internal/fixtures/zone_add_empty_forwards.json b/providers/dns/eurodns/internal/fixtures/zone_add_empty_forwards.json index 67dbe2836..64f8530c9 100644 --- a/providers/dns/eurodns/internal/fixtures/zone_add_empty_forwards.json +++ b/providers/dns/eurodns/internal/fixtures/zone_add_empty_forwards.json @@ -1,14 +1,17 @@ { - "name": "string", + "name": "example.com", "domainConnect": true, "records": [ { + "id": 1000, "type": "A", - "host": "string", + "host": "@", + "ttl": 600, "rdata": "string", - "updated": null, - "locked": null, - "isDynDns": null + "updated": true, + "locked": true, + "isDynDns": true, + "proxy": "ON" }, { "type": "TXT", diff --git a/providers/dns/eurodns/internal/fixtures/zone_add_validate_ko.json b/providers/dns/eurodns/internal/fixtures/zone_add_validate_ko.json new file mode 100644 index 000000000..9f3aa095b --- /dev/null +++ b/providers/dns/eurodns/internal/fixtures/zone_add_validate_ko.json @@ -0,0 +1,139 @@ +{ + "name": "example.com", + "domainConnect": true, + "records": [ + { + "id": 1000, + "type": "A", + "host": "@", + "ttl": 600, + "rdata": "string", + "updated": true, + "locked": true, + "isDynDns": true, + "proxy": "ON" + }, + { + "type": "TXT", + "host": "_acme-challenge", + "ttl": 600, + "rdata": "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY", + "updated": null, + "locked": null, + "isDynDns": null + } + ], + "urlForwards": [ + { + "id": 2000, + "forwardType": "FRAME", + "host": "string", + "url": "string", + "title": "string", + "keywords": "string", + "description": "string", + "updated": true + } + ], + "mailForwards": [ + { + "id": 3000, + "source": "string", + "destination": "string", + "updated": true + } + ], + "report": { + "isValid": false, + "recordErrors": [ + { + "messages": [ + "string" + ], + "record": { + "id": 1000, + "type": "A", + "host": "@", + "ttl": 600, + "rdata": "string", + "updated": true, + "locked": true, + "isDynDns": true, + "proxy": "ON" + }, + "severity": "ERROR" + } + ], + "urlForwardErrors": [ + { + "messages": [ + "string" + ], + "urlForward": { + "id": 2000, + "forwardType": "FRAME", + "host": "string", + "url": "string", + "title": "string", + "keywords": "string", + "description": "string", + "updated": true + }, + "severity": "ERROR" + } + ], + "mailForwardErrors": [ + { + "messages": [ + "string" + ], + "mailForward": { + "id": 3000, + "source": "string", + "destination": "string", + "updated": true + }, + "severity": "ERROR" + } + ], + "zoneErrors": [ + { + "message": "string", + "records": [ + { + "id": 1000, + "type": "A", + "host": "@", + "ttl": 600, + "rdata": "string", + "updated": true, + "locked": true, + "isDynDns": true, + "proxy": "ON" + } + ], + "urlForwards": [ + { + "id": 2000, + "forwardType": "FRAME", + "host": "string", + "url": "string", + "title": "string", + "keywords": "string", + "description": "string", + "updated": true + } + ], + "mailForwards": [ + { + "id": 3000, + "source": "string", + "destination": "string", + "updated": true + } + ], + "severity": "ERROR" + } + ] + } +} diff --git a/providers/dns/eurodns/internal/fixtures/zone_add_validate_ok.json b/providers/dns/eurodns/internal/fixtures/zone_add_validate_ok.json new file mode 100644 index 000000000..ba0ddfefb --- /dev/null +++ b/providers/dns/eurodns/internal/fixtures/zone_add_validate_ok.json @@ -0,0 +1,49 @@ +{ + "name": "example.com", + "domainConnect": true, + "records": [ + { + "id": 1000, + "type": "A", + "host": "@", + "ttl": 600, + "rdata": "string", + "updated": true, + "locked": true, + "isDynDns": true, + "proxy": "ON" + }, + { + "type": "TXT", + "host": "_acme-challenge", + "ttl": 600, + "rdata": "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY", + "updated": null, + "locked": null, + "isDynDns": null + } + ], + "urlForwards": [ + { + "id": 2000, + "forwardType": "FRAME", + "host": "string", + "url": "string", + "title": "string", + "keywords": "string", + "description": "string", + "updated": true + } + ], + "mailForwards": [ + { + "id": 3000, + "source": "string", + "destination": "string", + "updated": true + } + ], + "report": { + "isValid": true + } +} diff --git a/providers/dns/eurodns/internal/fixtures/zone_get.json b/providers/dns/eurodns/internal/fixtures/zone_get.json index c9143602d..ebbc8593e 100644 --- a/providers/dns/eurodns/internal/fixtures/zone_get.json +++ b/providers/dns/eurodns/internal/fixtures/zone_get.json @@ -1,12 +1,12 @@ { - "name": "string", + "name": "example.com", "domainConnect": true, "records": [ { - "id": 0, + "id": 1000, "type": "A", - "host": "string", - "ttl": 0, + "host": "@", + "ttl": 600, "rdata": "string", "updated": true, "locked": true, @@ -16,7 +16,7 @@ ], "urlForwards": [ { - "id": 0, + "id": 2000, "forwardType": "FRAME", "host": "string", "url": "string", @@ -28,103 +28,10 @@ ], "mailForwards": [ { - "id": 0, + "id": 3000, "source": "string", "destination": "string", "updated": true } - ], - "report": { - "isValid": true, - "recordErrors": [ - { - "messages": [ - "string" - ], - "record": { - "id": 0, - "type": "A", - "host": "string", - "ttl": 0, - "rdata": "string", - "updated": true, - "locked": true, - "isDynDns": true, - "proxy": "ON" - }, - "severity": "ERROR" - } - ], - "urlForwardErrors": [ - { - "messages": [ - "string" - ], - "urlForward": { - "id": 0, - "forwardType": "FRAME", - "host": "string", - "url": "string", - "title": "string", - "keywords": "string", - "description": "string", - "updated": true - }, - "severity": "ERROR" - } - ], - "mailForwardErrors": [ - { - "messages": [ - "string" - ], - "mailForward": { - "id": 0, - "source": "string", - "destination": "string", - "updated": true - }, - "severity": "ERROR" - } - ], - "zoneErrors": [ - { - "message": "string", - "records": [ - { - "id": 0, - "type": "A", - "host": "string", - "ttl": 0, - "rdata": "string", - "updated": true, - "locked": true, - "isDynDns": true, - "proxy": "ON" - } - ], - "urlForwards": [ - { - "id": 0, - "forwardType": "FRAME", - "host": "string", - "url": "string", - "title": "string", - "keywords": "string", - "description": "string", - "updated": true - } - ], - "mailForwards": [ - { - "id": 0, - "source": "string", - "destination": "string", - "updated": true - } - ], - "severity": "ERROR" - } - ] - } + ] } diff --git a/providers/dns/eurodns/internal/fixtures/zone_remove.json b/providers/dns/eurodns/internal/fixtures/zone_remove.json index 449493adf..ebbc8593e 100644 --- a/providers/dns/eurodns/internal/fixtures/zone_remove.json +++ b/providers/dns/eurodns/internal/fixtures/zone_remove.json @@ -1,10 +1,12 @@ { - "name": "string", + "name": "example.com", "domainConnect": true, "records": [ { + "id": 1000, "type": "A", - "host": "string", + "host": "@", + "ttl": 600, "rdata": "string", "updated": true, "locked": true, @@ -14,6 +16,7 @@ ], "urlForwards": [ { + "id": 2000, "forwardType": "FRAME", "host": "string", "url": "string", @@ -25,94 +28,10 @@ ], "mailForwards": [ { + "id": 3000, "source": "string", "destination": "string", "updated": true } - ], - "report": { - "isValid": true, - "recordErrors": [ - { - "messages": [ - "string" - ], - "record": { - "type": "A", - "host": "string", - "rdata": "string", - "updated": true, - "locked": true, - "isDynDns": true, - "proxy": "ON" - }, - "severity": "ERROR" - } - ], - "urlForwardErrors": [ - { - "messages": [ - "string" - ], - "urlForward": { - "forwardType": "FRAME", - "host": "string", - "url": "string", - "title": "string", - "keywords": "string", - "description": "string", - "updated": true - }, - "severity": "ERROR" - } - ], - "mailForwardErrors": [ - { - "messages": [ - "string" - ], - "mailForward": { - "source": "string", - "destination": "string", - "updated": true - }, - "severity": "ERROR" - } - ], - "zoneErrors": [ - { - "message": "string", - "records": [ - { - "type": "A", - "host": "string", - "rdata": "string", - "updated": true, - "locked": true, - "isDynDns": true, - "proxy": "ON" - } - ], - "urlForwards": [ - { - "forwardType": "FRAME", - "host": "string", - "url": "string", - "title": "string", - "keywords": "string", - "description": "string", - "updated": true - } - ], - "mailForwards": [ - { - "source": "string", - "destination": "string", - "updated": true - } - ], - "severity": "ERROR" - } - ] - } + ] } diff --git a/providers/dns/eurodns/internal/types.go b/providers/dns/eurodns/internal/types.go index a2d0b65b8..891b02e14 100644 --- a/providers/dns/eurodns/internal/types.go +++ b/providers/dns/eurodns/internal/types.go @@ -95,7 +95,7 @@ func (r *Report) Error() string { type RecordError struct { Messages []string `json:"messages,omitempty"` - Record *Record `json:"record,omitempty"` + Record Record `json:"record"` Severity string `json:"severity,omitempty"` } @@ -104,9 +104,9 @@ func (e *RecordError) Error() string { } type URLForwardError struct { - Messages []string `json:"messages,omitempty"` - URLForward *URLForward `json:"urlForward,omitempty"` - Severity string `json:"severity,omitempty"` + Messages []string `json:"messages,omitempty"` + URLForward URLForward `json:"urlForward"` + Severity string `json:"severity,omitempty"` } func (e *URLForwardError) Error() string { @@ -114,9 +114,9 @@ func (e *URLForwardError) Error() string { } type MailForwardError struct { - Messages []string `json:"messages,omitempty"` - MailForward *MailForward `json:"mailForward,omitempty"` - Severity string `json:"severity,omitempty"` + Messages []string `json:"messages,omitempty"` + MailForward MailForward `json:"mailForward"` + Severity string `json:"severity,omitempty"` } func (e *MailForwardError) Error() string {