mail_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2011 Google Inc. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package mail
  5. import (
  6. "testing"
  7. "github.com/golang/protobuf/proto"
  8. "google.golang.org/appengine/internal/aetesting"
  9. basepb "google.golang.org/appengine/internal/base"
  10. pb "google.golang.org/appengine/internal/mail"
  11. )
  12. func TestMessageConstruction(t *testing.T) {
  13. var got *pb.MailMessage
  14. c := aetesting.FakeSingleContext(t, "mail", "Send", func(in *pb.MailMessage, out *basepb.VoidProto) error {
  15. got = in
  16. return nil
  17. })
  18. msg := &Message{
  19. Sender: "dsymonds@example.com",
  20. To: []string{"nigeltao@example.com"},
  21. Body: "Hey, lunch time?",
  22. Attachments: []Attachment{
  23. // Regression test for a prod bug. The address of a range variable was used when
  24. // constructing the outgoing proto, so multiple attachments used the same name.
  25. {
  26. Name: "att1.txt",
  27. Data: []byte("data1"),
  28. ContentID: "<att1>",
  29. },
  30. {
  31. Name: "att2.txt",
  32. Data: []byte("data2"),
  33. },
  34. },
  35. }
  36. if err := Send(c, msg); err != nil {
  37. t.Fatalf("Send: %v", err)
  38. }
  39. want := &pb.MailMessage{
  40. Sender: proto.String("dsymonds@example.com"),
  41. To: []string{"nigeltao@example.com"},
  42. Subject: proto.String(""),
  43. TextBody: proto.String("Hey, lunch time?"),
  44. Attachment: []*pb.MailAttachment{
  45. {
  46. FileName: proto.String("att1.txt"),
  47. Data: []byte("data1"),
  48. ContentID: proto.String("<att1>"),
  49. },
  50. {
  51. FileName: proto.String("att2.txt"),
  52. Data: []byte("data2"),
  53. },
  54. },
  55. }
  56. if !proto.Equal(got, want) {
  57. t.Errorf("Bad proto for %+v\n got %v\nwant %v", msg, got, want)
  58. }
  59. }