Revert "Added more test coverage for portmapper package."

This reverts commit 2fc4f3154f.

Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
Madhu Venugopal 2015-05-21 10:12:21 -07:00
parent a82b6032d3
commit dbb71728f9
1 changed files with 10 additions and 41 deletions

View File

@ -2,20 +2,15 @@ package portmapper
import ( import (
"net" "net"
"os"
"testing" "testing"
"time"
"github.com/docker/docker/pkg/reexec"
"github.com/docker/libnetwork/iptables" "github.com/docker/libnetwork/iptables"
"github.com/docker/libnetwork/netutils" _ "github.com/docker/libnetwork/netutils"
) )
func TestMain(m *testing.M) { func init() {
if reexec.Init() { // override this func to mock out the proxy server
return newProxy = newMockProxyCommand
}
os.Exit(m.Run())
} }
func TestSetIptablesChain(t *testing.T) { func TestSetIptablesChain(t *testing.T) {
@ -37,7 +32,6 @@ func TestSetIptablesChain(t *testing.T) {
} }
func TestMapTCPPorts(t *testing.T) { func TestMapTCPPorts(t *testing.T) {
defer netutils.SetupTestNetNS(t)()
pm := New() pm := New()
dstIP1 := net.ParseIP("192.168.0.1") dstIP1 := net.ParseIP("192.168.0.1")
dstIP2 := net.ParseIP("192.168.0.2") dstIP2 := net.ParseIP("192.168.0.2")
@ -117,7 +111,6 @@ func TestGetUDPIPAndPort(t *testing.T) {
} }
func TestMapUDPPorts(t *testing.T) { func TestMapUDPPorts(t *testing.T) {
defer netutils.SetupTestNetNS(t)()
pm := New() pm := New()
dstIP1 := net.ParseIP("192.168.0.1") dstIP1 := net.ParseIP("192.168.0.1")
dstIP2 := net.ParseIP("192.168.0.2") dstIP2 := net.ParseIP("192.168.0.2")
@ -164,11 +157,6 @@ func TestMapUDPPorts(t *testing.T) {
} }
func TestMapAllPortsSingleInterface(t *testing.T) { func TestMapAllPortsSingleInterface(t *testing.T) {
newProxy = newMockProxyCommand
defer func() {
newProxy = newProxyCommand
}()
defer netutils.SetupTestNetNS(t)()
pm := New() pm := New()
dstIP1 := net.ParseIP("0.0.0.0") dstIP1 := net.ParseIP("0.0.0.0")
srcAddr1 := &net.TCPAddr{Port: 1080, IP: net.ParseIP("172.16.0.1")} srcAddr1 := &net.TCPAddr{Port: 1080, IP: net.ParseIP("172.16.0.1")}
@ -177,6 +165,12 @@ func TestMapAllPortsSingleInterface(t *testing.T) {
var host net.Addr var host net.Addr
var err error var err error
defer func() {
for _, val := range hosts {
pm.Unmap(val)
}
}()
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
start, end := pm.Allocator.Begin, pm.Allocator.End start, end := pm.Allocator.Begin, pm.Allocator.End
for i := start; i < end; i++ { for i := start; i < end; i++ {
@ -200,28 +194,3 @@ func TestMapAllPortsSingleInterface(t *testing.T) {
hosts = []net.Addr{} hosts = []net.Addr{}
} }
} }
func TestExecProxy(t *testing.T) {
defer netutils.SetupTestNetNS(t)()
args := []string{
userlandProxyCommandName,
"-proto", "tcp",
"-host-ip", "0.0.0.0",
"-host-port", "9999",
"-container-ip", "172.168.1.1",
"-container-port", "8888",
}
os.Args = args
doneChan := make(chan bool)
go func() {
execProxy()
doneChan <- true
}()
select {
case <-doneChan:
t.Fatal("execProxy is not supposed to exit")
case <-time.After(3 * time.Second):
return
}
}