mail_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package mail
  2. import (
  3. "flag"
  4. "fmt"
  5. "testing"
  6. "go-common/app/tool/saga/conf"
  7. "go-common/app/tool/saga/model"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func init() {
  11. var err error
  12. flag.Set("conf", "../../cmd/saga-test.toml")
  13. if err = conf.Init(); err != nil {
  14. panic(err)
  15. }
  16. }
  17. // go test -test.v -test.run TestMail
  18. func TestMail(t *testing.T) {
  19. Convey("Test mail", t, func() {
  20. m := &model.Mail{
  21. ToAddress: []*model.MailAddress{{Name: "baihai", Address: "changhengyuan@bilibili.com"},
  22. {Name: "muyan", Address: "changhengyuan@bilibili.com"}},
  23. Subject: fmt.Sprintf("【Sage 提醒】%s项目发生Merge Request事件", "test-mail"),
  24. }
  25. mergeOut := " Merge made by the 'recursive' strategy.\n" +
  26. "tools/saga/CHANGELOG.md | 4 ++++\n" +
  27. "business/interface/app-show/service/rank/rank.go | 28 +++++++++++------------\n" +
  28. "business/interface/app-show/service/show/cache.go | 6 ++---\n" +
  29. "3 files changed, 21 insertions(+), 17 deletions(-)"
  30. err := SendMail(m, &model.MailData{
  31. UserName: "baihai",
  32. SourceBranch: "featre_answer",
  33. TargetBranch: "master",
  34. Title: "修改变量A",
  35. Description: "内容就是",
  36. URL: "http://www.baidu.com",
  37. Info: mergeOut,
  38. })
  39. So(err, ShouldBeNil)
  40. })
  41. }