cursor_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package history
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "testing"
  6. "time"
  7. hmdl "go-common/app/interface/main/history/model"
  8. "go-common/app/interface/main/tv/model/history"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. testMid = int64(320773689)
  13. testAid = int64(10110670)
  14. testHisMC = &history.HisMC{
  15. MID: testMid,
  16. Res: []*history.HisRes{
  17. {
  18. Mid: testMid,
  19. Oid: testAid,
  20. },
  21. },
  22. LastViewAt: time.Now().Unix(),
  23. }
  24. )
  25. func TestDao_Cursor(t *testing.T) {
  26. convey.Convey("TestDao_Cursor", t, WithDao(func(d *Dao) {
  27. var (
  28. mcDataHis = &hmdl.ArgHistory{
  29. Mid: testMid,
  30. Realtime: time.Now().Unix(),
  31. History: &hmdl.History{
  32. Mid: testMid,
  33. Aid: testAid,
  34. Business: "archive",
  35. },
  36. }
  37. )
  38. res, err := d.Cursor(ctx, testMid, 0, 100, 0, []string{"pgc", "archive"})
  39. if len(res) == 0 {
  40. if errAdd := d.hisRPC.Add(ctx, mcDataHis); errAdd != nil {
  41. fmt.Println(errAdd)
  42. return
  43. }
  44. res, err = d.Cursor(ctx, testMid, 0, 100, 0, []string{"pgc", "archive"})
  45. }
  46. convey.So(err, convey.ShouldBeNil)
  47. convey.So(len(res), convey.ShouldBeGreaterThan, 0)
  48. data, _ := json.Marshal(res)
  49. fmt.Println(string(data))
  50. }))
  51. }
  52. func TestHistorykeyHis(t *testing.T) {
  53. var (
  54. mid = int64(320773689)
  55. )
  56. convey.Convey("keyHis", t, func(c convey.C) {
  57. p1 := keyHis(mid)
  58. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  59. c.So(p1, convey.ShouldNotBeNil)
  60. })
  61. })
  62. }
  63. func TestHistorySaveHisCache(t *testing.T) {
  64. var (
  65. filtered = []*history.HisRes{
  66. {
  67. Mid: testMid,
  68. Oid: testAid,
  69. },
  70. }
  71. )
  72. convey.Convey("SaveHisCache", t, func(c convey.C) {
  73. d.SaveHisCache(ctx, filtered)
  74. c.Convey("No return values", func(c convey.C) {
  75. })
  76. })
  77. }
  78. func TestHistoryaddHisCache(t *testing.T) {
  79. convey.Convey("addHisCache", t, func(c convey.C) {
  80. d.addHisCache(ctx, testHisMC)
  81. c.Convey("No return values", func(c convey.C) {
  82. })
  83. })
  84. }
  85. func TestHistorysetHisCache(t *testing.T) {
  86. convey.Convey("setHisCache", t, func(c convey.C) {
  87. err := d.setHisCache(ctx, testHisMC)
  88. c.Convey("Then err should be nil.", func(c convey.C) {
  89. c.So(err, convey.ShouldBeNil)
  90. })
  91. })
  92. }
  93. func TestHistoryHisCache(t *testing.T) {
  94. convey.Convey("HisCache", t, func(c convey.C) {
  95. s, err := d.HisCache(ctx, testMid)
  96. c.Convey("Then err should be nil.s should not be nil.", func(c convey.C) {
  97. c.So(err, convey.ShouldBeNil)
  98. c.So(s, convey.ShouldNotBeNil)
  99. })
  100. })
  101. }