dao_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package alarm
  2. import (
  3. "flag"
  4. "os"
  5. "strings"
  6. "testing"
  7. "github.com/smartystreets/goconvey/convey"
  8. "go-common/app/service/main/resource/conf"
  9. "go-common/app/service/main/resource/model"
  10. "gopkg.in/h2non/gock.v1"
  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.app-svr.resource-service")
  18. flag.Set("conf_token", "y79sErNhxggjvULS0O8Czas9PaxHBF5o")
  19. flag.Set("tree_id", "3232")
  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/resource-service-test.toml")
  28. }
  29. flag.Parse()
  30. if err := conf.Init(); err != nil {
  31. panic(err)
  32. }
  33. d = New(conf.Conf)
  34. d.httpClient.SetTransport(gock.DefaultTransport)
  35. m.Run()
  36. os.Exit(0)
  37. }
  38. func httpMock(method, url string) *gock.Request {
  39. r := gock.New(url)
  40. r.Method = strings.ToUpper(method)
  41. return r
  42. }
  43. func TestDaoCheckURL(t *testing.T) {
  44. var (
  45. originURL = "https://www.bilibili.com"
  46. wis = []*model.ResWarnInfo{}
  47. )
  48. convey.Convey("CheckURL", t, func(ctx convey.C) {
  49. httpMock("GET", "http://www.bilibili.com").Reply(200)
  50. d.CheckURL(originURL, wis)
  51. ctx.Convey("no return values", func() {
  52. })
  53. })
  54. }