fix: add mutex to MockAuditor export to prevent race (#5189)

See: https://github.com/coder/coder/actions/runs/3575201153/jobs/6011435900.
This commit is contained in:
Kyle Carberry 2022-11-30 17:25:30 +01:00 committed by GitHub
parent 41f10e7b69
commit 2a73362026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package audit
import (
"context"
"sync"
"github.com/coder/coder/coderd/database"
)
@ -30,10 +31,13 @@ func NewMock() *MockAuditor {
}
type MockAuditor struct {
mutex sync.Mutex
AuditLogs []database.AuditLog
}
func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error {
a.mutex.Lock()
defer a.mutex.Unlock()
a.AuditLogs = append(a.AuditLogs, alog)
return nil
}