pgc_batch_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package cms
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/interface/main/tv/model"
  6. "testing"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestCmssnCMSCacheKey(t *testing.T) {
  10. var (
  11. sid = int64(0)
  12. )
  13. convey.Convey("snCMSCacheKey", t, func(c convey.C) {
  14. p1 := snCMSCacheKey(sid)
  15. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  16. c.So(p1, convey.ShouldNotBeNil)
  17. })
  18. })
  19. }
  20. func TestCmsepCMSCacheKey(t *testing.T) {
  21. var (
  22. epid = int64(0)
  23. )
  24. convey.Convey("epCMSCacheKey", t, func(c convey.C) {
  25. p1 := epCMSCacheKey(epid)
  26. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  27. c.So(p1, convey.ShouldNotBeNil)
  28. })
  29. })
  30. }
  31. func TestCmskeysTreat(t *testing.T) {
  32. var (
  33. ids = []int64{1, 2, 3}
  34. keyFunc = snCMSCacheKey
  35. )
  36. convey.Convey("keysTreat", t, func(c convey.C) {
  37. idmap, allKeys := keysTreat(ids, keyFunc)
  38. c.Convey("Then idmap,allKeys should not be nil.", func(c convey.C) {
  39. c.So(allKeys, convey.ShouldNotBeNil)
  40. c.So(idmap, convey.ShouldNotBeNil)
  41. })
  42. })
  43. }
  44. func TestCmsmissedTreat(t *testing.T) {
  45. var (
  46. idmap map[string]int64
  47. lenCached = int(0)
  48. )
  49. convey.Convey("missedTreat", t, func(c convey.C) {
  50. missed := missedTreat(idmap, lenCached)
  51. c.Convey("Then missed should not be nil.", func(c convey.C) {
  52. c.So(missed, convey.ShouldNotBeNil)
  53. })
  54. })
  55. }
  56. func TestCmsEpMetaCache(t *testing.T) {
  57. var (
  58. ctx = context.Background()
  59. )
  60. convey.Convey("EpMetaCache", t, func(c convey.C) {
  61. c.Convey("Empty Input", func(c convey.C) {
  62. cached, missed, err := d.EpMetaCache(ctx, []int64{})
  63. c.So(err, convey.ShouldBeNil)
  64. c.So(len(missed), convey.ShouldBeZeroValue)
  65. c.So(len(cached), convey.ShouldBeZeroValue)
  66. })
  67. c.Convey("Normal Situation", func(c convey.C) {
  68. epids, err := pickIDs(d.db, _pickEpids)
  69. if err != nil || len(epids) == 0 {
  70. fmt.Println("empty epids")
  71. return
  72. }
  73. cached, missed, err := d.EpMetaCache(ctx, epids)
  74. c.So(err, convey.ShouldBeNil)
  75. c.So(len(missed)+len(cached), convey.ShouldNotEqual, 0)
  76. })
  77. })
  78. }
  79. func TestCmsAddSeasonMetaCache(t *testing.T) {
  80. var (
  81. ctx = context.Background()
  82. vs = &model.SeasonCMS{}
  83. )
  84. convey.Convey("AddSeasonMetaCache", t, func(c convey.C) {
  85. err := d.AddSeasonMetaCache(ctx, vs)
  86. c.Convey("Then err should be nil.", func(c convey.C) {
  87. c.So(err, convey.ShouldBeNil)
  88. })
  89. })
  90. }
  91. func TestCmsAddEpMetaCache(t *testing.T) {
  92. var (
  93. ctx = context.Background()
  94. vs = &model.EpCMS{}
  95. )
  96. convey.Convey("AddEpMetaCache", t, func(c convey.C) {
  97. err := d.AddEpMetaCache(ctx, vs)
  98. c.Convey("Then err should be nil.", func(c convey.C) {
  99. c.So(err, convey.ShouldBeNil)
  100. })
  101. })
  102. }