@@ -2,8 +2,6 @@ package websocket_test
22
33import (
44 "context"
5- "io"
6- "net"
75 "net/http"
86 "os"
97 "testing"
@@ -12,7 +10,6 @@ import (
1210 "github.com/coder/websocket"
1311 "github.com/coder/websocket/internal/test/assert"
1412 "github.com/coder/websocket/internal/test/wstest"
15- "github.com/coder/websocket/internal/test/xrand"
1613)
1714
1815func TestWasm (t * testing.T ) {
@@ -40,62 +37,6 @@ func TestWasm(t *testing.T) {
4037 assert .Success (t , err )
4138}
4239
43- func TestWasmNetConnReadLimit (t * testing.T ) {
44- t .Parallel ()
45-
46- for _ , tc := range []struct {
47- name string
48- netConn func (ctx context.Context , c * websocket.Conn ) net.Conn
49- msgSize int
50- wantErr error
51- }{
52- {"Unset" , func (ctx context.Context , c * websocket.Conn ) net.Conn {
53- return websocket .NetConn (ctx , c , websocket .MessageBinary )
54- }, 65536 , nil },
55- {"DisabledBeforeNetConn" , func (ctx context.Context , c * websocket.Conn ) net.Conn {
56- c .SetReadLimit (- 1 )
57- return websocket .NetConn (ctx , c , websocket .MessageBinary )
58- }, 65536 , nil },
59- {"BeforeNetConn" , func (ctx context.Context , c * websocket.Conn ) net.Conn {
60- c .SetReadLimit (1024 )
61- return websocket .NetConn (ctx , c , websocket .MessageBinary )
62- }, 4096 , websocket .ErrMessageTooBig },
63- {"AfterNetConn" , func (ctx context.Context , c * websocket.Conn ) net.Conn {
64- nc := websocket .NetConn (ctx , c , websocket .MessageBinary )
65- c .SetReadLimit (1024 )
66- return nc
67- }, 4096 , websocket .ErrMessageTooBig },
68- } {
69- t .Run (tc .name , func (t * testing.T ) {
70- t .Parallel ()
71-
72- ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
73- defer cancel ()
74-
75- c , _ , err := websocket .Dial (ctx , os .Getenv ("WS_ECHO_SERVER_URL" ), & websocket.DialOptions {
76- Subprotocols : []string {"echo" },
77- })
78- assert .Success (t , err )
79- // The echo server expects StatusNormalClosure.
80- defer c .Close (websocket .StatusNormalClosure , "" )
81-
82- nc := tc .netConn (ctx , c )
83- msg := []byte (xrand .String (tc .msgSize ))
84- _ , err = nc .Write (msg )
85- assert .Success (t , err )
86-
87- got := make ([]byte , len (msg ))
88- _ , err = io .ReadFull (nc , got )
89- if tc .wantErr != nil {
90- assert .ErrorIs (t , tc .wantErr , err )
91- return
92- }
93- assert .Success (t , err )
94- assert .Equal (t , "read msg" , msg , got )
95- })
96- }
97- }
98-
9940func TestWasmDialTimeout (t * testing.T ) {
10041 t .Parallel ()
10142
0 commit comments