OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package mail |
| 6 |
| 7 import ( |
| 8 net_mail "net/mail" |
| 9 "testing" |
| 10 |
| 11 . "github.com/luci/luci-go/common/testing/assertions" |
| 12 . "github.com/smartystreets/goconvey/convey" |
| 13 ) |
| 14 |
| 15 func TestDataTypes(t *testing.T) { |
| 16 t.Parallel() |
| 17 |
| 18 Convey("data types", t, func() { |
| 19 m := &Message{ |
| 20 "from@example.com", |
| 21 "reply_to@example.com", |
| 22 []string{"to1@example.com", "to2@example.com"}, |
| 23 []string{"cc1@example.com", "cc2@example.com"}, |
| 24 []string{"bcc1@example.com", "bcc2@example.com"}, |
| 25 "subject", |
| 26 "body", |
| 27 "<html><body>body</body></html>", |
| 28 []Attachment{{"name.doc", []byte("data"), "https://conte
nt_id"}}, |
| 29 net_mail.Header{ |
| 30 "In-Reply-To": []string{"cats"}, |
| 31 }, |
| 32 } |
| 33 |
| 34 Convey("empty copy doesn't do extra allocations", func() { |
| 35 m := (&Message{}).Copy() |
| 36 So(m.To, ShouldBeNil) |
| 37 So(m.Cc, ShouldBeNil) |
| 38 So(m.Bcc, ShouldBeNil) |
| 39 So(m.Attachments, ShouldBeNil) |
| 40 So(m.Headers, ShouldBeNil) |
| 41 |
| 42 tm := (&TestMessage{}).Copy() |
| 43 So(tm.MIMETypes, ShouldBeNil) |
| 44 }) |
| 45 |
| 46 Convey("can copy nil", func() { |
| 47 So((*Message)(nil).Copy(), ShouldBeNil) |
| 48 So((*Message)(nil).ToSDKMessage(), ShouldBeNil) |
| 49 So((*TestMessage)(nil).Copy(), ShouldBeNil) |
| 50 }) |
| 51 |
| 52 Convey("Message is copyable", func() { |
| 53 m2 := m.Copy() |
| 54 So(m2, ShouldResembleV, m) |
| 55 |
| 56 // make sure it's really a copy |
| 57 m2.To[0] = "fake@faker.example.com" |
| 58 So(m2.To, ShouldNotResembleV, m.To) |
| 59 |
| 60 m2.Headers["SomethingElse"] = []string{"noooo"} |
| 61 So(m2.Headers, ShouldNotResembleV, m.Headers) |
| 62 }) |
| 63 |
| 64 Convey("TestMessage is copyable", func() { |
| 65 tm := &TestMessage{*m, []string{"application/msword"}} |
| 66 tm2 := tm.Copy() |
| 67 So(tm, ShouldResembleV, tm2) |
| 68 |
| 69 tm2.MIMETypes[0] = "spam" |
| 70 So(tm, ShouldNotResembleV, tm2) |
| 71 }) |
| 72 |
| 73 Convey("Message can be cast to an SDK Message", func() { |
| 74 m2 := m.ToSDKMessage() |
| 75 So(m2.Sender, ShouldResembleV, m.Sender) |
| 76 So(m2.ReplyTo, ShouldResembleV, m.ReplyTo) |
| 77 So(m2.To, ShouldResembleV, m.To) |
| 78 So(m2.Cc, ShouldResembleV, m.Cc) |
| 79 So(m2.Bcc, ShouldResembleV, m.Bcc) |
| 80 So(m2.Subject, ShouldResembleV, m.Subject) |
| 81 So(m2.Body, ShouldResembleV, m.Body) |
| 82 So(m2.HTMLBody, ShouldResembleV, m.HTMLBody) |
| 83 So(m2.Headers, ShouldResembleV, m.Headers) |
| 84 |
| 85 So((Attachment)(m2.Attachments[0]), ShouldResembleV, m.A
ttachments[0]) |
| 86 }) |
| 87 }) |
| 88 } |
OLD | NEW |