exp_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/member/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. "gopkg.in/h2non/gock.v1"
  8. )
  9. func TestDaoExp(t *testing.T) {
  10. var (
  11. c = context.TODO()
  12. mid = int64(4780461)
  13. )
  14. convey.Convey("Exp", t, func(ctx convey.C) {
  15. exp, err := d.Exp(c, mid)
  16. ctx.Convey("Error should be nil", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. })
  19. ctx.Convey("exp should not be nil", func(ctx convey.C) {
  20. t.Logf("exp:%+v", exp)
  21. ctx.So(exp, convey.ShouldNotBeNil)
  22. })
  23. })
  24. }
  25. func TestDaoExps(t *testing.T) {
  26. var (
  27. c = context.TODO()
  28. mids = []int64{4780461, 2}
  29. )
  30. convey.Convey("Exps", t, func(ctx convey.C) {
  31. exps, err := d.Exps(c, mids)
  32. ctx.Convey("Error should be nil", func(ctx convey.C) {
  33. ctx.So(err, convey.ShouldBeNil)
  34. })
  35. ctx.Convey("exps should not be nil", func(ctx convey.C) {
  36. ctx.So(exps, convey.ShouldNotBeNil)
  37. })
  38. })
  39. }
  40. func TestDaoExpLog(t *testing.T) {
  41. var (
  42. c = context.TODO()
  43. mid = int64(0)
  44. ip = ""
  45. searchLogUrl = "http://uat-bili-search.bilibili.co/x/admin/search/log"
  46. )
  47. convey.Convey("ExpLog", t, func(ctx convey.C) {
  48. d.client.SetTransport(gock.DefaultTransport)
  49. defer gock.OffAll()
  50. httpMock("GET", searchLogUrl).Reply(200).JSON(`{"code":0,"message":"0"}`)
  51. l, err := d.ExpLog(c, mid, ip)
  52. ctx.Convey("Error should be nil", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. })
  55. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  56. ctx.So(l, convey.ShouldNotBeNil)
  57. })
  58. })
  59. }
  60. func TestDaoasExpLog(t *testing.T) {
  61. var (
  62. res = &model.SearchResult{}
  63. )
  64. convey.Convey("asExpLog", t, func(ctx convey.C) {
  65. p1 := asExpLog(res)
  66. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  67. t.Logf("log:%+v", p1)
  68. ctx.So(p1, convey.ShouldNotBeNil)
  69. })
  70. })
  71. }