Skip to content

Commit

Permalink
Merge pull request #914 from davecheney/internal-dag-dry-up
Browse files Browse the repository at this point in the history
internal/dag: dry up tests with a method expression
  • Loading branch information
davecheney authored Mar 4, 2019
2 parents 9523955 + c15abf0 commit b50f5e8
Showing 1 changed file with 15 additions and 35 deletions.
50 changes: 15 additions & 35 deletions internal/dag/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2762,11 +2762,7 @@ func TestDAGInsert(t *testing.T) {
dag := b.Build()

got := make(map[int]*Listener)
dag.Visit(func(v Vertex) {
if l, ok := v.(*Listener); ok {
got[l.Port] = l
}
})
dag.Visit(listenerMap(got).Visit)

want := make(map[int]*Listener)
for _, v := range tc.want {
Expand All @@ -2785,6 +2781,14 @@ func TestDAGInsert(t *testing.T) {
}
}

type listenerMap map[int]*Listener

func (lm listenerMap) Visit(v Vertex) {
if l, ok := v.(*Listener); ok {
lm[l.Port] = l
}
}

func backend(name string, port intstr.IntOrString) *v1beta1.IngressBackend {
return &v1beta1.IngressBackend{
ServiceName: name,
Expand Down Expand Up @@ -2922,11 +2926,7 @@ func TestDAGIngressRouteCycle(t *testing.T) {
dag := b.Build()

got := make(map[int]*Listener)
dag.Visit(func(v Vertex) {
if l, ok := v.(*Listener); ok {
got[l.Port] = l
}
})
dag.Visit(listenerMap(got).Visit)

want := make(map[int]*Listener)
want[80] = &Listener{
Expand Down Expand Up @@ -2972,11 +2972,7 @@ func TestDAGIngressRouteCycleSelfEdge(t *testing.T) {
dag := b.Build()

got := make(map[int]*Listener)
dag.Visit(func(v Vertex) {
if l, ok := v.(*Listener); ok {
got[l.Port] = l
}
})
dag.Visit(listenerMap(got).Visit)

want := make(map[int]*Listener)
opts := []cmp.Option{
Expand Down Expand Up @@ -3012,11 +3008,7 @@ func TestDAGIngressRouteDelegatesToNonExistent(t *testing.T) {
dag := b.Build()

got := make(map[int]*Listener)
dag.Visit(func(v Vertex) {
if l, ok := v.(*Listener); ok {
got[l.Port] = l
}
})
dag.Visit(listenerMap(got).Visit)

want := make(map[int]*Listener)
opts := []cmp.Option{
Expand Down Expand Up @@ -3067,11 +3059,7 @@ func TestDAGIngressRouteDelegatePrefixDoesntMatch(t *testing.T) {
dag := b.Build()

got := make(map[int]*Listener)
dag.Visit(func(v Vertex) {
if l, ok := v.(*Listener); ok {
got[l.Port] = l
}
})
dag.Visit(listenerMap(got).Visit)

want := make(map[int]*Listener)
opts := []cmp.Option{
Expand Down Expand Up @@ -3239,11 +3227,7 @@ func TestDAGIngressRouteDelegatePrefixMatchesStringPrefixButNotPathPrefix(t *tes
dag := b.Build()

got := make(map[int]*Listener)
dag.Visit(func(v Vertex) {
if l, ok := v.(*Listener); ok {
got[l.Port] = l
}
})
dag.Visit(listenerMap(got).Visit)

want := make(map[int]*Listener)
opts := []cmp.Option{
Expand Down Expand Up @@ -3824,11 +3808,7 @@ func TestDAGIngressRouteUniqueFQDNs(t *testing.T) {
}
dag := b.Build()
got := make(map[int]*Listener)
dag.Visit(func(v Vertex) {
if l, ok := v.(*Listener); ok {
got[l.Port] = l
}
})
dag.Visit(listenerMap(got).Visit)

want := make(map[int]*Listener)
for _, v := range tc.want {
Expand Down

0 comments on commit b50f5e8

Please sign in to comment.