forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 7
/
writer_test.go
49 lines (42 loc) · 963 Bytes
/
writer_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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package qlog
import (
"bytes"
"errors"
"io"
"log"
"os"
"github.com/quic-go/quic-go/internal/protocol"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
type limitedWriter struct {
io.WriteCloser
N int
written int
}
func (w *limitedWriter) Write(p []byte) (int, error) {
if w.written+len(p) > w.N {
return 0, errors.New("writer full")
}
n, err := w.WriteCloser.Write(p)
w.written += n
return n, err
}
var _ = Describe("Writing", func() {
It("stops writing when encountering an error", func() {
buf := &bytes.Buffer{}
t := NewConnectionTracer(
&limitedWriter{WriteCloser: nopWriteCloser(buf), N: 250},
protocol.PerspectiveServer,
protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef}),
)
for i := uint32(0); i < 1000; i++ {
t.UpdatedPTOCount(i)
}
b := &bytes.Buffer{}
log.SetOutput(b)
defer log.SetOutput(os.Stdout)
t.Close()
Expect(b.String()).To(ContainSubstring("writer full"))
})
})