dao_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package email
  2. import (
  3. "context"
  4. "flag"
  5. "github.com/smartystreets/goconvey/convey"
  6. "go-common/app/job/main/aegis/conf"
  7. "os"
  8. "testing"
  9. )
  10. var (
  11. d *Dao
  12. )
  13. func TestMain(m *testing.M) {
  14. if os.Getenv("DEPLOY_ENV") != "" {
  15. flag.Set("app_id", "main.archive.aegis-job")
  16. flag.Set("conf_token", "aed3cc21ca345ffc284c6036da32352b")
  17. flag.Set("tree_id", "61819")
  18. flag.Set("conf_version", "1")
  19. flag.Set("deploy_env", "uat")
  20. flag.Set("conf_host", "config.bilibili.co")
  21. flag.Set("conf_path", "/tmp")
  22. flag.Set("region", "sh")
  23. flag.Set("zone", "sh001")
  24. } else {
  25. flag.Set("conf", "../../cmd/aegis-job.toml")
  26. }
  27. flag.Parse()
  28. if err := conf.Init(); err != nil {
  29. panic(err)
  30. }
  31. d = New(conf.Conf)
  32. os.Exit(m.Run())
  33. }
  34. func TestDao_MonitorEmailAsync(t *testing.T) {
  35. convey.Convey("MonitorEmailAsync", t, func(ctx convey.C) {
  36. var (
  37. c = context.Background()
  38. )
  39. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  40. err := d.MonitorEmailAsync(c, []string{"abc@bilibili.com"}, "测试标题", "测试内容<a href=\"https://www.bilibili.com\">link</a>")
  41. ctx.Convey("Then err should be nil.tasks,lastid should not be nil.", func(ctx convey.C) {
  42. ctx.So(err, convey.ShouldBeNil)
  43. })
  44. })
  45. })
  46. }
  47. func TestDao_MonitorEmailProc(t *testing.T) {
  48. convey.Convey("MonitorEmailProc", t, func(ctx convey.C) {
  49. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  50. err := d.MonitorEmailProc()
  51. ctx.Convey("Then err should be nil.tasks,lastid should not be nil.", func(ctx convey.C) {
  52. ctx.So(err, convey.ShouldNotBeNil)
  53. })
  54. })
  55. })
  56. }