dao_test.go 930 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package upcrmdao
  2. import (
  3. "flag"
  4. "github.com/go-sql-driver/mysql"
  5. "go-common/app/service/main/upcredit/conf"
  6. "os"
  7. "testing"
  8. )
  9. var (
  10. d *Dao
  11. )
  12. func TestMain(m *testing.M) {
  13. if os.Getenv("DEPLOY_ENV") != "" {
  14. flag.Set("app_id", "main.archive.upcredit-service")
  15. flag.Set("conf_token", "e85677843358d6c5dcd7246e6e3fc2de")
  16. flag.Set("tree_id", "33287")
  17. flag.Set("conf_version", "docker-1")
  18. flag.Set("deploy_env", "uat")
  19. flag.Set("conf_host", "config.bilibili.co")
  20. flag.Set("conf_path", "/tmp")
  21. flag.Set("region", "sh")
  22. flag.Set("zone", "sh001")
  23. } else {
  24. flag.Set("conf", "../../cmd/upcredit-service.toml")
  25. }
  26. flag.Parse()
  27. if err := conf.Init(); err != nil {
  28. panic(err)
  29. }
  30. d = New(conf.Conf)
  31. m.Run()
  32. os.Exit(0)
  33. }
  34. func IgnoreErr(err error) error {
  35. if err == nil {
  36. return err
  37. }
  38. var e, _ = err.(*mysql.MySQLError)
  39. if e != nil {
  40. switch e.Number {
  41. case 1062:
  42. return nil
  43. }
  44. }
  45. return err
  46. }