Commit e25b7929 authored by Yerken's avatar Yerken Committed by Martin Linkhorst
Browse files

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
parent 92e59e7f
Showing with 10 additions and 6 deletions
+10 -6
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment