Skip to content

Commit

Permalink
Revert "Change MockSMTP to Server"
Browse files Browse the repository at this point in the history
This reverts commit 80cbfe7.
  • Loading branch information
stanislas-m committed Jun 23, 2018
1 parent 80cbfe7 commit 4805bd9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ package mailers_test
import (
"testing"

"github.com/stanislas-m/mocksmtp"
"github.com/stretchr/testify/require"
"gitlab.com/stanislas-m/mybuffaloproject/mailers"
"github.com/stretchr/testify/require"
"gitlab.com/stanislas-m/mybuffaloproject/mailers"
)

func Test_SendRegistrationMail(t *testing.T) {
r := require.New(t)
ms, v := mailers.SMTP.(*mocksmtp.Server)
ms, v := mailers.SMTP.(*MockSMTP)
r.True(v)
// Clear SMTP queue after test
defer ms.Clear()
Expand Down
22 changes: 11 additions & 11 deletions mocksmtp.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Server
package mocksmtp

import (
"errors"
Expand All @@ -10,15 +10,15 @@ import (
// ErrNoMessage is returned when no message was caught.
var ErrNoMessage = errors.New("no message sent")

// Server is an in-memory implementation for buffalo `Sender`
// MockSMTP is an in-memory implementation for buffalo `Sender`
// interface. It's intended to catch sent messages for test purposes.
type Server struct {
type MockSMTP struct {
messages []mail.Message
mutex sync.RWMutex
}

// Send implements buffalo `Sender` interface, to send mails.
func (s *Server) Send(m mail.Message) error {
func (s *MockSMTP) Send(m mail.Message) error {
s.mutex.Lock()
defer s.mutex.Unlock()
s.messages = append(s.messages, m)
Expand All @@ -27,7 +27,7 @@ func (s *Server) Send(m mail.Message) error {

// LastMessage gets the last sent message, if it exists.
// It returns `NoMessage` error if there is not last message.
func (s *Server) LastMessage() (mail.Message, error) {
func (s *MockSMTP) LastMessage() (mail.Message, error) {
s.mutex.RLock()
defer s.mutex.RUnlock()
l := len(s.Messages())
Expand All @@ -39,30 +39,30 @@ func (s *Server) LastMessage() (mail.Message, error) {
}

// Messages gets the list of sent messages.
func (s *Server) Messages() []mail.Message {
func (s *MockSMTP) Messages() []mail.Message {
s.mutex.RLock()
defer s.mutex.RUnlock()
return s.messages
}

// Count gets the amount of sent messages.
func (s *Server) Count() int {
func (s *MockSMTP) Count() int {
s.mutex.RLock()
defer s.mutex.RUnlock()
return len(s.messages)
}

// Clear destroys all sent messages.
func (s *Server) Clear() {
func (s *MockSMTP) Clear() {
s.mutex.Lock()
defer s.mutex.Unlock()

s.messages = []mail.Message{}
}

// New constructs a new Server.
func New() *Server {
return &Server{
// New constructs a new MockSMTP.
func New() *MockSMTP {
return &MockSMTP{
messages: []mail.Message{},
mutex: sync.RWMutex{},
}
Expand Down

0 comments on commit 4805bd9

Please sign in to comment.