dao_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package http
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "strings"
  7. "testing"
  8. "go-common/app/admin/main/aegis/conf"
  9. "github.com/smartystreets/goconvey/convey"
  10. "gopkg.in/h2non/gock.v1"
  11. )
  12. var (
  13. d *Dao
  14. cntx context.Context
  15. )
  16. func TestMain(m *testing.M) {
  17. if os.Getenv("DEPLOY_ENV") != "" {
  18. flag.Set("app_id", "main.archive.aegis-admin")
  19. flag.Set("conf_token", "cad913269be022e1eb8c45a8d5408d78")
  20. flag.Set("tree_id", "60977")
  21. flag.Set("conf_version", "1")
  22. flag.Set("deploy_env", "uat")
  23. flag.Set("conf_host", "config.bilibili.co")
  24. flag.Set("conf_path", "/tmp")
  25. flag.Set("region", "sh")
  26. flag.Set("zone", "sh001")
  27. } else {
  28. flag.Set("conf", "../../cmd/aegis-admin.toml")
  29. }
  30. flag.Parse()
  31. if err := conf.Init(); err != nil {
  32. panic(err)
  33. }
  34. d = New(conf.Conf)
  35. cntx = context.Background()
  36. os.Exit(m.Run())
  37. }
  38. func httpMock(method, url string) *gock.Request {
  39. r := gock.New(url)
  40. d.clientR.SetTransport(gock.DefaultTransport)
  41. d.clientW.SetTransport(gock.DefaultTransport)
  42. r.Method = strings.ToUpper(method)
  43. return r
  44. }
  45. func TestHttpPing(t *testing.T) {
  46. convey.Convey("Ping", t, func(ctx convey.C) {
  47. ctx.Convey("Ping", func(ctx convey.C) {
  48. err := d.Ping(cntx)
  49. ctx.Convey("Then err should not be nil", func(ctx convey.C) {
  50. ctx.So(err, convey.ShouldBeNil)
  51. })
  52. })
  53. })
  54. }