chore: wrap audit logs in a mutex to fix data race (#6898)

This was seen in `main`!
This commit is contained in:
Kyle Carberry
2023-03-30 12:13:03 -05:00
committed by GitHub
parent 5780006adb
commit a63c97b8de
11 changed files with 109 additions and 101 deletions
+10 -2
View File
@@ -39,13 +39,21 @@ func NewMock() *MockAuditor {
type MockAuditor struct {
mutex sync.Mutex
AuditLogs []database.AuditLog
auditLogs []database.AuditLog
}
func (a *MockAuditor) AuditLogs() []database.AuditLog {
a.mutex.Lock()
defer a.mutex.Unlock()
logs := make([]database.AuditLog, len(a.auditLogs))
copy(logs, a.auditLogs)
return logs
}
func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error {
a.mutex.Lock()
defer a.mutex.Unlock()
a.AuditLogs = append(a.AuditLogs, alog)
a.auditLogs = append(a.auditLogs, alog)
return nil
}