Debian Codegraph @

mailyak_test.go

raw symbols SCIP
1 package mailyakscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.12 fmt/"
5 "net/smtpscip-go gomod github.com/golang/go/src go1.12 `net/smtp`/"
6 "stringsscip-go gomod github.com/golang/go/src go1.12 strings/"
7 "testingscip-go gomod github.com/golang/go/src go1.12 testing/"
8 "timescip-go gomod github.com/golang/go/src go1.12 time/"
9 )
10
11 // TestMailYakStringer ensures MailYak struct conforms to the Stringer interface.
12 func TestMailYakStringerscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/TestMailYakStringer().(t *testingscip-go gomod github.com/golang/go/src go1.12 testing/.Tscip-go gomod github.com/golang/go/src go1.12 testing/T#) {
13 t.Parallelscip-go gomod github.com/golang/go/src go1.12 testing/T#Parallel().()
14
15 mail := Newscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/New().("mail.host.com:25", smtpscip-go gomod github.com/golang/go/src go1.12 `net/smtp`/.PlainAuthscip-go gomod github.com/golang/go/src go1.12 `net/smtp`/PlainAuth().("", "user", "pass", "mail.host.com"))
16 mail.Fromscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#From().("[email protected]")
17 mail.FromNamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#FromName().("From Example")
18 mail.Toscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#To().("[email protected]")
19 mail.Bccscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#Bcc().("[email protected]", "[email protected]")
20 mail.Subjectscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#Subject().("Test subject")
21 mail.ReplyToscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#ReplyTo().("[email protected]")
22 mail.HTMLscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#HTML().().Setscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/BodyPart#Set().("HTML part: this is just a test.")
23 mail.Plainscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#Plain().().Setscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/BodyPart#Set().("Plain text part: this is also just a test.")
24 mail.Attachscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#Attach().("test.html", stringsscip-go gomod github.com/golang/go/src go1.12 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.12 strings/NewReader().("<html><head></head></html>"))
25 mail.Attachscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#Attach().("test2.html", stringsscip-go gomod github.com/golang/go/src go1.12 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.12 strings/NewReader().("<html><head></head></html>"))
26
27 mail.AddHeaderscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#AddHeader().("Precedence", "bulk")
28
29 mail.datescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#date. = "a date"
30
31 want := "&MailYak{date: \"a date\", from: \"[email protected]\", fromName: \"From Example\", html: 31 bytes, plain: 42 bytes, toAddrs: [[email protected]], bccAddrs: [[email protected] [email protected]], subject: \"Test subject\", Precedence: [\"bulk\"], host: \"mail.host.com:25\", attachments (2): [{filename: test.html} {filename: test2.html}], auth set: true, explicit tls: false}"
32 got := fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.12 fmt/Sprintf().("%+v", mail)
33 if got != want {
34 t.Errorfscip-go gomod github.com/golang/go/src go1.12 testing/common#Errorf().("MailYak.String() = %v, want %v", got, want)
35 }
36 }
37
38 // TestMailYakDate ensures two emails sent with the same MailYak instance use
39 // different (updated) date timestamps.
40 func TestMailYakDatescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/TestMailYakDate().(t *testingscip-go gomod github.com/golang/go/src go1.12 testing/.Tscip-go gomod github.com/golang/go/src go1.12 testing/T#) {
41 t.Parallelscip-go gomod github.com/golang/go/src go1.12 testing/T#Parallel().()
42
43 mail := Newscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/New().("mail.host.com:25", smtpscip-go gomod github.com/golang/go/src go1.12 `net/smtp`/.PlainAuthscip-go gomod github.com/golang/go/src go1.12 `net/smtp`/PlainAuth().("", "user", "pass", "mail.host.com"))
44 mail.Fromscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#From().("[email protected]")
45 mail.Toscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#To().("[email protected]")
46 mail.Subjectscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#Subject().("Test subject")
47
48 // send two emails at different times (discarding any errors)
49 _, _ = mail.MimeBufscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#MimeBuf().()
50 dateOne := mail.datescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#date.
51
52 timescip-go gomod github.com/golang/go/src go1.12 time/.Sleepscip-go gomod github.com/golang/go/src go1.12 time/Sleep().(1 * timescip-go gomod github.com/golang/go/src go1.12 time/.Secondscip-go gomod github.com/golang/go/src go1.12 time/Second.)
53
54 _, _ = mail.MimeBufscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#MimeBuf().()
55 dateTwo := mail.datescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#date.
56
57 if dateOne == dateTwo {
58 t.Errorfscip-go gomod github.com/golang/go/src go1.12 testing/common#Errorf().("MailYak.Send(): timestamp not updated: %v", dateOne)
59 }
60 }
61
62 // TestStripNames ensures that the stripNames() method correctly
63 // remove the name part of a list of RFC 5322 addresses.
64 func TestStripNamesscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/TestStripNames().(t *testingscip-go gomod github.com/golang/go/src go1.12 testing/.Tscip-go gomod github.com/golang/go/src go1.12 testing/T#) {
65 addresses := []string{
66 "[email protected]",
67 "[email protected]",
68 "invalid1",
69 "John Doe <[email protected]>",
70 "<[email protected]>",
71 "invalid2",
72 }
73
74 expected := map[string]struct{}{
75 "[email protected]": {},
76 "[email protected]": {},
77 "invalid1": {},
78 "[email protected]": {},
79 "[email protected]": {},
80 "invalid2": {},
81 }
82
83 result := stripNamesscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/stripNames().(addresses)
84
85 if len(result) != len(expected) {
86 t.Fatalfscip-go gomod github.com/golang/go/src go1.12 testing/common#Fatalf().("stripNames: Expected %d addresses, got %d: \n%v", len(expected), len(result), result)
87 }
88
89 for _, addr := range result {
90 if _, ok := expected[addr]; !ok {
91 t.Errorfscip-go gomod github.com/golang/go/src go1.12 testing/common#Errorf().("stripNames: Address %q was not expected", addr)
92 }
93 }
94 }