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
|
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package mail
import (
"testing"
"github.com/golang/protobuf/proto"
"google.golang.org/appengine/internal/aetesting"
basepb "google.golang.org/appengine/internal/base"
pb "google.golang.org/appengine/internal/mail"
)
func TestMessageConstruction(t *testing.T) {
var got *pb.MailMessage
c := aetesting.FakeSingleContext(t, "mail", "Send", func(in *pb.MailMessage, out *basepb.VoidProto) error {
got = in
return nil
})
msg := &Message{
Sender: "dsymonds@example.com",
To: []string{"nigeltao@example.com"},
Body: "Hey, lunch time?",
Attachments: []Attachment{
// Regression test for a prod bug. The address of a range variable was used when
// constructing the outgoing proto, so multiple attachments used the same name.
{
Name: "att1.txt",
Data: []byte("data1"),
ContentID: "<att1>",
},
{
Name: "att2.txt",
Data: []byte("data2"),
},
},
}
if err := Send(c, msg); err != nil {
t.Fatalf("Send: %v", err)
}
want := &pb.MailMessage{
Sender: proto.String("dsymonds@example.com"),
To: []string{"nigeltao@example.com"},
Subject: proto.String(""),
TextBody: proto.String("Hey, lunch time?"),
Attachment: []*pb.MailAttachment{
{
FileName: proto.String("att1.txt"),
Data: []byte("data1"),
ContentID: proto.String("<att1>"),
},
{
FileName: proto.String("att2.txt"),
Data: []byte("data2"),
},
},
}
if !proto.Equal(got, want) {
t.Errorf("Bad proto for %+v\n got %v\nwant %v", msg, got, want)
}
}
|