Implement tests for the port range.

This commit is contained in:
Jelmer Snoeck 2016-03-02 15:33:42 +00:00
parent 74999eee66
commit 0cf396756c

View File

@ -0,0 +1,43 @@
package transport_test
import (
"strings"
"testing"
"github.com/micro/go-micro/transport"
)
func TestHTTPTransport_PortRange(t *testing.T) {
tp := transport.NewTransport([]string{})
lsn1, err := tp.Listen(":44444-44448")
if err != nil {
t.Errorf("Did not expect an error, got %s", err)
}
expectedPort(t, "44444", lsn1)
lsn2, err := tp.Listen(":44444-44448")
if err != nil {
t.Errorf("Did not expect an error, got %s", err)
}
expectedPort(t, "44445", lsn2)
lsn, err := tp.Listen(":0")
if err != nil {
t.Errorf("Did not expect an error, got %s", err)
}
lsn.Close()
lsn1.Close()
lsn2.Close()
}
func expectedPort(t *testing.T, expected string, lsn transport.Listener) {
parts := strings.Split(lsn.Addr(), ":")
port := parts[len(parts)-1]
if port != expected {
lsn.Close()
t.Errorf("Expected address to be `%s`, got `%s`", expected, port)
}
}