Skip to content

Commit

Permalink
SMTP: Adding unit test for message parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Hinderberger committed Jun 26, 2024
1 parent f5920d7 commit e65c71c
Show file tree
Hide file tree
Showing 3 changed files with 621 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/smtp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Server struct {
maxMessageSize int64

mutex sync.RWMutex

clock func() time.Time // making clock mockable for unit testing
}

type session struct {
Expand All @@ -50,6 +52,7 @@ func NewServer(addr string, maxMessageSize int64) *Server {

server := &Server{
maxMessageSize: maxMessageSize,
clock: time.Now,
}

backend := smtp.BackendFunc(func(c *smtp.Conn) (smtp.Session, error) {
Expand Down Expand Up @@ -154,7 +157,7 @@ func (s *session) Data(r io.Reader) error {
defer s.server.mutex.Unlock()

idx := len(s.server.receivedMessages)
now := time.Now()
now := s.server.clock()

logrus.Infof("SMTP: Receiving message from %s to %v at %v", s.from, s.rcptTo, now)
msg, err := NewReceivedMessage(
Expand Down
Loading

0 comments on commit e65c71c

Please sign in to comment.