-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathclient_test.go
More file actions
105 lines (99 loc) · 2.06 KB
/
client_test.go
File metadata and controls
105 lines (99 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"net/textproto"
"testing"
"github.com/phires/go-guerrilla/mail"
"github.com/stretchr/testify/assert"
)
func TestGetTo(t *testing.T) {
tests := []struct {
name string
envelope *mail.Envelope
expected []string
}{
{
name: "single recipient",
envelope: &mail.Envelope{
RcptTo: []mail.Address{
{User: "user1", Host: "example.com"},
},
},
expected: []string{"[email protected]"},
},
{
name: "multiple recipients",
envelope: &mail.Envelope{
RcptTo: []mail.Address{
{User: "user1", Host: "example.com"},
{User: "user2", Host: "test.com"},
{User: "admin", Host: "company.org"},
},
},
expected: []string{
},
},
{
name: "no recipients",
envelope: &mail.Envelope{RcptTo: []mail.Address{}},
expected: nil,
},
{
name: "nil envelope recipients",
envelope: &mail.Envelope{RcptTo: nil},
expected: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := getTo(tt.envelope)
assert.Equal(t, tt.expected, result)
})
}
}
func TestIsQuitError(t *testing.T) {
tests := []struct {
name string
err error
expected bool
}{
{
name: "nil error",
err: nil,
expected: false,
},
{
name: "SMTP 221 code (acceptable)",
err: &textproto.Error{Code: 221, Msg: "Bye"},
expected: false,
},
{
name: "SMTP 250 code (acceptable)",
err: &textproto.Error{Code: 250, Msg: "OK"},
expected: false,
},
{
name: "SMTP 550 error code",
err: &textproto.Error{Code: 550, Msg: "Mailbox not found"},
expected: true,
},
{
name: "SMTP 421 error code",
err: &textproto.Error{Code: 421, Msg: "Service not available"},
expected: true,
},
{
name: "non-textproto error",
err: assert.AnError,
expected: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := isQuitError(tt.err)
assert.Equal(t, tt.expected, result)
})
}
}