test(mail): derive the mail sender clock from the current date
This commit is contained in:
1 parent
a38d7571ea
commit
c410636b7f
3 files changed
+105
-4
No files matched your search
@@ -140,6 +140,16 @@ func (server *Server) Script(replies ...Reply) {
|
||||
server.scripted = append(server.scripted, replies...)
|
||||
}
|
||||
|
||||
// ClearScript drops the queued answers that no call has used and returns
|
||||
// their number, so a test that stops early does not hand them to the next one.
|
||||
func (server *Server) ClearScript() int {
|
||||
server.mu.Lock()
|
||||
defer server.mu.Unlock()
|
||||
left := len(server.scripted)
|
||||
server.scripted = nil
|
||||
return left
|
||||
}
|
||||
|
||||
// SetDelay makes the fixture wait before it answers every later call, so a
|
||||
// test can act while a send is in flight.
|
||||
func (server *Server) SetDelay(delay time.Duration) { server.delay.Store(int64(delay)) }
|
||||
|
||||
@@ -57,6 +57,26 @@ func TestFixtureAnswersLikeResendForTheLoopbackTransport(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestClearScriptDropsUnusedAnswers(t *testing.T) {
|
||||
fixture := resendfixture.New()
|
||||
defer fixture.Close()
|
||||
sender, err := resend.NewLoopbackSender(resendfixture.APIKey, "Lincodex <no-reply@example.com>", 5*time.Second, fixture.URL(), time.Now)
|
||||
if err != nil {
|
||||
t.Fatalf("NewLoopbackSender() error = %v", err)
|
||||
}
|
||||
fixture.Script(resendfixture.Reply{Status: 429, Name: "daily_quota_exceeded"}, resendfixture.Reply{Status: 500, Name: "application_error"})
|
||||
if left := fixture.ClearScript(); left != 2 {
|
||||
t.Fatalf("ClearScript() = %d, want 2", left)
|
||||
}
|
||||
if left := fixture.ClearScript(); left != 0 {
|
||||
t.Fatalf("second ClearScript() = %d, want 0", left)
|
||||
}
|
||||
result, err := sender.Send(t.Context(), newMail(t, "Subject", "delivery/1"))
|
||||
if err != nil || result.Outcome != outbound.MailOutcomeAccepted {
|
||||
t.Fatalf("Send() after ClearScript() = %+v, %v; want accepted", result, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoopbackSenderRefusesAnyOtherHost(t *testing.T) {
|
||||
for _, endpoint := range []string{
|
||||
"https://api.resend.com/emails",
|
||||
|
||||
Reference in new issue
Block a user