@@ -485,6 +485,41 @@ func TestConnection(t *testing.T) {
485
485
}
486
486
listener .assertMethodsCalled (t , 1 , 1 )
487
487
})
488
+ t .Run ("message too large errors" , func (t * testing.T ) {
489
+ testCases := []struct {
490
+ name string
491
+ buffer []byte
492
+ desc description.Server
493
+ }{
494
+ {
495
+ "message too large errors with small max message size" ,
496
+ []byte {0x0A , 0x00 , 0x00 , 0x00 }, // defines a message size of 10 in hex with the first four bytes.
497
+ description.Server {MaxMessageSize : 9 },
498
+ },
499
+ {
500
+ "message too large errors with default max message size" ,
501
+ []byte {0x01 , 0x6C , 0xDC , 0x02 }, // defines a message size of 48000001 in hex with the first four bytes.
502
+ description.Server {},
503
+ },
504
+ }
505
+ for _ , tc := range testCases {
506
+ t .Run (tc .name , func (t * testing.T ) {
507
+ err := errors .New ("length of read message too large" )
508
+ tnc := & testNetConn {buf : make ([]byte , len (tc .buffer ))}
509
+ copy (tnc .buf , tc .buffer )
510
+ conn := & connection {id : "foobar" , nc : tnc , connected : connected , desc : tc .desc }
511
+ listener := newTestCancellationListener (false )
512
+ conn .cancellationListener = listener
513
+
514
+ want := ConnectionError {ConnectionID : "foobar" , Wrapped : err , message : err .Error ()}
515
+ _ , got := conn .readWireMessage (context .Background (), nil )
516
+ if ! cmp .Equal (got , want , cmp .Comparer (compareErrors )) {
517
+ t .Errorf ("errors do not match. got %v; want %v" , got , want )
518
+ }
519
+ listener .assertMethodsCalled (t , 1 , 1 )
520
+ })
521
+ }
522
+ })
488
523
t .Run ("success" , func (t * testing.T ) {
489
524
want := []byte {0x0A , 0x00 , 0x00 , 0x00 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0A }
490
525
tnc := & testNetConn {buf : make ([]byte , len (want ))}
0 commit comments