diff options
| author | 2026-03-25 16:22:03 +0000 | |
|---|---|---|
| committer | 2026-03-25 16:22:03 +0000 | |
| commit | 311edcd50f3a84f4b860bde3cb887451d74eaa11 (patch) | |
| tree | be7aa5e9a51e636358f33b1c90637b5024b70dc3 /network/protocol/sideband64k/encoder_partial_write_test.go | |
| parent | README: Split off contrib, benchmarks, remove history for now I guess, etc. (diff) | |
| signature | No 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.go | 46 |
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) + } +} |
