MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / AssertLogContains

Function AssertLogContains

base/logging.go:414–427  ·  view source on GitHub ↗

AssertLogContains asserts that the logs produced by function f contain string s.

(t *testing.T, s string, f func())

Source from the content-addressed store, hash-verified

412
413// AssertLogContains asserts that the logs produced by function f contain string s.
414func AssertLogContains(t *testing.T, s string, f func()) {
415 // Temporarily override logger output
416 b := &bytes.Buffer{}
417 mw := io.MultiWriter(b, os.Stderr)
418 consoleLogger.Load().logger.SetOutput(mw)
419 // Call the given function
420 f()
421
422 FlushLogBuffers()
423 consoleLogger.Load().FlushBufferToLog()
424 // do not reset output in defer, since we are accessing b.String() after
425 consoleLogger.Load().logger.SetOutput(os.Stderr)
426 assert.Contains(t, b.String(), s)
427}
428
429// AssertLogNotContains asserts that the logs produced by function f do not contain string s.
430func AssertLogNotContains(t *testing.T, s string, f func()) {

Callers 8

TestBadCORSValuesConfigFunction · 0.92
TestHTTPLoggingRedactionFunction · 0.92
TestImportFilterLoggingFunction · 0.92
TestUnprocessableDeltasFunction · 0.92
TestBlipCorrelationIDFunction · 0.92
TestAuditFieldsMergeFunction · 0.85
TestRedactedLogFuncsFunction · 0.85

Calls 5

FlushLogBuffersFunction · 0.85
LoadMethod · 0.80
FlushBufferToLogMethod · 0.80
ContainsMethod · 0.65
StringMethod · 0.65

Tested by 8

TestBadCORSValuesConfigFunction · 0.74
TestHTTPLoggingRedactionFunction · 0.74
TestImportFilterLoggingFunction · 0.74
TestUnprocessableDeltasFunction · 0.74
TestBlipCorrelationIDFunction · 0.74
TestAuditFieldsMergeFunction · 0.68
TestRedactedLogFuncsFunction · 0.68