mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 01:26:59 +02:00
* Make suitableType() be Endpoint method With this change it becomes possible to work with endpoint of empty type in packages other than "provider". Also it seems logical for a smart property getter without side effects to be a method rather than a function in different package * Make plan computation work correctly with multi-target domains * fix drawing * drop comments * fix boilerplate header * fix comment * fix the bug with empty map * rework registry to support random lables * serialize->serializeLabel function rename * golint for err variable naming * add additional test * add tests for current case where one resource can generate multiple endpoints * make labels have its own type, add serialization as a method * add comment for exported error * use greater rather than not equal zero * update changelog
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
/*
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package testutils
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"github.com/kubernetes-incubator/external-dns/endpoint"
|
|
)
|
|
|
|
/** test utility functions for endpoints verifications */
|
|
|
|
type byAllFields []*endpoint.Endpoint
|
|
|
|
func (b byAllFields) Len() int { return len(b) }
|
|
func (b byAllFields) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
|
func (b byAllFields) Less(i, j int) bool {
|
|
if b[i].DNSName < b[j].DNSName {
|
|
return true
|
|
}
|
|
if b[i].DNSName == b[j].DNSName {
|
|
if b[i].Target < b[j].Target {
|
|
return true
|
|
}
|
|
if b[i].Target == b[j].Target {
|
|
return b[i].RecordType <= b[j].RecordType
|
|
}
|
|
return false
|
|
}
|
|
return false
|
|
}
|
|
|
|
// SameEndpoint returns true if two endpoints are same
|
|
// considers example.org. and example.org DNSName/Target as different endpoints
|
|
func SameEndpoint(a, b *endpoint.Endpoint) bool {
|
|
return a.DNSName == b.DNSName && a.Target == b.Target && a.RecordType == b.RecordType &&
|
|
a.Labels[endpoint.OwnerLabelKey] == b.Labels[endpoint.OwnerLabelKey] && a.RecordTTL == b.RecordTTL &&
|
|
a.Labels[endpoint.ResourceLabelKey] == b.Labels[endpoint.ResourceLabelKey]
|
|
}
|
|
|
|
// SameEndpoints compares two slices of endpoints regardless of order
|
|
// [x,y,z] == [z,x,y]
|
|
// [x,x,z] == [x,z,x]
|
|
// [x,y,y] != [x,x,y]
|
|
// [x,x,x] != [x,x,z]
|
|
func SameEndpoints(a, b []*endpoint.Endpoint) bool {
|
|
if len(a) != len(b) {
|
|
return false
|
|
}
|
|
|
|
sa := a[:]
|
|
sb := b[:]
|
|
sort.Sort(byAllFields(sa))
|
|
sort.Sort(byAllFields(sb))
|
|
|
|
for i := range sa {
|
|
if !SameEndpoint(sa[i], sb[i]) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// SamePlanChanges verifies that two set of changes are the same
|
|
func SamePlanChanges(a, b map[string][]*endpoint.Endpoint) bool {
|
|
return SameEndpoints(a["Create"], b["Create"]) && SameEndpoints(a["Delete"], b["Delete"]) &&
|
|
SameEndpoints(a["UpdateOld"], b["UpdateOld"]) && SameEndpoints(a["UpdateNew"], b["UpdateNew"])
|
|
}
|