aboutsummaryrefslogtreecommitdiff
path: root/network/protocol/sideband64k/encoder_partial_write_test.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-25 16:22:03 +0000
committerGravatar Runxi Yu2026-03-25 16:22:03 +0000
commit311edcd50f3a84f4b860bde3cb887451d74eaa11 (patch)
treebe7aa5e9a51e636358f33b1c90637b5024b70dc3 /network/protocol/sideband64k/encoder_partial_write_test.go
parentREADME: Split off contrib, benchmarks, remove history for now I guess, etc. (diff)
signatureNo signature
network/protocol: Rename from protocol v0.1.110
Diffstat (limited to 'network/protocol/sideband64k/encoder_partial_write_test.go')
-rw-r--r--network/protocol/sideband64k/encoder_partial_write_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/network/protocol/sideband64k/encoder_partial_write_test.go b/network/protocol/sideband64k/encoder_partial_write_test.go
new file mode 100644
index 00000000..8e35376a
--- /dev/null
+++ b/network/protocol/sideband64k/encoder_partial_write_test.go
@@ -0,0 +1,46 @@
+package sideband64k_test
+
+import (
+ "errors"
+ "io"
+ "testing"
+
+ "codeberg.org/lindenii/furgit/network/protocol/sideband64k"
+)
+
+func TestEncoderHandlesPartialWrites(t *testing.T) {
+ t.Parallel()
+
+ dst := &limitWriter{maxPerWrite: 2}
+ enc := sideband64k.NewEncoder(dst)
+
+ err := enc.WriteProgress([]byte("abc"))
+ if err != nil {
+ t.Fatalf("WriteProgress: %v", err)
+ }
+
+ err = enc.WriteFlushAndFlushIO()
+ if err != nil {
+ t.Fatalf("WriteFlushAndFlushIO: %v", err)
+ }
+
+ if got, want := dst.buf.String(), "0008\x02abc0000"; got != want {
+ t.Fatalf("got %q, want %q", got, want)
+ }
+
+ if dst.flushes != 1 {
+ t.Fatalf("flushes=%d, want 1", dst.flushes)
+ }
+}
+
+func TestEncoderReturnsShortWrite(t *testing.T) {
+ t.Parallel()
+
+ dst := &limitWriter{shortWrite: true}
+ enc := sideband64k.NewEncoder(dst)
+
+ err := enc.WriteData([]byte("x"))
+ if !errors.Is(err, io.ErrShortWrite) {
+ t.Fatalf("got err %v, want io.ErrShortWrite", err)
+ }
+}