|
|
@ -6,6 +6,7 @@ import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
@ -33,7 +34,7 @@ func TestServer(t *testing.T) { |
|
|
|
srv := NewServer() |
|
|
|
srv := NewServer() |
|
|
|
srv.HandleFunc("/index", fn) |
|
|
|
srv.HandleFunc("/index", fn) |
|
|
|
|
|
|
|
|
|
|
|
if e, err := srv.Endpoint(); err != nil || e == nil { |
|
|
|
if e, err := srv.Endpoint(); err != nil || e == nil || strings.HasSuffix(e.Host, ":0") { |
|
|
|
t.Fatal(e, err) |
|
|
|
t.Fatal(e, err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -58,17 +59,17 @@ func testClient(t *testing.T, srv *Server) { |
|
|
|
{"PATCH", "/index"}, |
|
|
|
{"PATCH", "/index"}, |
|
|
|
{"DELETE", "/index"}, |
|
|
|
{"DELETE", "/index"}, |
|
|
|
} |
|
|
|
} |
|
|
|
port, ok := host.Port(srv.lis) |
|
|
|
e, err := srv.Endpoint() |
|
|
|
if !ok { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("extract port error: %v", srv.lis) |
|
|
|
t.Fatal(err) |
|
|
|
} |
|
|
|
} |
|
|
|
client, err := NewClient(context.Background(), WithEndpoint(fmt.Sprintf("127.0.0.1:%d", port))) |
|
|
|
client, err := NewClient(context.Background(), WithEndpoint(e.Host)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err) |
|
|
|
t.Fatal(err) |
|
|
|
} |
|
|
|
} |
|
|
|
for _, test := range tests { |
|
|
|
for _, test := range tests { |
|
|
|
var res testData |
|
|
|
var res testData |
|
|
|
url := fmt.Sprintf("http://127.0.0.1:%d%s", port, test.path) |
|
|
|
url := fmt.Sprintf(e.String() + test.path) |
|
|
|
req, err := http.NewRequest(test.method, url, nil) |
|
|
|
req, err := http.NewRequest(test.method, url, nil) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err) |
|
|
|
t.Fatal(err) |
|
|
|