MCPcopy
hub / github.com/nats-io/nats.go / TestWSCompressionWithContinuationFrames

Function TestWSCompressionWithContinuationFrames

ws_test.go:565–605  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

563}
564
565func TestWSCompressionWithContinuationFrames(t *testing.T) {
566 uncompressed := []byte("this is an uncompressed message with AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
567 buf := &bytes.Buffer{}
568 compressor, _ := flate.NewWriter(buf, flate.BestSpeed)
569 compressor.Write(uncompressed)
570 compressor.Close()
571 b := buf.Bytes()
572 if len(b) < 30 {
573 panic("revisit test so that compressed buffer is more than 30 bytes long")
574 }
575
576 srbuf := &bytes.Buffer{}
577 // We are going to split this in several frames.
578 fh := []byte{66, 10}
579 srbuf.Write(fh)
580 srbuf.Write(b[:10])
581 fh = []byte{0, 10}
582 srbuf.Write(fh)
583 srbuf.Write(b[10:20])
584 fh = []byte{wsFinalBit, 0}
585 fh[1] = byte(len(b) - 20)
586 srbuf.Write(fh)
587 srbuf.Write(b[20:])
588
589 r := wsNewReader(srbuf)
590 rbuf := make([]byte, 100)
591 n, err := r.Read(rbuf[:15])
592 // Since we have a partial of compressed message, the library keeps track
593 // of buffer, but it can't return anything at this point, so n==0 err==nil
594 // is the expected result.
595 if n != 0 || err != nil {
596 t.Fatalf("Error reading: n=%v err=%v", n, err)
597 }
598 n, err = r.Read(rbuf)
599 if n != len(uncompressed) || err != nil {
600 t.Fatalf("Error reading: n=%v err=%v", n, err)
601 }
602 if !reflect.DeepEqual(uncompressed, rbuf[:n]) {
603 t.Fatalf("Unexpected uncompressed data: %v", rbuf[:n])
604 }
605}
606
607func TestWSTlsNoConfig(t *testing.T) {
608 opts := GetDefaultOptions()

Callers

nothing calls this directly

Calls 6

wsNewReaderFunction · 0.85
FatalfMethod · 0.80
BytesMethod · 0.65
WriteMethod · 0.45
CloseMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected