tests: improve fixtures

This commit is contained in:
Fernandez Ludovic 2026-03-08 21:05:57 +01:00
commit 95af323f66
9 changed files with 376 additions and 394 deletions

View file

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

View file

@ -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()},
}},
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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