Skip to content

Commit a3a891b

Browse files
committed
Improve coverage in dial.go and header.go
1 parent 695d679 commit a3a891b

File tree

6 files changed

+63
-6
lines changed

6 files changed

+63
-6
lines changed

ci/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mkdir -p ci/out/websocket
88
testFlags=(
99
-race
1010
"-vet=off"
11-
"-bench=."
11+
# "-bench=."
1212
"-coverprofile=ci/out/coverage.prof"
1313
"-coverpkg=./..."
1414
)

dial_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,53 @@
11
package websocket
22

33
import (
4+
"context"
45
"net/http"
56
"net/http/httptest"
67
"testing"
8+
"time"
79
)
810

11+
func TestBadDials(t *testing.T) {
12+
t.Parallel()
13+
14+
testCases := []struct {
15+
name string
16+
url string
17+
opts DialOptions
18+
}{
19+
{
20+
name: "badURL",
21+
url: "://noscheme",
22+
},
23+
{
24+
name: "badURLScheme",
25+
url: "ftp://nhooyr.io",
26+
},
27+
{
28+
name: "badHTTPClient",
29+
url: "ws://nhooyr.io",
30+
opts: DialOptions{
31+
HTTPClient: &http.Client{
32+
Timeout: time.Minute,
33+
},
34+
},
35+
},
36+
}
37+
38+
for _, tc := range testCases {
39+
tc := tc
40+
t.Run(tc.name, func(t *testing.T) {
41+
t.Parallel()
42+
43+
_, _, err := Dial(context.Background(), tc.url, tc.opts)
44+
if err == nil {
45+
t.Fatalf("expected non nil error: %+v", err)
46+
}
47+
})
48+
}
49+
}
50+
951
func Test_verifyServerHandshake(t *testing.T) {
1052
t.Parallel()
1153

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ require (
1313
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
1414
golang.org/x/tools v0.0.0-20190429184909-35c670923e21
1515
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522
16-
gotest.tools/gotestsum v0.3.5
16+
gotest.tools/gotestsum v0.3.6-0.20190825182939-fc6cb5870c52
1717
mvdan.cc/sh v2.6.4+incompatible
1818
)
19-
20-
replace gotest.tools/gotestsum => github.com/nhooyr/gotestsum v0.3.6-0.20190821172136-aaabbb33254b

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRU
2222
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
2323
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
2424
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
25-
github.com/nhooyr/gotestsum v0.3.6-0.20190821172136-aaabbb33254b h1:t6DbmxEtGMM72Uhs638nBOyK7tjsrDwoMfYO1EfQdFE=
26-
github.com/nhooyr/gotestsum v0.3.6-0.20190821172136-aaabbb33254b/go.mod h1:Mnf3e5FUzXbkCfynWBGOwLssY7gTQgCHObK9tMpAriY=
2725
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
2826
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
2927
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -85,5 +83,7 @@ gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
8583
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
8684
gotest.tools v2.1.0+incompatible h1:5USw7CrJBYKqjg9R7QlA6jzqZKEAtvW82aNmsxxGPxw=
8785
gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
86+
gotest.tools/gotestsum v0.3.6-0.20190825182939-fc6cb5870c52 h1:Qr31uPFyjpOhAgRfKV4ATUnknnLT2X7HFjqwkstdbbE=
87+
gotest.tools/gotestsum v0.3.6-0.20190825182939-fc6cb5870c52/go.mod h1:Mnf3e5FUzXbkCfynWBGOwLssY7gTQgCHObK9tMpAriY=
8888
mvdan.cc/sh v2.6.4+incompatible h1:eD6tDeh0pw+/TOTI1BBEryZ02rD2nMcFsgcvde7jffM=
8989
mvdan.cc/sh v2.6.4+incompatible/go.mod h1:IeeQbZq+x2SUGBensq/jge5lLQbS3XT2ktyp3wrt4x8=

header_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ func randBool() bool {
2121
func TestHeader(t *testing.T) {
2222
t.Parallel()
2323

24+
t.Run("writeNegativeLength", func(t *testing.T) {
25+
t.Parallel()
26+
27+
defer func() {
28+
r := recover()
29+
if r == nil {
30+
t.Fatal("failed to induce panic in writeHeader with negative payload length")
31+
}
32+
}()
33+
34+
writeHeader(nil, header{
35+
payloadLength: -1,
36+
})
37+
})
38+
2439
t.Run("readNegativeLength", func(t *testing.T) {
2540
t.Parallel()
2641

websocket_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ func testServer(tb testing.TB, fn http.HandlerFunc) (s *httptest.Server, closeFn
654654
// https://github.com/crossbario/autobahn-python/tree/master/wstest
655655
func TestAutobahnServer(t *testing.T) {
656656
t.Parallel()
657+
t.Skip()
657658

658659
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
659660
c, err := websocket.Accept(w, r, websocket.AcceptOptions{
@@ -794,6 +795,7 @@ func unusedListenAddr() (string, error) {
794795
// https://github.com/crossbario/autobahn-python/blob/master/wstest/testee_client_aio.py
795796
func TestAutobahnClient(t *testing.T) {
796797
t.Parallel()
798+
t.Skip()
797799

798800
serverAddr, err := unusedListenAddr()
799801
if err != nil {

0 commit comments

Comments
 (0)