dao_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package dao
  2. import (
  3. "flag"
  4. "os"
  5. "reflect"
  6. "testing"
  7. "go-common/app/job/main/identify/conf"
  8. "go-common/library/database/sql"
  9. "github.com/bouk/monkey"
  10. "github.com/smartystreets/goconvey/convey"
  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.identify-job")
  18. flag.Set("conf_token", "138ecf5e1bc269922614e4b549b261bb")
  19. flag.Set("tree_id", "18436")
  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/identify-job-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 TestDaoClose(t *testing.T) {
  37. convey.Convey("Close", t, func(ctx convey.C) {
  38. monkey.PatchInstanceMethod(reflect.TypeOf(d.authDB), "Close", func(_ *sql.DB) error {
  39. return nil
  40. })
  41. defer monkey.UnpatchAll()
  42. var err error
  43. d.Close()
  44. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  45. ctx.So(err, convey.ShouldBeNil)
  46. })
  47. })
  48. }