rpc/client: handle client creation error in new wsclient
Client returns error if it can't parse endpoint string. WSClient should check client error or there could be panic at `cl.cli = nil` expression.
This commit is contained in:
parent
29e66925aa
commit
aca6f2f3ad
2 changed files with 19 additions and 0 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -297,3 +298,17 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewWS(t *testing.T) {
|
||||
srv := initTestServer(t, "")
|
||||
defer srv.Close()
|
||||
|
||||
t.Run("good", func(t *testing.T) {
|
||||
_, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("bad URL", func(t *testing.T) {
|
||||
_, err := NewWS(context.TODO(), strings.Trim(srv.URL, "http://"), Options{})
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue