MCPcopy Create free account
hub / github.com/entireio/git-sync / TestPrefixedLineWriter

Function TestPrefixedLineWriter

internal/gitproto/push_test.go:26–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestPrefixedLineWriter(t *testing.T) {
27 tests := []struct {
28 name string
29 writes []string
30 want string
31 }{
32 {
33 name: "single line with newline",
34 writes: []string{"counting objects: 42\n"},
35 want: "target: counting objects: 42\n",
36 },
37 {
38 name: "carriage returns are line terminators for in-place updates",
39 writes: []string{"resolving deltas: 10%\rresolving deltas: 50%\rresolving deltas: 100%\n"},
40 want: "target: resolving deltas: 10%\rtarget: resolving deltas: 50%\rtarget: resolving deltas: 100%\n",
41 },
42 {
43 name: "split across multiple writes",
44 writes: []string{"count", "ing ", "objects: 100\nresolving "},
45 want: "target: counting objects: 100\ntarget: resolving ",
46 },
47 {
48 name: "no trailing prefix when stream ends mid-line",
49 writes: []string{"partial progress"},
50 want: "target: partial progress",
51 },
52 {
53 name: "empty write is a noop",
54 writes: []string{"", "visible\n"},
55 want: "target: visible\n",
56 },
57 }
58
59 for _, tc := range tests {
60 t.Run(tc.name, func(t *testing.T) {
61 var buf bytes.Buffer
62 pw := &prefixedLineWriter{w: &buf, prefix: "target: ", atLineStart: true}
63 for _, chunk := range tc.writes {
64 n, err := pw.Write([]byte(chunk))
65 if err != nil {
66 t.Fatalf("Write(%q): %v", chunk, err)
67 }
68 if n != len(chunk) {
69 t.Fatalf("Write(%q) consumed %d, want %d", chunk, n, len(chunk))
70 }
71 }
72 if got := buf.String(); got != tc.want {
73 t.Fatalf("output = %q, want %q", got, tc.want)
74 }
75 })
76 }
77}
78
79func TestProgressSinkNilWhenNotVerbose(t *testing.T) {
80 if got := progressSink(false, "anything: ", nil); got != nil {

Callers

nothing calls this directly

Calls 2

WriteMethod · 0.95
StringMethod · 0.45

Tested by

no test coverage detected