Merge pull request #2185 from KohlsTechnology/bluecat-delete

bluecat: improve test coverage
This commit is contained in:
Kubernetes Prow Robot 2021-07-20 09:55:32 -07:00 committed by GitHub
commit f9a3fe3d7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 4 deletions

View File

@ -215,7 +215,7 @@ func (p *BluecatProvider) Records(ctx context.Context) (endpoints []*endpoint.En
tempEndpoint := endpoint.NewEndpoint(rec.Name, endpoint.RecordTypeTXT, rec.Properties)
tempEndpoint.Labels[endpoint.OwnerLabelKey], err = extractOwnerfromTXTRecord(rec.Properties)
if err != nil {
return nil, errors.Wrapf(err, "Error fetching owner from record")
log.Debugf("External DNS Owner %s", err)
}
endpoints = append(endpoints, tempEndpoint)
}
@ -243,7 +243,7 @@ func (p *BluecatProvider) Records(ctx context.Context) (endpoints []*endpoint.En
if strings.Compare(rec.Name, txtRec.Name) == 0 {
ep.Labels[endpoint.OwnerLabelKey], err = extractOwnerfromTXTRecord(txtRec.Properties)
if err != nil {
return nil, errors.Wrapf(err, "owner not parsed correctly")
log.Debugf("External DNS Owner %s", err)
}
}
}
@ -272,7 +272,7 @@ func (p *BluecatProvider) Records(ctx context.Context) (endpoints []*endpoint.En
if strings.Compare(rec.Name, txtRec.Name) == 0 {
ep.Labels[endpoint.OwnerLabelKey], err = extractOwnerfromTXTRecord(txtRec.Properties)
if err != nil {
return nil, errors.Wrapf(err, "owner not parsed correctly")
log.Debugf("External DNS Owner %s", err)
}
}
}

View File

@ -192,6 +192,18 @@ var tests = bluecatTestData{
Targets: endpoint.Targets{"bluecatnetworks.com"},
RecordTTL: endpoint.TTL(30),
},
{
DNSName: "wack.example.com",
RecordType: endpoint.RecordTypeTXT,
Targets: endpoint.Targets{"hello"},
Labels: endpoint.Labels{"owner": ""},
},
{
DNSName: "sack.example.com",
RecordType: endpoint.RecordTypeTXT,
Targets: endpoint.Targets{""},
Labels: endpoint.Labels{"owner": ""},
},
{
DNSName: "kdb.example.com",
RecordType: endpoint.RecordTypeTXT,
@ -209,6 +221,8 @@ func TestBluecatRecords(t *testing.T) {
},
mockBluecatTXTs: &[]BluecatTXTRecord{
createMockBluecatTXT("kdb.example.com", "heritage=external-dns,external-dns/owner=default,external-dns/resource=service/openshift-ingress/router-default"),
createMockBluecatTXT("wack.example.com", "hello"),
createMockBluecatTXT("sack.example.com", ""),
},
mockBluecatHosts: &[]BluecatHostRecord{
createMockBluecatHostRecord("example.com", "123.123.123.122", 30),
@ -275,6 +289,8 @@ func TestBluecatApplyChangesDelete(t *testing.T) {
},
mockBluecatTXTs: &[]BluecatTXTRecord{
createMockBluecatTXT("kdb.example.com", "heritage=external-dns,external-dns/owner=default,external-dns/resource=service/openshift-ingress/router-default"),
createMockBluecatTXT("wack.example.com", "hello"),
createMockBluecatTXT("sack.example.com", ""),
},
}
@ -311,6 +327,8 @@ func TestBluecatApplyChangesDeleteWithOwner(t *testing.T) {
},
mockBluecatTXTs: &[]BluecatTXTRecord{
createMockBluecatTXT("kdb.example.com", "heritage=external-dns,external-dns/owner=default,external-dns/resource=service/openshift-ingress/router-default"),
createMockBluecatTXT("wack.example.com", "hello"),
createMockBluecatTXT("sack.example.com", ""),
},
}
@ -341,7 +359,32 @@ func TestBluecatApplyChangesDeleteWithOwner(t *testing.T) {
}
// TODO: ensure mapChanges method is tested
func TestExpandZones(t *testing.T) {
mockZones := []string{"example.com", "nginx.example.com", "hack.example.com"}
expected := []string{"zones/com/zones/example/zones/", "zones/com/zones/example/zones/nginx/zones/", "zones/com/zones/example/zones/hack/zones/"}
for i := range mockZones {
if expandZone(mockZones[i]) != expected[i] {
t.Fatalf("%s", expected[i])
}
}
}
func TestBluecatNewGatewayClient(t *testing.T) {
testCookie := http.Cookie{Name: "testCookie", Value: "exampleCookie"}
testToken := "exampleToken"
testgateWayHost := "exampleHost"
testDNSConfiguration := "exampleDNSConfiguration"
testView := "testView"
testZone := "example.com"
testVerify := true
client := NewGatewayClient(testCookie, testToken, testgateWayHost, testDNSConfiguration, testView, testZone, testVerify)
if client.Cookie.Value != testCookie.Value || client.Cookie.Name != testCookie.Name || client.Token != testToken || client.Host != testgateWayHost || client.DNSConfiguration != testDNSConfiguration || client.View != testView || client.RootZone != testZone || client.SkipTLSVerify != testVerify {
t.Fatal("Client values dont match")
}
}
// TODO: ensure findZone method is tested
// TODO: ensure zones method is tested
// TODO: ensure createRecords method is tested