@@ -28,6 +28,7 @@ import (
28
28
"bytes"
29
29
"crypto/tls"
30
30
"errors"
31
+ "math/rand"
31
32
"net/http"
32
33
"net/http/httptest"
33
34
"strings"
@@ -46,6 +47,7 @@ import (
46
47
"github.com/gorilla/websocket"
47
48
. "github.com/onsi/ginkgo/v2"
48
49
. "github.com/onsi/gomega"
50
+ "github.com/tinylib/msgp/msgp"
49
51
)
50
52
51
53
var _ = Describe ("IAMAuthInfo" , func () {
@@ -303,6 +305,44 @@ var _ = Describe("WSClient", func() {
303
305
Expect (bytes .Equal (bits , writtenbits )).To (BeTrue ())
304
306
})
305
307
308
+ It ("Sends the message" , func () {
309
+ msgBytes , _ := msg .MarshalMsg (nil )
310
+ Expect (client .Send (& msg )).ToNot (HaveOccurred ())
311
+
312
+ writtenBytes := conn .WriteArgsForCall (0 )
313
+ Expect (bytes .Equal (msgBytes , writtenBytes )).To (BeTrue ())
314
+ })
315
+
316
+ When ("The message is large" , func () {
317
+ const charset = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
318
+
319
+ var (
320
+ expectedBytes int
321
+ messageSize = 65536
322
+ )
323
+
324
+ JustBeforeEach (func () {
325
+ seededRand := rand .New (
326
+ rand .NewSource (time .Now ().UnixNano ()))
327
+ m := make ([]byte , messageSize )
328
+ for i := range m {
329
+ m [i ] = charset [seededRand .Intn (len (charset ))]
330
+ }
331
+ msg .Record = m
332
+
333
+ var b bytes.Buffer
334
+ Expect (msgp .Encode (& b , & msg )).ToNot (HaveOccurred ())
335
+ expectedBytes = len (b .Bytes ())
336
+ })
337
+
338
+ It ("Sends the correct number of bits" , func () {
339
+ Expect (client .Send (& msg )).ToNot (HaveOccurred ())
340
+ Expect (conn .WriteCallCount ()).To (Equal (1 ))
341
+ writtenBytes := len (conn .WriteArgsForCall (0 ))
342
+ Expect (writtenBytes ).To (Equal (expectedBytes ))
343
+ })
344
+ })
345
+
306
346
When ("the connection is disconnected" , func () {
307
347
JustBeforeEach (func () {
308
348
err := client .Disconnect ()
0 commit comments