Add unit tests for NAPTR and invalid endpoints

This commit is contained in:
Joel Studler 2024-01-27 13:16:53 +01:00
parent b716b764af
commit 2fdc7354c0
2 changed files with 65 additions and 0 deletions

View File

@ -44,6 +44,8 @@ const (
RecordTypePTR = "PTR"
// RecordTypeMX is a RecordType enum value
RecordTypeMX = "MX"
// RecordTypeNAPTR is a RecordType enum value
RecordTypeNAPTR = "NAPTR"
)
// TTL is a structure defining the TTL of a DNS record

View File

@ -404,6 +404,69 @@ func testCRDSourceEndpoints(t *testing.T) {
expectEndpoints: true,
expectError: false,
},
{
title: "Create NAPTR record",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
labelFilter: "test=that",
endpoints: []*endpoint.Endpoint{
{
DNSName: "example.org",
Targets: endpoint.Targets{`100 10 "S" "SIP+D2U" "!^.*$!sip:customer-service@example.org!" _sip._udp.example.org.`, `102 10 "S" "SIP+D2T" "!^.*$!sip:customer-service@example.org!" _sip._tcp.example.org.`},
RecordType: endpoint.RecordTypeNAPTR,
RecordTTL: 180,
},
},
expectEndpoints: true,
expectError: false,
},
{
title: "invalid endpoint CNAME",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
labelFilter: "test=that",
endpoints: []*endpoint.Endpoint{
{
DNSName: "example.org",
Targets: endpoint.Targets{"foo.example.org."},
RecordType: endpoint.RecordTypeCNAME,
RecordTTL: 180,
},
},
expectEndpoints: false,
expectError: false,
},
{
title: "invalid endpoint NAPTR",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
labelFilter: "test=that",
endpoints: []*endpoint.Endpoint{
{
DNSName: "example.org",
Targets: endpoint.Targets{`100 10 "S" "SIP+D2U" "!^.*$!sip:customer-service@example.org!" _sip._udp.example.org`, `102 10 "S" "SIP+D2T" "!^.*$!sip:customer-service@example.org!" _sip._tcp.example.org`},
RecordType: endpoint.RecordTypeNAPTR,
RecordTTL: 180,
},
},
expectEndpoints: false,
expectError: false,
},
} {
ti := ti
t.Run(ti.title, func(t *testing.T) {