dao_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package monitor
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/job/main/creative/conf"
  8. _ "github.com/go-sql-driver/mysql"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. d *Dao
  13. )
  14. func TestMain(m *testing.M) {
  15. if os.Getenv("DEPLOY_ENV") != "" {
  16. flag.Set("app_id", "main.archive.creative-job")
  17. flag.Set("conf_token", "43943fda0bb311e8865c66d44b23cda7")
  18. flag.Set("tree_id", "16037")
  19. flag.Set("conf_version", "docker-1")
  20. flag.Set("deploy_env", "uat")
  21. flag.Set("conf_host", "config.bilibili.co")
  22. flag.Set("conf_path", "/tmp")
  23. flag.Set("region", "sh")
  24. flag.Set("zone", "sh001")
  25. } else {
  26. flag.Set("conf", "../../cmd/creative-job.toml")
  27. }
  28. flag.Parse()
  29. if err := conf.Init(); err != nil {
  30. panic(err)
  31. }
  32. d = New(conf.Conf)
  33. os.Exit(m.Run())
  34. }
  35. func Test_Monitor(t *testing.T) {
  36. var (
  37. err error
  38. c = context.TODO()
  39. username = "test"
  40. )
  41. convey.Convey("monitor", t, func(ctx convey.C) {
  42. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  43. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  44. err = d.Send(c, username, "creative-job test")
  45. ctx.So(err, convey.ShouldEqual, err)
  46. })
  47. })
  48. })
  49. }