Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing non code test's dependency on testing package #69

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ func TestLbCreateDelete(t *testing.T) {
if err != nil {
t.Fatalf("%v", err)
}
cm.fakeLbs.CheckURLMap(t, l7, pm.toNodePortSvcNames(m))
if err := cm.fakeLbs.CheckURLMap(l7, pm.toNodePortSvcNames(m)); err != nil {
t.Fatalf("%v", err)
}
ings = append(ings, newIng)
}
lbc.ingLister.Store.Delete(ings[0])
Expand Down Expand Up @@ -318,7 +320,9 @@ func TestLbFaultyUpdate(t *testing.T) {
if err != nil {
t.Fatalf("%v", err)
}
cm.fakeLbs.CheckURLMap(t, l7, pm.toNodePortSvcNames(inputMap))
if err := cm.fakeLbs.CheckURLMap(l7, pm.toNodePortSvcNames(inputMap)); err != nil {
t.Fatalf("%v", err)
}

// Change the urlmap directly through the lb pool, resync, and
// make sure the controller corrects it.
Expand All @@ -329,7 +333,9 @@ func TestLbFaultyUpdate(t *testing.T) {
})

lbc.sync(ingStoreKey)
cm.fakeLbs.CheckURLMap(t, l7, pm.toNodePortSvcNames(inputMap))
if err := cm.fakeLbs.CheckURLMap(l7, pm.toNodePortSvcNames(inputMap)); err != nil {
t.Fatalf("%v", err)
}
}

func TestLbDefaulting(t *testing.T) {
Expand All @@ -347,7 +353,9 @@ func TestLbDefaulting(t *testing.T) {
t.Fatalf("%v", err)
}
expectedMap := map[string]utils.FakeIngressRuleValueMap{loadbalancers.DefaultHost: {loadbalancers.DefaultPath: "foo1svc"}}
cm.fakeLbs.CheckURLMap(t, l7, pm.toNodePortSvcNames(expectedMap))
if err := cm.fakeLbs.CheckURLMap(l7, pm.toNodePortSvcNames(expectedMap)); err != nil {
t.Fatalf("%v", err)
}
}

func TestLbNoService(t *testing.T) {
Expand Down Expand Up @@ -391,7 +399,9 @@ func TestLbNoService(t *testing.T) {
utils.DefaultBackendKey: "foo1svc",
}
expectedMap := pm.toNodePortSvcNames(inputMap)
cm.fakeLbs.CheckURLMap(t, l7, expectedMap)
if err := cm.fakeLbs.CheckURLMap(l7, expectedMap); err != nil {
t.Fatalf("%v", err)
}
}

func TestLbChangeStaticIP(t *testing.T) {
Expand Down
22 changes: 11 additions & 11 deletions pkg/loadbalancers/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package loadbalancers

import (
"fmt"
"testing"

compute "google.golang.org/api/compute/v1"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -315,11 +314,11 @@ func (f *FakeLoadBalancers) SetSslCertificateForTargetHttpsProxy(proxy *compute.
// UrlMap fakes

// CheckURLMap checks the URL map.
func (f *FakeLoadBalancers) CheckURLMap(t *testing.T, l7 *L7, expectedMap map[string]utils.FakeIngressRuleValueMap) {
func (f *FakeLoadBalancers) CheckURLMap(l7 *L7, expectedMap map[string]utils.FakeIngressRuleValueMap) error {
f.calls = append(f.calls, "CheckURLMap")
um, err := f.GetUrlMap(l7.um.Name)
if err != nil || um == nil {
t.Fatalf("%v", err)
return err
}
// Check the default backend
var d string
Expand All @@ -331,7 +330,7 @@ func (f *FakeLoadBalancers) CheckURLMap(t *testing.T, l7 *L7, expectedMap map[st
}
// The urlmap should have a default backend, and each path matcher.
if d != "" && l7.um.DefaultService != d {
t.Fatalf("Expected default backend %v found %v",
return fmt.Errorf("Expected default backend %v found %v",
d, l7.um.DefaultService)
}

Expand All @@ -341,10 +340,10 @@ func (f *FakeLoadBalancers) CheckURLMap(t *testing.T, l7 *L7, expectedMap map[st
for _, hostRule := range l7.um.HostRules {
if matcher.Name == hostRule.PathMatcher {
if len(hostRule.Hosts) != 1 {
t.Fatalf("Unexpected hosts in hostrules %+v", hostRule)
return fmt.Errorf("Unexpected hosts in hostrules %+v", hostRule)
}
if d != "" && matcher.DefaultService != d {
t.Fatalf("Expected default backend %v found %v",
return fmt.Errorf("Expected default backend %v found %v",
d, matcher.DefaultService)
}
hostname = hostRule.Hosts[0]
Expand All @@ -354,15 +353,15 @@ func (f *FakeLoadBalancers) CheckURLMap(t *testing.T, l7 *L7, expectedMap map[st
// These are all pathrules for a single host, found above
for _, rule := range matcher.PathRules {
if len(rule.Paths) != 1 {
t.Fatalf("Unexpected rule in pathrules %+v", rule)
return fmt.Errorf("Unexpected rule in pathrules %+v", rule)
}
pathRule := rule.Paths[0]
if hostMap, ok := expectedMap[hostname]; !ok {
t.Fatalf("Expected map for host %v: %v", hostname, hostMap)
return fmt.Errorf("Expected map for host %v: %v", hostname, hostMap)
} else if svc, ok := expectedMap[hostname][pathRule]; !ok {
t.Fatalf("Expected rule %v in host map", pathRule)
return fmt.Errorf("Expected rule %v in host map", pathRule)
} else if svc != rule.Service {
t.Fatalf("Expected service %v found %v", svc, rule.Service)
return fmt.Errorf("Expected service %v found %v", svc, rule.Service)
}
delete(expectedMap[hostname], pathRule)
if len(expectedMap[hostname]) == 0 {
Expand All @@ -371,8 +370,9 @@ func (f *FakeLoadBalancers) CheckURLMap(t *testing.T, l7 *L7, expectedMap map[st
}
}
if len(expectedMap) != 0 {
t.Fatalf("Untranslated entries %+v", expectedMap)
return fmt.Errorf("Untranslated entries %+v", expectedMap)
}
return nil
}

// Static IP fakes
Expand Down
4 changes: 3 additions & 1 deletion pkg/loadbalancers/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ func TestUpdateUrlMap(t *testing.T) {
"/bar1": "bar1svc",
},
}
f.CheckURLMap(t, l7, expectedMap)
if err := f.CheckURLMap(l7, expectedMap); err != nil {
t.Fatalf("%v", err)
}
}

func TestUpdateUrlMapNoChanges(t *testing.T) {
Expand Down