MCPcopy
hub / github.com/coder/websocket / testMask

Function testMask

mask_test.go:40–73  ·  view source on GitHub ↗
(t *testing.T, name string, fn func(b []byte, key uint32) uint32)

Source from the content-addressed store, hash-verified

38}
39
40func testMask(t *testing.T, name string, fn func(b []byte, key uint32) uint32) {
41 t.Run(name, func(t *testing.T) {
42 t.Parallel()
43 for range 9999 {
44 keyb := make([]byte, 4)
45 _, err := rand.Read(keyb)
46 assert.Success(t, err)
47 key := binary.LittleEndian.Uint32(keyb)
48
49 n, err := rand.Int(rand.Reader, big.NewInt(1<<16))
50 assert.Success(t, err)
51
52 b := make([]byte, 1+n.Int64())
53 _, err = rand.Read(b)
54 assert.Success(t, err)
55
56 b2 := make([]byte, len(b))
57 copy(b2, b)
58 b3 := make([]byte, len(b))
59 copy(b3, b)
60
61 key2 := basicMask(b2, key)
62 key3 := fn(b3, key)
63
64 if key2 != key3 {
65 t.Errorf("expected key %X but got %X", key2, key3)
66 }
67 if !bytes.Equal(b2, b3) {
68 t.Error("bad bytes")
69 return
70 }
71 }
72 })
73}

Callers 2

TestMaskASMFunction · 0.85
TestMaskFunction · 0.85

Calls 4

SuccessFunction · 0.92
basicMaskFunction · 0.70
ReadMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…