Skip to content

Commit

Permalink
Merge branch 'main' into feat/metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
olexsmir committed Oct 3, 2024
2 parents 3dc84a8 + a4b3d8e commit 9d46d93
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions internal/mailer/testing_mailer.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
package mailer

import "context"
import (
"context"
"sync"
)

var _ Mailer = (*TestMailer)(nil)

type TestMailer struct {
mu sync.Mutex

emails map[string]string
}

// NewTestMailer create a mailer for tests
// that implementation of Mailer stores all sent email in memory
// to get the last email sent to a specific email use GetLastSentEmailToEmail
func NewTestMailer() *TestMailer {
return &TestMailer{
return &TestMailer{ //nolint:exhaustruct
emails: make(map[string]string),
}
}

func (t *TestMailer) Send(_ context.Context, to, _, content string) error {
t.mu.Lock()
defer t.mu.Unlock()

t.emails[to] = content

return nil
}

// GetLastSentEmailToEmail returns the last email sent to a specific email
func (t *TestMailer) GetLastSentEmailToEmail(email string) string {
return t.emails[email]
t.mu.Lock()
defer t.mu.Unlock()

e := t.emails[email]

return e
}

0 comments on commit 9d46d93

Please sign in to comment.