blob: e95d06efcff721acc51a3f907ec4f162973b226f (
about) (
plain) (
blame)
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
|
package iolimit_test
import (
"bytes"
"testing"
"codeberg.org/lindenii/furgit/internal/iolimit"
)
func TestCappedCaptureWriterWithinLimit(t *testing.T) {
t.Parallel()
writer := iolimit.NewCappedCaptureWriter(8)
_, _ = writer.Write([]byte("hello"))
_, _ = writer.Write([]byte("!"))
if got := writer.Bytes(); !bytes.Equal(got, []byte("hello!")) {
t.Fatalf("Bytes() = %q, want %q", got, "hello!")
}
}
func TestCappedCaptureWriterExceededLimit(t *testing.T) {
t.Parallel()
writer := iolimit.NewCappedCaptureWriter(4)
_, _ = writer.Write([]byte("abcd"))
_, _ = writer.Write([]byte("x"))
if got := writer.Bytes(); got != nil {
t.Fatalf("Bytes() = %q, want nil after overflow", got)
}
}
func TestCappedCaptureWriterZeroLimit(t *testing.T) {
t.Parallel()
writer := iolimit.NewCappedCaptureWriter(0)
_, _ = writer.Write([]byte("x"))
if got := writer.Bytes(); got != nil {
t.Fatalf("Bytes() = %q, want nil at zero limit", got)
}
}
|