diff --git a/CHANGELOG.md b/CHANGELOG.md index bc7e6765..cb2dd29a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.22.15-WIP + +- Added `tests.TestMailer` mutex to minimize the data race warnings during tests ([#5157](https://github.com/pocketbase/pocketbase/issues/5157)). + + ## v0.22.14 - Added OAuth2 POST redirect support (in case of `response_mode=form_post`) to allow specifying scopes for the Apple OAuth2 integration. diff --git a/tests/mailer.go b/tests/mailer.go index 82d97c1f..9672ad8b 100644 --- a/tests/mailer.go +++ b/tests/mailer.go @@ -1,6 +1,8 @@ package tests import ( + "sync" + "github.com/pocketbase/pocketbase/tools/mailer" ) @@ -8,6 +10,8 @@ var _ mailer.Mailer = (*TestMailer)(nil) // TestMailer is a mock `mailer.Mailer` implementation. type TestMailer struct { + mux sync.Mutex + TotalSend int LastMessage mailer.Message @@ -17,6 +21,9 @@ type TestMailer struct { // Reset clears any previously test collected data. func (tm *TestMailer) Reset() { + tm.mux.Lock() + defer tm.mux.Unlock() + tm.TotalSend = 0 tm.LastMessage = mailer.Message{} tm.SentMessages = nil @@ -24,6 +31,9 @@ func (tm *TestMailer) Reset() { // Send implements `mailer.Mailer` interface. func (tm *TestMailer) Send(m *mailer.Message) error { + tm.mux.Lock() + defer tm.mux.Unlock() + tm.TotalSend++ tm.LastMessage = *m tm.SentMessages = append(tm.SentMessages, tm.LastMessage)