dao_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "strings"
  7. "testing"
  8. "go-common/app/job/main/spy/conf"
  9. . "github.com/smartystreets/goconvey/convey"
  10. gock "gopkg.in/h2non/gock.v1"
  11. )
  12. var (
  13. d *Dao
  14. c = context.Background()
  15. )
  16. func TestMain(m *testing.M) {
  17. if os.Getenv("DEPLOY_ENV") != "" {
  18. flag.Set("app_id", "main.account-law.spy-job")
  19. flag.Set("conf_appid", "main.account-law.spy-job")
  20. flag.Set("conf_token", "1404609bda3db4cd20ad9823bfd20a83")
  21. flag.Set("tree_id", "2856")
  22. flag.Set("conf_version", "docker-1")
  23. flag.Set("deploy_env", "uat")
  24. flag.Set("conf_env", "10")
  25. flag.Set("conf_host", "config.bilibili.co")
  26. flag.Set("conf_path", "/tmp")
  27. flag.Set("region", "sh")
  28. flag.Set("zone", "sh001")
  29. } else {
  30. flag.Set("conf", "../cmd/spy-job-test.toml")
  31. }
  32. flag.Parse()
  33. if err := conf.Init(); err != nil {
  34. panic(err)
  35. }
  36. d = New(conf.Conf)
  37. d.httpClient.SetTransport(gock.DefaultTransport)
  38. os.Exit(m.Run())
  39. }
  40. func httpMock(method, url string) *gock.Request {
  41. r := gock.New(url)
  42. r.Method = strings.ToUpper(method)
  43. return r
  44. }
  45. func TestPing(t *testing.T) {
  46. Convey("TestPing", t, func() {
  47. err := d.Ping(c)
  48. So(err, ShouldBeNil)
  49. })
  50. }