Move some test-only code into the test

This commit is contained in:
Tim Hockin 2014-09-20 11:38:05 -07:00
parent 20826e6d50
commit a559d8d9b2
2 changed files with 11 additions and 11 deletions

View File

@ -317,15 +317,6 @@ func NewProxier(loadBalancer LoadBalancer, address string) *Proxier {
}
}
// StopProxy stops the proxy for the named service.
func (proxier *Proxier) StopProxy(service string) error {
info, found := proxier.getServiceInfo(service)
if !found {
return fmt.Errorf("unknown service: %s", service)
}
return proxier.stopProxy(service, info)
}
// This assumes proxier.mu is not locked.
func (proxier *Proxier) stopProxy(service string, info *serviceInfo) error {
proxier.mu.Lock()

View File

@ -171,6 +171,15 @@ func TestUDPProxy(t *testing.T) {
testEchoUDP(t, "127.0.0.1", proxyPort)
}
// Helper: Stops the proxy for the named service.
func stopProxyByName(proxier *Proxier, service string) error {
info, found := proxier.getServiceInfo(service)
if !found {
return fmt.Errorf("unknown service: %s", service)
}
return proxier.stopProxy(service, info)
}
func TestTCPProxyStop(t *testing.T) {
lb := NewLoadBalancerRR()
lb.OnUpdate([]api.Endpoints{
@ -192,7 +201,7 @@ func TestTCPProxyStop(t *testing.T) {
}
conn.Close()
p.StopProxy("echo")
stopProxyByName(p, "echo")
// Wait for the port to really close.
if err := waitForClosedPortTCP(p, proxyPort); err != nil {
t.Fatalf(err.Error())
@ -220,7 +229,7 @@ func TestUDPProxyStop(t *testing.T) {
}
conn.Close()
p.StopProxy("echo")
stopProxyByName(p, "echo")
// Wait for the port to really close.
if err := waitForClosedPortUDP(p, proxyPort); err != nil {
t.Fatalf(err.Error())