Skip to content

Commit

Permalink
test: reset the log recorder after each test to enable tests with log…
Browse files Browse the repository at this point in the history
… recording to share an environment;
  • Loading branch information
ajscholl committed Aug 5, 2024
1 parent c2f3f2a commit b8cc599
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/test/env/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ func (e *Environment) Logs() LogRecords {
return e.logger.Records()
}

func (e *Environment) ResetLogs() {
e.logger.Reset()
}

func (e *Environment) Clock() clock.Clock {
return clock.Provider
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/test/env/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type (
RecordingLogger interface {
log.GosoLogger
Records() []LogRecord
Reset()
}

recordingLogger struct {
Expand Down Expand Up @@ -102,6 +103,13 @@ func (r recordingLogger) Records() []LogRecord {
return records
}

func (r recordingLogger) Reset() {
r.mutex.RLock()
defer r.mutex.RUnlock()

*r.records = []LogRecord{}
}

func (h handlerInMemoryWriter) Channels() []string {
return []string{}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/test/suite/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func runTestCaseWithSharedEnvironment(t *testing.T, suite TestingSuite, suiteOpt
stream.ResetInMemoryInputs()
stream.ResetInMemoryOutputs()
stream.ResetProducerDaemons()
environment.ResetLogs()
}
}

Expand Down

0 comments on commit b8cc599

Please sign in to comment.