-
Notifications
You must be signed in to change notification settings - Fork 38
/
protocol_test.go
83 lines (61 loc) · 1.79 KB
/
protocol_test.go
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
package smtpd
import "testing"
func TestParseLine(t *testing.T) {
cmd := parseLine("HELO hostname")
if cmd.action != "HELO" {
t.Fatalf("unexpected action: %s", cmd.action)
}
if len(cmd.fields) != 2 {
t.Fatalf("unexpected fields length: %d", len(cmd.fields))
}
if len(cmd.params) != 1 {
t.Fatalf("unexpected params length: %d", len(cmd.params))
}
if cmd.params[0] != "hostname" {
t.Fatalf("unexpected value for param 0: %v", cmd.params[0])
}
cmd = parseLine("DATA")
if cmd.action != "DATA" {
t.Fatalf("unexpected action: %s", cmd.action)
}
if len(cmd.fields) != 1 {
t.Fatalf("unexpected fields length: %d", len(cmd.fields))
}
if cmd.params != nil {
t.Fatalf("unexpected params: %v", cmd.params)
}
cmd = parseLine("MAIL FROM:<[email protected]>")
if cmd.action != "MAIL" {
t.Fatalf("unexpected action: %s", cmd.action)
}
if len(cmd.fields) != 2 {
t.Fatalf("unexpected fields length: %d", len(cmd.fields))
}
if len(cmd.params) != 2 {
t.Fatalf("unexpected params length: %d", len(cmd.params))
}
if cmd.params[0] != "FROM" {
t.Fatalf("unexpected value for param 0: %v", cmd.params[0])
}
if cmd.params[1] != "<[email protected]>" {
t.Fatalf("unexpected value for param 1: %v", cmd.params[1])
}
}
func TestParseLineMailformedMAILFROM(t *testing.T) {
cmd := parseLine("MAIL FROM: <[email protected]>")
if cmd.action != "MAIL" {
t.Fatalf("unexpected action: %s", cmd.action)
}
if len(cmd.fields) != 2 {
t.Fatalf("unexpected fields length: %d", len(cmd.fields))
}
if len(cmd.params) != 2 {
t.Fatalf("unexpected params length: %d", len(cmd.params))
}
if cmd.params[0] != "FROM" {
t.Fatalf("unexpected value for param 0: %v", cmd.params[0])
}
if cmd.params[1] != "<[email protected]>" {
t.Fatalf("unexpected value for param 1: %v", cmd.params[1])
}
}