forked from coder/websocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compress_test.go
34 lines (27 loc) · 696 Bytes
/
compress_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// +build !js
package websocket
import (
"strings"
"testing"
"nhooyr.io/websocket/internal/test/assert"
"nhooyr.io/websocket/internal/test/xrand"
)
func Test_slidingWindow(t *testing.T) {
t.Parallel()
const testCount = 99
const maxWindow = 99999
for i := 0; i < testCount; i++ {
t.Run("", func(t *testing.T) {
t.Parallel()
input := xrand.String(maxWindow)
windowLength := xrand.Int(maxWindow)
var sw slidingWindow
sw.init(windowLength)
sw.write([]byte(input))
assert.Equal(t, "window length", windowLength, cap(sw.buf))
if !strings.HasSuffix(input, string(sw.buf)) {
t.Fatalf("r.buf is not a suffix of input: %q and %q", input, sw.buf)
}
})
}
}