Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: service/mail/message_test.go

Issue 1525923002: Implement Mail service. (Closed) Base URL: https://github.com/luci/gae.git@filter_user
Patch Set: tests and words Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « service/mail/message.go ('k') | service/mail/testable.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « service/mail/message.go ('k') | service/mail/testable.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698