MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestCappedStringWriter

Function TestCappedStringWriter

cmd/hooks_test.go:147–181  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestCappedStringWriter(t *testing.T) {
148 t.Run("captures full output under limit", func(t *testing.T) {
149 w := newCappedStringWriter(8)
150 n, err := w.Write([]byte("hello"))
151 if err != nil {
152 t.Fatalf("unexpected error: %v", err)
153 }
154 if n != 5 {
155 t.Fatalf("expected 5 bytes written, got %d", n)
156 }
157 if got := w.String(); got != "hello" {
158 t.Fatalf("expected %q, got %q", "hello", got)
159 }
160 if w.Truncated() {
161 t.Fatal("expected writer not truncated")
162 }
163 })
164
165 t.Run("caps output and marks truncated", func(t *testing.T) {
166 w := newCappedStringWriter(4)
167 n, err := w.Write([]byte("helloworld"))
168 if err != nil {
169 t.Fatalf("unexpected error: %v", err)
170 }
171 if n != len("helloworld") {
172 t.Fatalf("expected write count %d, got %d", len("helloworld"), n)
173 }
174 if got := w.String(); got != "hell" {
175 t.Fatalf("expected %q, got %q", "hell", got)
176 }
177 if !w.Truncated() {
178 t.Fatal("expected writer to be truncated")
179 }
180 })
181}
182
183func TestHookTimeoutFromEnv(t *testing.T) {
184 tests := []struct {

Callers

nothing calls this directly

Calls 4

newCappedStringWriterFunction · 0.85
WriteMethod · 0.80
TruncatedMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected