Skip to content

Commit

Permalink
syncing up to 3318633f3f421aa547c559500a04a7949cd38c6f
Browse files Browse the repository at this point in the history
Co-authored-by: Carl Noel <[email protected]>
  • Loading branch information
superblocksadmin and noelcarl committed Aug 30, 2024
1 parent 0e8a650 commit dfce01f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/utils/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func NewZapTestObservedLogger(tb testing.TB) (*zap.Logger, *observer.ObservedLog
return log, logs
}

// RequireLogContains finds at least one log message that has the given Message at the given level.
func RequireLogContains(tb FatalTB, logs *observer.ObservedLogs, level zapcore.Level, msg string) {
// LogContains returns true if there is at least one log that has the given Message at the given level.
func LogContains(logs *observer.ObservedLogs, level zapcore.Level, msg string) bool {
found := false
for _, le := range logs.FilterLevelExact(level).All() {
if le.Message == msg {
Expand All @@ -47,7 +47,13 @@ func RequireLogContains(tb FatalTB, logs *observer.ObservedLogs, level zapcore.L
}
}

if !found {
return found
}

// RequireLogContains finds at least one log message that has the given Message at the given level, or fails
// the test if not.
func RequireLogContains(tb FatalTB, logs *observer.ObservedLogs, level zapcore.Level, msg string) {
if !LogContains(logs, level, msg) {
tb.Fatalf("failed: logs (level %q) does not contain %q", level.String(), msg)
}
}
Expand Down

0 comments on commit dfce01f

Please sign in to comment.