dao_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/service/main/sms/conf"
  8. "go-common/app/service/main/sms/model"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. var d *Dao
  12. func TestMain(m *testing.M) {
  13. if os.Getenv("DEPLOY_ENV") == "uat" {
  14. flag.Set("app_id", "main.account.sms-service")
  15. flag.Set("conf_token", "35805e3d0bd411e889af5a488f30b450")
  16. flag.Set("tree_id", "6325")
  17. flag.Set("conf_version", "docker-1")
  18. flag.Set("deploy_env", "uat")
  19. flag.Set("conf_host", "config.bilibili.co")
  20. flag.Set("conf_path", "/tmp")
  21. flag.Set("region", "sh")
  22. flag.Set("zone", "sh001")
  23. }
  24. flag.Parse()
  25. if err := conf.Init(); err != nil {
  26. panic(err)
  27. }
  28. d = New(conf.Conf)
  29. m.Run()
  30. os.Exit(0)
  31. }
  32. func TestDaoTemplateByStatus(t *testing.T) {
  33. convey.Convey("TemplateByStatus", t, func(ctx convey.C) {
  34. var status = model.TemplateStatusApprovel
  35. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  36. res, err := d.TemplateByStatus(context.Background(), status)
  37. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  38. ctx.So(err, convey.ShouldBeNil)
  39. ctx.So(res, convey.ShouldNotBeNil)
  40. })
  41. })
  42. })
  43. }
  44. func TestDaoPubSingle(t *testing.T) {
  45. convey.Convey("PubSingle", t, func(ctx convey.C) {
  46. err := d.PubSingle(context.Background(), &model.ModelSend{})
  47. ctx.Convey("Then err should be nil", func(ctx convey.C) {
  48. ctx.So(err, convey.ShouldBeNil)
  49. })
  50. })
  51. }
  52. func TestDao_PubBatch(t *testing.T) {
  53. convey.Convey("PubBatch", t, func(ctx convey.C) {
  54. err := d.PubBatch(context.Background(), &model.ModelSend{})
  55. ctx.Convey("Then err should be nil", func(ctx convey.C) {
  56. ctx.So(err, convey.ShouldBeNil)
  57. })
  58. })
  59. }