From 6a0f240c18088b13972a45966b02c127af0131de Mon Sep 17 00:00:00 2001 From: Jana Radhakrishnan Date: Thu, 14 May 2015 21:59:17 +0000 Subject: [PATCH] Changed portallocator New() method to Get() Signed-off-by: Jana Radhakrishnan --- pkg/portallocator/portallocator.go | 4 ++-- pkg/portallocator/portallocator_test.go | 20 ++++++++++---------- portmapper/mapper.go | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/portallocator/portallocator.go b/pkg/portallocator/portallocator.go index 422284e..84b07b2 100644 --- a/pkg/portallocator/portallocator.go +++ b/pkg/portallocator/portallocator.go @@ -80,8 +80,8 @@ type ( protoMap map[string]*portMap ) -// New returns a new instance of PortAllocator -func New() *PortAllocator { +// Get returns the default instance of PortAllocator +func Get() *PortAllocator { // Port Allocator is a singleton // Note: Long term solution will be each PortAllocator will have access to // the OS so that it can have up to date view of the OS port allocation. diff --git a/pkg/portallocator/portallocator_test.go b/pkg/portallocator/portallocator_test.go index 6b55456..2075649 100644 --- a/pkg/portallocator/portallocator_test.go +++ b/pkg/portallocator/portallocator_test.go @@ -12,7 +12,7 @@ func resetPortAllocator() { } func TestRequestNewPort(t *testing.T) { - p := New() + p := Get() defer resetPortAllocator() port, err := p.RequestPort(defaultIP, "tcp", 0) @@ -26,7 +26,7 @@ func TestRequestNewPort(t *testing.T) { } func TestRequestSpecificPort(t *testing.T) { - p := New() + p := Get() defer resetPortAllocator() port, err := p.RequestPort(defaultIP, "tcp", 5000) @@ -40,7 +40,7 @@ func TestRequestSpecificPort(t *testing.T) { } func TestReleasePort(t *testing.T) { - p := New() + p := Get() port, err := p.RequestPort(defaultIP, "tcp", 5000) if err != nil { @@ -56,7 +56,7 @@ func TestReleasePort(t *testing.T) { } func TestReuseReleasedPort(t *testing.T) { - p := New() + p := Get() defer resetPortAllocator() port, err := p.RequestPort(defaultIP, "tcp", 5000) @@ -78,7 +78,7 @@ func TestReuseReleasedPort(t *testing.T) { } func TestReleaseUnreadledPort(t *testing.T) { - p := New() + p := Get() defer resetPortAllocator() port, err := p.RequestPort(defaultIP, "tcp", 5000) @@ -99,13 +99,13 @@ func TestReleaseUnreadledPort(t *testing.T) { } func TestUnknowProtocol(t *testing.T) { - if _, err := New().RequestPort(defaultIP, "tcpp", 0); err != ErrUnknownProtocol { + if _, err := Get().RequestPort(defaultIP, "tcpp", 0); err != ErrUnknownProtocol { t.Fatalf("Expected error %s got %s", ErrUnknownProtocol, err) } } func TestAllocateAllPorts(t *testing.T) { - p := New() + p := Get() defer resetPortAllocator() for i := 0; i <= p.End-p.Begin; i++ { @@ -156,7 +156,7 @@ func TestAllocateAllPorts(t *testing.T) { } func BenchmarkAllocatePorts(b *testing.B) { - p := New() + p := Get() defer resetPortAllocator() for i := 0; i < b.N; i++ { @@ -175,7 +175,7 @@ func BenchmarkAllocatePorts(b *testing.B) { } func TestPortAllocation(t *testing.T) { - p := New() + p := Get() defer resetPortAllocator() ip := net.ParseIP("192.168.0.1") @@ -237,7 +237,7 @@ func TestPortAllocation(t *testing.T) { } func TestNoDuplicateBPR(t *testing.T) { - p := New() + p := Get() defer resetPortAllocator() if port, err := p.RequestPort(defaultIP, "tcp", p.Begin); err != nil { diff --git a/portmapper/mapper.go b/portmapper/mapper.go index c545eae..e4532ae 100644 --- a/portmapper/mapper.go +++ b/portmapper/mapper.go @@ -42,7 +42,7 @@ type PortMapper struct { // New returns a new instance of PortMapper func New() *PortMapper { - return NewWithPortAllocator(portallocator.New()) + return NewWithPortAllocator(portallocator.Get()) } // NewWithPortAllocator returns a new instance of PortMapper which will use the specified PortAllocator