dao_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package blocked
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/admin/main/credit/conf"
  8. _ "go-common/library/database/orm"
  9. _ "github.com/jinzhu/gorm"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var d *Dao
  13. func TestMain(m *testing.M) {
  14. if os.Getenv("DEPLOY_ENV") != "" {
  15. flag.Set("app_id", "main.account-law.credit-admin")
  16. flag.Set("conf_appid", "main.account-law.credit-admin")
  17. flag.Set("conf_token", "eKmbn2M4jvSyyjMEOywLFOQlX5ggRG9x")
  18. flag.Set("tree_id", "5885")
  19. flag.Set("conf_version", "docker-1")
  20. flag.Set("deploy_env", "uat")
  21. flag.Set("conf_env", "10")
  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/convey-test.toml")
  28. }
  29. flag.Parse()
  30. if err := conf.Init(); err != nil {
  31. panic(err)
  32. }
  33. d = New(conf.Conf)
  34. os.Exit(m.Run())
  35. }
  36. func WithDao(f func(d *Dao)) func() {
  37. return func() {
  38. f(d)
  39. }
  40. }
  41. func WithMysql(f func(d *Dao)) func() {
  42. return func() {
  43. f(d)
  44. }
  45. }
  46. func ctx() context.Context {
  47. return context.Background()
  48. }
  49. func Test_initORM(t *testing.T) {
  50. Convey("not need return", t, func() {
  51. d.initORM()
  52. })
  53. }
  54. func Test_Ping(t *testing.T) {
  55. Convey("return someting", t, func() {
  56. err := d.Ping(context.TODO())
  57. So(err, ShouldBeNil)
  58. })
  59. }