merge v0.23.0-rc changes

This commit is contained in:
Gani Georgiev
2024-09-29 19:23:19 +03:00
parent ad92992324
commit 844f18cac3
753 changed files with 85141 additions and 63396 deletions
+55 -16
View File
@@ -1,6 +1,7 @@
package tests
import (
"slices"
"sync"
"github.com/pocketbase/pocketbase/tools/mailer"
@@ -8,15 +9,19 @@ import (
var _ mailer.Mailer = (*TestMailer)(nil)
// TestMailer is a mock `mailer.Mailer` implementation.
// TestMailer is a mock [mailer.Mailer] implementation.
type TestMailer struct {
mux sync.Mutex
mux sync.Mutex
messages []*mailer.Message
}
TotalSend int
LastMessage mailer.Message
// Send implements [mailer.Mailer] interface.
func (tm *TestMailer) Send(m *mailer.Message) error {
tm.mux.Lock()
defer tm.mux.Unlock()
// @todo consider deprecating the above 2 fields?
SentMessages []mailer.Message
tm.messages = append(tm.messages, m)
return nil
}
// Reset clears any previously test collected data.
@@ -24,19 +29,53 @@ func (tm *TestMailer) Reset() {
tm.mux.Lock()
defer tm.mux.Unlock()
tm.TotalSend = 0
tm.LastMessage = mailer.Message{}
tm.SentMessages = nil
tm.messages = nil
}
// Send implements `mailer.Mailer` interface.
func (tm *TestMailer) Send(m *mailer.Message) error {
// TotalSend returns the total number of sent messages.
func (tm *TestMailer) TotalSend() int {
tm.mux.Lock()
defer tm.mux.Unlock()
tm.TotalSend++
tm.LastMessage = *m
tm.SentMessages = append(tm.SentMessages, tm.LastMessage)
return nil
return len(tm.messages)
}
// Messages returns a shallow copy of all of the collected test messages.
func (tm *TestMailer) Messages() []*mailer.Message {
tm.mux.Lock()
defer tm.mux.Unlock()
return slices.Clone(tm.messages)
}
// FirstMessage returns a shallow copy of the first sent message.
//
// Returns an empty mailer.Message struct if there are no sent messages.
func (tm *TestMailer) FirstMessage() mailer.Message {
tm.mux.Lock()
defer tm.mux.Unlock()
var m mailer.Message
if len(tm.messages) > 0 {
return *tm.messages[0]
}
return m
}
// LastMessage returns a shallow copy of the last sent message.
//
// Returns an empty mailer.Message struct if there are no sent messages.
func (tm *TestMailer) LastMessage() mailer.Message {
tm.mux.Lock()
defer tm.mux.Unlock()
var m mailer.Message
if len(tm.messages) > 0 {
return *tm.messages[len(tm.messages)-1]
}
return m
}