44 lines
879 B
Go
44 lines
879 B
Go
|
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)
|
||
|
}
|
||
|
}
|