dao_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package monitor
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/service/main/up/conf"
  6. "net/url"
  7. "os"
  8. "testing"
  9. "github.com/smartystreets/goconvey/convey"
  10. "go-common/app/service/main/up/dao"
  11. )
  12. var (
  13. d *Dao
  14. )
  15. func TestMain(m *testing.M) {
  16. if os.Getenv("DEPLOY_ENV") != "" {
  17. flag.Set("app_id", dao.AppID)
  18. flag.Set("conf_token", dao.UatToken)
  19. flag.Set("tree_id", dao.TreeID)
  20. flag.Set("conf_version", "docker-1")
  21. flag.Set("deploy_env", "uat")
  22. flag.Set("conf_host", "config.bilibili.co")
  23. flag.Set("conf_path", "/tmp")
  24. flag.Set("region", "sh")
  25. flag.Set("zone", "sh001")
  26. } else {
  27. flag.Set("conf", "../../cmd/up-service.toml")
  28. }
  29. if os.Getenv("UT_LOCAL_TEST") != "" {
  30. flag.Set("conf", "../../cmd/up-service.toml")
  31. }
  32. flag.Parse()
  33. if err := conf.Init(); err != nil {
  34. panic(err)
  35. }
  36. d = New(conf.Conf)
  37. m.Run()
  38. os.Exit(0)
  39. }
  40. func TestMonitorSend(t *testing.T) {
  41. var (
  42. c = context.TODO()
  43. username = ""
  44. msg = ""
  45. )
  46. convey.Convey("Send", t, func(ctx convey.C) {
  47. err := d.Send(c, username, msg)
  48. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  49. ctx.So(err, convey.ShouldBeNil)
  50. })
  51. })
  52. }
  53. func TestMonitorgetSign(t *testing.T) {
  54. var (
  55. params url.Values
  56. )
  57. convey.Convey("getSign", t, func(ctx convey.C) {
  58. sign := d.getSign(params)
  59. ctx.Convey("Then sign should not be nil.", func(ctx convey.C) {
  60. ctx.So(sign, convey.ShouldNotBeNil)
  61. })
  62. })
  63. }