MCPcopy Create free account
hub / github.com/cockroachdb/redact / TestRedactStream

Function TestRedactStream

markers_test.go:311–366  ·  view source on GitHub ↗

TestRedactStream verifies that the redaction logic is able to both add the redaction quotes and also respects the format parameters and verb.

(t *testing.T)

Source from the content-addressed store, hash-verified

309// add the redaction quotes and also respects the format parameters
310// and verb.
311func TestRedactStream(t *testing.T) {
312 testData := []struct {
313 f string
314 input interface{}
315 expected string
316 }{
317 {"%v", "", ""},
318 {"%v", " ", "‹ ›"},
319 {"‹› %v ›››", "abc", "?? ‹abc› ???"},
320 {"%v", "abc ", "‹abc ›"},
321 {"%q", "abc ", `‹"abc "›`},
322 {"%v", "abc\n ", "‹abc›\n‹ ›"},
323 {"%v", "abc \n\n", "‹abc ›\n\n"},
324 {"%v", " \n\nabc", "‹ ›\n\n‹abc›"},
325 {"%v", "‹abc›", "‹?abc?›"},
326 {"%v", 123, "‹123›"},
327 {"%05d", 123, "‹00123›"},
328 {"%v", Safe(123), "123"},
329 {"%05d", Safe(123), "00123"},
330 {"%#x", 17, "‹0x11›"},
331 {"%+v", &complexObj{"‹›"}, "&{v:‹??›}"},
332 {"%v", &safestringer{"as"}, "as"},
333 {"%v", &stringer{"as"}, "‹as›"},
334 {"%v", &safefmtformatter{"af"}, "af"},
335 {"%v", &fmtformatter{"af"}, "‹af›"},
336 {"%v", &safemsg{"az"}, "az"},
337 // Printers that cause panics during rendering.
338 {"%v", &safepanicObj1{"s1-x‹y›z"}, `%!v(PANIC=String method: s1-x?y?z)`},
339 {"%v", &safepanicObj2{"s2-x‹y›z"}, `%!v(PANIC=Format method: s2-x?y?z)`},
340 {"%v", &panicObj1{"p1-x‹y›z"}, `%!v(PANIC=String method: ‹p1-x?y?z›)`},
341 {"%v", &panicObj2{"p2-x‹y›z"}, `%!v(PANIC=Format method: ‹p2-x?y?z›)`},
342 {"%v", &panicObj3{"p3-x‹y›z"}, `%!v(PANIC=SafeFormat method: ‹p3-x?y?z›)`},
343 {"%v", &panicObj4{"unused"}, `%!v(PANIC=SafeMessager method: ‹woo›)`},
344 {"%v", (*safestringer)(nil), `<nil>`},
345 {"%v", (*safemsg)(nil), `<nil>`},
346 {"%v", (*safefmtformatter)(nil), `<nil>`},
347 {"%v", (*safepanicObj1)(nil), `<nil>`},
348 {"%v", (*safepanicObj2)(nil), `<nil>`},
349 {"%v", (*panicObj1)(nil), `<nil>`},
350 {"%v", (*panicObj2)(nil), `<nil>`},
351 {"%v", (*panicObj3)(nil), `<nil>`},
352 {"%v", (*panicObj4)(nil), `<nil>`},
353 }
354
355 for i, tc := range testData {
356 var buf strings.Builder
357 n, _ := Fprintf(&buf, tc.f, tc.input)
358 result := buf.String()
359 if result != tc.expected {
360 t.Errorf("%d: expected %q, got %q", i, tc.expected, result)
361 }
362 if n != len(result) {
363 t.Errorf("%d: expected len %d, got %d", i, n, len(result))
364 }
365 }
366}
367
368func Example_format() {

Callers

nothing calls this directly

Calls 3

SafeFunction · 0.70
FprintfFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…