Implement tests for the port range.
This commit is contained in:
parent
74999eee66
commit
0cf396756c
43
transport/http_transport_test.go
Normal file
43
transport/http_transport_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user