blob: 395d731058a35b3e53b6bf7127c70fb1bc2e05cb (
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
46
47
48
49
50
|
package pktline_test
import (
"bufio"
"bytes"
"testing"
"codeberg.org/lindenii/furgit/protocol/pktline"
)
func TestEncoderBufferedFlushAndFFlush(t *testing.T) {
t.Parallel()
var out bytes.Buffer
bw := bufio.NewWriter(&out)
enc := pktline.NewEncoder(bw)
err := enc.WriteData([]byte("x"))
if err != nil {
t.Fatalf("WriteData: %v", err)
}
if out.Len() != 0 {
t.Fatalf("unexpected immediate output: %q", out.String())
}
err = enc.FlushIO()
if err != nil {
t.Fatalf("FlushIO: %v", err)
}
if out.String() != "0005x" {
t.Fatalf("got %q, want %q", out.String(), "0005x")
}
out.Reset()
bw = bufio.NewWriter(&out)
enc = pktline.NewEncoder(bw)
err = enc.WriteFlushAndFlushIO()
if err != nil {
t.Fatalf("WriteFlushAndFlushIO: %v", err)
}
if out.String() != "0000" {
t.Fatalf("got %q, want %q", out.String(), "0000")
}
}
|