]>
src.bluestatic.org Git - mailpopbox.git/blob - smtp/relay_test.go
2 // Copyright 2020 Blue Static <https://www.bluestatic.org>
3 // This program is free software licensed under the GNU General Public License,
4 // version 3.0. The full text of the license can be found in LICENSE.txt.
5 // SPDX-License-Identifier: GPL-3.0-only
14 "github.com/uber-go/zap"
17 type deliveryServer
struct {
22 func (s
*deliveryServer
) OnMessageDelivered(env Envelope
) *ReplyLine
{
23 s
.messages
= append(s
.messages
, env
)
27 func TestRelayRoundTrip(t
*testing
.T
) {
29 testServer
: testServer
{domain
: "receive.net"},
35 MailFrom
: mail
.Address
{Address
: "from@sender.org"},
36 RcptTo
: []mail
.Address
{{Address
: "to@receive.net"}},
37 Data
: []byte("~~~Message~~~\n"),
41 relayMessageToHost(s
, env
, zap
.New(zap
.NullEncoder()), env
.RcptTo
[0].Address
, l
.Addr().String())
43 if len(s
.messages
) != 1 {
44 t
.Errorf("Expected 1 message to be delivered, got %d", len(s
.messages
))
48 received
:= s
.messages
[0]
50 if env
.MailFrom
.Address
!= received
.MailFrom
.Address
{
51 t
.Errorf("Expected MailFrom %s, got %s", env
.MailFrom
.Address
, received
.MailFrom
.Address
)
53 if len(received
.RcptTo
) != 1 {
54 t
.Errorf("Expected 1 RcptTo, got %d", len(received
.RcptTo
))
57 if env
.RcptTo
[0].Address
!= received
.RcptTo
[0].Address
{
58 t
.Errorf("Expected RcptTo %s, got %s", env
.RcptTo
[0].Address
, received
.RcptTo
[0].Address
)
61 if !bytes
.HasSuffix(received
.Data
, env
.Data
) {
62 t
.Errorf("Delivered message does not match relayed one. Delivered=%q Relayed=%q", string(env
.Data
), string(received
.Data
))