mirror of
https://github.com/pocketbase/pocketbase.git
synced 2024-11-21 13:35:49 +02:00
[#5157] added tests.TestMailer
mutex
This commit is contained in:
parent
bc1bcac5a1
commit
5b58a78e64
@ -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.
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user