dao_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package dao
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "os"
  7. "strings"
  8. "testing"
  9. "go-common/app/admin/main/tv/conf"
  10. "flag"
  11. . "github.com/smartystreets/goconvey/convey"
  12. "gopkg.in/h2non/gock.v1"
  13. )
  14. var d *Dao
  15. func init() {
  16. // dir, _ := filepath.Abs("../cmd/tv-admin-test.toml")
  17. // flag.Set("conf", dir)
  18. if os.Getenv("DEPLOY_ENV") != "" {
  19. flag.Set("app_id", "main.web-svr.tv-admin")
  20. flag.Set("conf_token", "3d446a004187a6572d656bab1dbff1b0")
  21. flag.Set("tree_id", "15310")
  22. flag.Set("conf_version", "docker-1")
  23. flag.Set("deploy_env", "uat")
  24. flag.Set("conf_host", "config.bilibili.co")
  25. flag.Set("conf_path", "/tmp")
  26. flag.Set("region", "sh")
  27. flag.Set("zone", "sh001")
  28. }
  29. flag.Parse()
  30. if err := conf.Init(); err != nil {
  31. panic(err)
  32. }
  33. d = New(conf.Conf)
  34. }
  35. func WithDao(f func(d *Dao)) func() {
  36. return func() {
  37. Reset(func() {})
  38. f(d)
  39. }
  40. }
  41. func httpMock(method, url string) *gock.Request {
  42. r := gock.New(url)
  43. r.Method = strings.ToUpper(method)
  44. d.client.SetTransport(gock.DefaultTransport)
  45. d.httpSearch.SetTransport(gock.DefaultTransport)
  46. d.bfsClient.Transport = gock.DefaultTransport
  47. return r
  48. }
  49. func TestDao_MaxOrder(t *testing.T) {
  50. Convey("TestDao_MaxOrder", t, WithDao(func(d *Dao) {
  51. order := d.MaxOrder(context.Background())
  52. So(order, ShouldBeGreaterThan, 0)
  53. fmt.Println(order)
  54. }))
  55. }
  56. func TestDao_MangoRecom(t *testing.T) {
  57. Convey("TestDao_MangoRecom", t, WithDao(func(d *Dao) {
  58. err := d.MangoRecom(context.Background(), []int64{3, 4, 5})
  59. So(err, ShouldBeNil)
  60. res, err2 := d.GetMRecom(context.Background())
  61. So(err2, ShouldBeNil)
  62. data, _ := json.Marshal(res)
  63. fmt.Println(string(data))
  64. }))
  65. }