diff --git a/transport/http_transport_test.go b/transport/http_transport_test.go new file mode 100644 index 00000000..72feddd6 --- /dev/null +++ b/transport/http_transport_test.go @@ -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) + } +}