Test success case of using WaitForPort func.
This commit is contained in:
parent
a35c0bb295
commit
1957ef1d73
1 changed files with 21 additions and 0 deletions
|
@ -2,6 +2,10 @@ package testtool
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -15,6 +19,23 @@ func TestGetFreePort(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWaitForPort(t *testing.T) {
|
||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||
defer s.Close()
|
||||
|
||||
u, err := url.Parse(s.URL)
|
||||
require.Nil(t, err)
|
||||
_, port, err := net.SplitHostPort(u.Host)
|
||||
require.Nil(t, err)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
|
||||
WaitForPort(ctx, port)
|
||||
|
||||
require.NoError(t, ctx.Err())
|
||||
}
|
||||
|
||||
func TestWaitForPort_timeout(t *testing.T) {
|
||||
p, err := GetFreePort()
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
Loading…
Reference in a new issue