mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 17:46:57 +02:00
add testutils to compare changes, im provider allow to inspect changes (#130)
* add testutils to compare changes, inmemory provider allow to inspect changes * use map instead of plan.Changes
This commit is contained in:
parent
92e59e7fd3
commit
e25b792970
@ -16,9 +16,7 @@ limitations under the License.
|
||||
|
||||
package testutils
|
||||
|
||||
import (
|
||||
"github.com/kubernetes-incubator/external-dns/endpoint"
|
||||
)
|
||||
import "github.com/kubernetes-incubator/external-dns/endpoint"
|
||||
|
||||
/** test utility functions for endpoints verifications */
|
||||
|
||||
@ -69,3 +67,9 @@ func SameEndpoints(a, b []*endpoint.Endpoint) bool {
|
||||
|
||||
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"])
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ type zone map[string][]*InMemoryRecord
|
||||
// initialized as dns provider with no records
|
||||
type InMemoryProvider struct {
|
||||
zones map[string]zone
|
||||
OnApplyChanges func()
|
||||
OnApplyChanges func(changes *plan.Changes)
|
||||
OnRecords func()
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ type InMemoryProvider struct {
|
||||
func NewInMemoryProvider() *InMemoryProvider {
|
||||
return &InMemoryProvider{
|
||||
zones: map[string]zone{},
|
||||
OnApplyChanges: func() {},
|
||||
OnApplyChanges: func(changes *plan.Changes) {},
|
||||
OnRecords: func() {},
|
||||
}
|
||||
}
|
||||
@ -92,7 +92,7 @@ func (im *InMemoryProvider) Records(zone string) ([]*endpoint.Endpoint, error) {
|
||||
// update/delete record - record should exist
|
||||
// create/update/delete lists should not have overlapping records
|
||||
func (im *InMemoryProvider) ApplyChanges(zone string, changes *plan.Changes) error {
|
||||
defer im.OnApplyChanges()
|
||||
defer im.OnApplyChanges(changes)
|
||||
|
||||
if err := im.validateChangeBatch(zone, changes); err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user