dao_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package search
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/admin/main/videoup/conf"
  6. "testing"
  7. . "github.com/smartystreets/goconvey/convey"
  8. "gopkg.in/h2non/gock.v1"
  9. "os"
  10. "strings"
  11. )
  12. func WithDao(f func(d *Dao)) func() {
  13. return func() {
  14. Reset(func() {})
  15. f(d)
  16. }
  17. }
  18. func httpMock(method, url string) *gock.Request {
  19. r := gock.New(url)
  20. r.Method = strings.ToUpper(method)
  21. d.httpClient.SetTransport(gock.DefaultTransport)
  22. return r
  23. }
  24. func TestOutTime(t *testing.T) {
  25. Convey("OutTime", t, WithDao(func(d *Dao) {
  26. httpMock("GET", d.URI).Reply(200).JSON(`{"code":0,"message":"0","ttl":1,"data":{"order":"ctime","sort":"desc","result":[],"debug":"","page":{"num":1,"size":10,"total":37}}}`)
  27. _, err := d.OutTime(context.TODO(), []int64{481, 6, 75, 248, 74, 246})
  28. So(err, ShouldBeNil)
  29. }))
  30. }
  31. func TestInQuitList(t *testing.T) {
  32. Convey("InQuitList", t, WithDao(func(d *Dao) {
  33. httpMock("GET", d.URI).Reply(200).JSON(`{"code":0,"message":"0","ttl":1,"data":{"order":"ctime","sort":"desc","result":[{"uid":0,"action":"0"}],"debug":"","page":{"num":1,"size":10,"total":37}}}`)
  34. _, err := d.InQuitList(context.TODO(), []int64{481}, "bt", "et")
  35. So(err, ShouldBeNil)
  36. }))
  37. }
  38. func TestMain(m *testing.M) {
  39. if os.Getenv("DEPLOY_ENV") != "" {
  40. flag.Set("app_id", "main.archive.videoup-admin")
  41. flag.Set("conf_token", "gRSfeavV7kJdY9875Gf29pbd2wrdKZ1a")
  42. flag.Set("tree_id", "2307")
  43. flag.Set("conf_version", "docker-1")
  44. flag.Set("deploy_env", "uat")
  45. flag.Set("conf_host", "config.bilibili.co")
  46. flag.Set("conf_path", "/tmp")
  47. flag.Set("region", "sh")
  48. flag.Set("zone", "sh001")
  49. } else {
  50. flag.Set("conf", "../../cmd/videoup-admin.toml")
  51. }
  52. flag.Parse()
  53. if err := conf.Init(); err != nil {
  54. panic(err)
  55. }
  56. d = New(conf.Conf)
  57. os.Exit(m.Run())
  58. }