Skip to content

Commit

Permalink
Fix comments in tests, visually restructure code
Browse files Browse the repository at this point in the history
  • Loading branch information
ffledgling committed Mar 22, 2018
1 parent e97cb6d commit c1c627d
Showing 1 changed file with 61 additions and 104 deletions.
165 changes: 61 additions & 104 deletions provider/pdns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ import (
"github.com/kubernetes-incubator/external-dns/endpoint"
)

// Test when we create a new provider it sets certain values correctly and errors out correctly in certain cases.

// Test zones to endpoints works correctly
// Test endpoints to zones works correctly
// Test the correct list/patch functions are called?
// Check your "regular"/80% case for arguments

// FIXME: Disabled record should not be returned in .Records()
// FIXME: What do we do about labels?

var (
Expand Down Expand Up @@ -58,21 +50,6 @@ var (
pgo.Record{Content: "\"heritage=external-dns,external-dns/owner=tower-pdns\"", Disabled: false, SetPtr: false},
},
}
endpointsSimpleRecord = []*endpoint.Endpoint{
endpoint.NewEndpointWithTTL("example.com", "8.8.8.8", endpoint.RecordTypeA, endpoint.TTL(300)),
endpoint.NewEndpointWithTTL("example.com", "\"heritage=external-dns,external-dns/owner=tower-pdns\"", endpoint.RecordTypeTXT, endpoint.TTL(300)),
}

endpointsLongRecord = []*endpoint.Endpoint{
endpoint.NewEndpointWithTTL("a.very.long.domainname.example.com", "8.8.8.8", endpoint.RecordTypeA, endpoint.TTL(300)),
endpoint.NewEndpointWithTTL("a.very.long.domainname.example.com", "\"heritage=external-dns,external-dns/owner=tower-pdns\"", endpoint.RecordTypeTXT, endpoint.TTL(300)),
}

endpointsNonexistantZone = []*endpoint.Endpoint{
endpoint.NewEndpointWithTTL("does.not.exist.com", "8.8.8.8", endpoint.RecordTypeA, endpoint.TTL(300)),
endpoint.NewEndpointWithTTL("does.not.exist.com", "\"heritage=external-dns,external-dns/owner=tower-pdns\"", endpoint.RecordTypeTXT, endpoint.TTL(300)),
}

// RRSet with one record disabled
RRSetDisabledRecord = pgo.RrSet{
Name: "example.com.",
Expand All @@ -83,9 +60,6 @@ var (
pgo.Record{Content: "8.8.4.4", Disabled: true, SetPtr: false},
},
}
endpointsDisabledRecord = []*endpoint.Endpoint{
endpoint.NewEndpointWithTTL("example.com", "8.8.8.8", endpoint.RecordTypeA, endpoint.TTL(300)),
}

RRSetCNAMERecord = pgo.RrSet{
Name: "cname.example.com.",
Expand Down Expand Up @@ -116,6 +90,24 @@ var (
},
}

endpointsDisabledRecord = []*endpoint.Endpoint{
endpoint.NewEndpointWithTTL("example.com", "8.8.8.8", endpoint.RecordTypeA, endpoint.TTL(300)),
}

endpointsSimpleRecord = []*endpoint.Endpoint{
endpoint.NewEndpointWithTTL("example.com", "8.8.8.8", endpoint.RecordTypeA, endpoint.TTL(300)),
endpoint.NewEndpointWithTTL("example.com", "\"heritage=external-dns,external-dns/owner=tower-pdns\"", endpoint.RecordTypeTXT, endpoint.TTL(300)),
}

endpointsLongRecord = []*endpoint.Endpoint{
endpoint.NewEndpointWithTTL("a.very.long.domainname.example.com", "8.8.8.8", endpoint.RecordTypeA, endpoint.TTL(300)),
endpoint.NewEndpointWithTTL("a.very.long.domainname.example.com", "\"heritage=external-dns,external-dns/owner=tower-pdns\"", endpoint.RecordTypeTXT, endpoint.TTL(300)),
}

endpointsNonexistantZone = []*endpoint.Endpoint{
endpoint.NewEndpointWithTTL("does.not.exist.com", "8.8.8.8", endpoint.RecordTypeA, endpoint.TTL(300)),
endpoint.NewEndpointWithTTL("does.not.exist.com", "\"heritage=external-dns,external-dns/owner=tower-pdns\"", endpoint.RecordTypeTXT, endpoint.TTL(300)),
}
endpointsMultipleRecords = []*endpoint.Endpoint{
endpoint.NewEndpointWithTTL("example.com", "8.8.8.8", endpoint.RecordTypeA, endpoint.TTL(300)),
endpoint.NewEndpointWithTTL("example.com", "8.8.4.4", endpoint.RecordTypeA, endpoint.TTL(300)),
Expand All @@ -137,7 +129,6 @@ var (
endpoint.NewEndpointWithTTL("mock.test", "\"heritage=external-dns,external-dns/owner=tower-pdns\"", endpoint.RecordTypeTXT, endpoint.TTL(300)),
}

//
ZoneEmpty = pgo.Zone{
// Opaque zone id (string), assigned by the server, should not be interpreted by the application. Guaranteed to be safe for embedding in URLs.
Id: "example.com.",
Expand All @@ -154,62 +145,38 @@ var (
}

ZoneEmptyLong = pgo.Zone{
// Opaque zone id (string), assigned by the server, should not be interpreted by the application. Guaranteed to be safe for embedding in URLs.
Id: "long.domainname.example.com.",
// Name of the zone (e.g. “example.com.”) MUST have a trailing dot
Name: "long.domainname.example.com.",
// Set to “Zone”
Type_: "Zone",
// API endpoint for this zone
Url: "/api/v1/servers/localhost/zones/long.domainname.example.com.",
// Zone kind, one of “Native”, “Master”, “Slave”
Kind: "Native",
// RRSets in this zone
Id: "long.domainname.example.com.",
Name: "long.domainname.example.com.",
Type_: "Zone",
Url: "/api/v1/servers/localhost/zones/long.domainname.example.com.",
Kind: "Native",
Rrsets: []pgo.RrSet{},
}

ZoneEmpty2 = pgo.Zone{
// Opaque zone id (string), assigned by the server, should not be interpreted by the application. Guaranteed to be safe for embedding in URLs.
Id: "mock.test.",
// Name of the zone (e.g. “mock.test.”) MUST have a trailing dot
Name: "mock.test.",
// Set to “Zone”
Type_: "Zone",
// API endpoint for this zone
Url: "/api/v1/servers/localhost/zones/mock.test.",
// Zone kind, one of “Native”, “Master”, “Slave”
Kind: "Native",
// RRSets in this zone
Id: "mock.test.",
Name: "mock.test.",
Type_: "Zone",
Url: "/api/v1/servers/localhost/zones/mock.test.",
Kind: "Native",
Rrsets: []pgo.RrSet{},
}

ZoneMixed = pgo.Zone{
// Opaque zone id (string), assigned by the server, should not be interpreted by the application. Guaranteed to be safe for embedding in URLs.
Id: "example.com.",
// Name of the zone (e.g. “example.com.”) MUST have a trailing dot
Name: "example.com.",
// Set to “Zone”
Type_: "Zone",
// API endpoint for this zone
Url: "/api/v1/servers/localhost/zones/example.com.",
// Zone kind, one of “Native”, “Master”, “Slave”
Kind: "Native",
// RRSets in this zone
Id: "example.com.",
Name: "example.com.",
Type_: "Zone",
Url: "/api/v1/servers/localhost/zones/example.com.",
Kind: "Native",
Rrsets: []pgo.RrSet{RRSetCNAMERecord, RRSetTXTRecord, RRSetMultipleRecords},
}

ZoneEmptyToSimplePatch = pgo.Zone{
// Opaque zone id (string), assigned by the server, should not be interpreted by the application. Guaranteed to be safe for embedding in URLs.
Id: "example.com.",
// Name of the zone (e.g. “example.com.”) MUST have a trailing dot
Name: "example.com.",
// Set to “Zone”
Id: "example.com.",
Name: "example.com.",
Type_: "Zone",
// API endpoint for this zone
Url: "/api/v1/servers/localhost/zones/example.com.",
// Zone kind, one of “Native”, “Master”, “Slave”
Kind: "Native",
// RRSets in this zone
Url: "/api/v1/servers/localhost/zones/example.com.",
Kind: "Native",
Rrsets: []pgo.RrSet{
pgo.RrSet{
Name: "example.com.",
Expand Down Expand Up @@ -243,17 +210,11 @@ var (
}

ZoneEmptyToLongPatch = pgo.Zone{
// Opaque zone id (string), assigned by the server, should not be interpreted by the application. Guaranteed to be safe for embedding in URLs.
Id: "long.domainname.example.com.",
// Name of the zone (e.g. “example.com.”) MUST have a trailing dot
Name: "long.domainname.example.com.",
// Set to “Zone”
Id: "long.domainname.example.com.",
Name: "long.domainname.example.com.",
Type_: "Zone",
// API endpoint for this zone
Url: "/api/v1/servers/localhost/zones/long.domainname.example.com.",
// Zone kind, one of “Native”, “Master”, “Slave”
Kind: "Native",
// RRSets in this zone
Url: "/api/v1/servers/localhost/zones/long.domainname.example.com.",
Kind: "Native",
Rrsets: []pgo.RrSet{
pgo.RrSet{
Name: "a.very.long.domainname.example.com.",
Expand Down Expand Up @@ -287,17 +248,11 @@ var (
}

ZoneEmptyToSimplePatch2 = pgo.Zone{
// Opaque zone id (string), assigned by the server, should not be interpreted by the application. Guaranteed to be safe for embedding in URLs.
Id: "mock.test.",
// Name of the zone (e.g. “mock.test.”) MUST have a trailing dot
Name: "mock.test.",
// Set to “Zone”
Id: "mock.test.",
Name: "mock.test.",
Type_: "Zone",
// API endpoint for this zone
Url: "/api/v1/servers/localhost/zones/mock.test.",
// Zone kind, one of “Native”, “Master”, “Slave”
Kind: "Native",
// RRSets in this zone
Url: "/api/v1/servers/localhost/zones/mock.test.",
Kind: "Native",
Rrsets: []pgo.RrSet{
pgo.RrSet{
Name: "mock.test.",
Expand Down Expand Up @@ -331,17 +286,11 @@ var (
}

ZoneEmptyToSimpleDelete = pgo.Zone{
// Opaque zone id (string), assigned by the server, should not be interpreted by the application. Guaranteed to be safe for embedding in URLs.
Id: "example.com.",
// Name of the zone (e.g. “example.com.”) MUST have a trailing dot
Name: "example.com.",
// Set to “Zone”
Id: "example.com.",
Name: "example.com.",
Type_: "Zone",
// API endpoint for this zone
Url: "/api/v1/servers/localhost/zones/example.com.",
// Zone kind, one of “Native”, “Master”, “Slave”
Kind: "Native",
// RRSets in this zone
Url: "/api/v1/servers/localhost/zones/example.com.",
Kind: "Native",
Rrsets: []pgo.RrSet{
pgo.RrSet{
Name: "example.com.",
Expand Down Expand Up @@ -373,6 +322,7 @@ var (
}
)

/******************************************************************************/
// API that returns a zone with multiple record types
type PDNSAPIClientStub struct {
}
Expand All @@ -387,7 +337,8 @@ func (c *PDNSAPIClientStub) PatchZone(zoneId string, zoneStruct pgo.Zone) (*http
return nil, nil
}

// API that returns a zone with no records
/******************************************************************************/
// API that returns a zones with no records
type PDNSAPIClientStubEmptyZones struct {
// Keep track of all zones we recieve via PatchZone
patchedZones []pgo.Zone
Expand All @@ -414,7 +365,8 @@ func (c *PDNSAPIClientStubEmptyZones) PatchZone(zoneId string, zoneStruct pgo.Zo
return nil, nil
}

// API that returns a zone with no records
/******************************************************************************/
// API that returns error on PatchZone()
type PDNSAPIClientStubPatchZoneFailure struct {
// Anonymous struct for composition
PDNSAPIClientStubEmptyZones
Expand All @@ -425,7 +377,8 @@ func (c *PDNSAPIClientStubPatchZoneFailure) PatchZone(zoneId string, zoneStruct
return nil, errors.New("Generic PDNS Error")
}

// API that returns a zone with no records
/******************************************************************************/
// API that returns error on ListZone()
type PDNSAPIClientStubListZoneFailure struct {
// Anonymous struct for composition
PDNSAPIClientStubEmptyZones
Expand All @@ -437,6 +390,8 @@ func (c *PDNSAPIClientStubListZoneFailure) ListZone(zoneId string) (pgo.Zone, *h

}

/******************************************************************************/
// API that returns error on ListZones() (Zones - plural)
type PDNSAPIClientStubListZonesFailure struct {
// Anonymous struct for composition
PDNSAPIClientStubEmptyZones
Expand All @@ -447,6 +402,8 @@ func (c *PDNSAPIClientStubListZonesFailure) ListZones() ([]pgo.Zone, *http.Respo
return []pgo.Zone{}, nil, errors.New("Generic PDNS Error")
}

/******************************************************************************/

type NewPDNSProviderTestSuite struct {
suite.Suite
}
Expand Down Expand Up @@ -551,7 +508,7 @@ func (suite *NewPDNSProviderTestSuite) TestPDNSConvertEndpointsToZones() {
assert.Nil(suite.T(), err)
assert.Equal(suite.T(), []pgo.Zone{}, zlist)

// TODO: Add test to check a record that matches multiple zones (one longer than other), is assigned to the right zone
// Check endpoints that match multiple zones (one longer than other), is assigned to the right zone
zlist, err = p.ConvertEndpointsToZones(endpointsLongRecord, PdnsReplace)
assert.Nil(suite.T(), err)
assert.Equal(suite.T(), []pgo.Zone{ZoneEmptyToLongPatch}, zlist)
Expand Down

0 comments on commit c1c627d

Please sign in to comment.