dao_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "strings"
  7. "testing"
  8. "go-common/app/service/main/coupon/conf"
  9. "github.com/smartystreets/goconvey/convey"
  10. gock "gopkg.in/h2non/gock.v1"
  11. )
  12. var (
  13. d *Dao
  14. )
  15. func TestMain(m *testing.M) {
  16. if os.Getenv("DEPLOY_ENV") != "" {
  17. flag.Set("app_id", "main.account.coupon-service")
  18. flag.Set("conf_token", "6f73e99036aecfafd140c193c036120b")
  19. flag.Set("tree_id", "22595")
  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/coupon-service.toml")
  28. }
  29. flag.Parse()
  30. if err := conf.Init(); err != nil {
  31. panic(err)
  32. }
  33. d = New(conf.Conf)
  34. d.client.SetTransport(gock.DefaultTransport)
  35. os.Exit(m.Run())
  36. }
  37. func httpMock(method, url string) *gock.Request {
  38. r := gock.New(url)
  39. r.Method = strings.ToUpper(method)
  40. return r
  41. }
  42. func TestDaoPing(t *testing.T) {
  43. convey.Convey("TestDaoPing", t, func(convCtx convey.C) {
  44. err := d.Ping(context.Background())
  45. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  46. convCtx.So(err, convey.ShouldBeNil)
  47. })
  48. })
  49. }
  50. func TestDaopingMC(t *testing.T) {
  51. convey.Convey("TestDaopingMC", t, func(convCtx convey.C) {
  52. err := d.pingMC(context.Background())
  53. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  54. convCtx.So(err, convey.ShouldBeNil)
  55. })
  56. })
  57. }