memcache_test.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package archive
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "go-common/app/interface/main/tv/model/view"
  7. arcwar "go-common/app/service/main/archive/api"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestArchivekeyRl(t *testing.T) {
  11. var (
  12. aid = int64(123)
  13. )
  14. convey.Convey("keyRl", t, func(ctx convey.C) {
  15. p1 := keyRl(aid)
  16. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  17. ctx.So(p1, convey.ShouldNotBeNil)
  18. })
  19. })
  20. }
  21. func TestArchivekeyView(t *testing.T) {
  22. var (
  23. aid = int64(123)
  24. )
  25. convey.Convey("keyView", t, func(ctx convey.C) {
  26. p1 := keyView(aid)
  27. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  28. ctx.So(p1, convey.ShouldNotBeNil)
  29. })
  30. })
  31. }
  32. func TestArchivekeyArc(t *testing.T) {
  33. var (
  34. aid = int64(123)
  35. )
  36. convey.Convey("keyArc", t, func(ctx convey.C) {
  37. p1 := keyArc(aid)
  38. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  39. ctx.So(p1, convey.ShouldNotBeNil)
  40. })
  41. })
  42. }
  43. func TestArchiveAddArcCache(t *testing.T) {
  44. var (
  45. aid = int64(123)
  46. arc = &arcwar.Arc{
  47. Aid: aid,
  48. }
  49. )
  50. convey.Convey("AddArcCache", t, func(ctx convey.C) {
  51. d.AddArcCache(aid, arc)
  52. ctx.Convey("No return values", func(ctx convey.C) {
  53. })
  54. })
  55. }
  56. func TestArchiveAddRelatesCache(t *testing.T) {
  57. var (
  58. aid = int64(123)
  59. rls = []*view.Relate{
  60. {
  61. Aid: aid,
  62. },
  63. }
  64. )
  65. convey.Convey("AddRelatesCache", t, func(ctx convey.C) {
  66. d.AddRelatesCache(aid, rls)
  67. d.addRelatesCache(context.TODO(), aid, rls)
  68. ctx.Convey("No return values", func(ctx convey.C) {
  69. })
  70. })
  71. }
  72. func TestArchiveAddViewCache(t *testing.T) {
  73. convey.Convey("AddViewCache", t, func(c convey.C) {
  74. aid, errGet := getPassAid(d.db)
  75. if errGet != nil {
  76. fmt.Println(errGet)
  77. return
  78. }
  79. vp, err := d.view3(context.Background(), aid)
  80. fmt.Println(vp, " ", aid)
  81. convey.So(err, convey.ShouldBeNil)
  82. convey.So(vp, convey.ShouldNotBeNil)
  83. d.AddViewCache(aid, vp)
  84. c.Convey("No return values", func(ctx convey.C) {
  85. })
  86. })
  87. }
  88. func TestArchiveaddViewCache(t *testing.T) {
  89. var (
  90. c = context.Background()
  91. aid = int64(123)
  92. vp = &arcwar.ViewReply{}
  93. )
  94. convey.Convey("addViewCache", t, func(ctx convey.C) {
  95. err := d.addViewCache(c, aid, vp)
  96. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  97. ctx.So(err, convey.ShouldBeNil)
  98. })
  99. })
  100. }
  101. func TestArchiveRelatesCache(t *testing.T) {
  102. var (
  103. c = context.Background()
  104. aid = int64(123)
  105. )
  106. convey.Convey("RelatesCache", t, func(ctx convey.C) {
  107. rls, err := d.RelatesCache(c, aid)
  108. ctx.Convey("Then err should be nil.rls should not be nil.", func(ctx convey.C) {
  109. fmt.Println(rls)
  110. ctx.So(err, convey.ShouldBeNil)
  111. ctx.So(rls, convey.ShouldNotBeNil)
  112. })
  113. })
  114. }
  115. func TestArchiveaddRelatesCache(t *testing.T) {
  116. var (
  117. c = context.Background()
  118. aid = int64(123)
  119. rls = []*view.Relate{
  120. {Aid: aid},
  121. }
  122. )
  123. convey.Convey("addRelatesCache", t, func(ctx convey.C) {
  124. err := d.addRelatesCache(c, aid, rls)
  125. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  126. ctx.So(err, convey.ShouldBeNil)
  127. })
  128. })
  129. }
  130. func TestArchiveaddArcCache(t *testing.T) {
  131. var (
  132. c = context.Background()
  133. aid = int64(123)
  134. cached = &arcwar.Arc{Aid: 123}
  135. )
  136. convey.Convey("addArcCache", t, func(ctx convey.C) {
  137. err := d.addArcCache(c, aid, cached)
  138. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  139. ctx.So(err, convey.ShouldBeNil)
  140. })
  141. })
  142. }
  143. func TestArchivearcsCache(t *testing.T) {
  144. var (
  145. c = context.Background()
  146. aids = []int64{123}
  147. )
  148. convey.Convey("arcsCache", t, func(ctx convey.C) {
  149. cached, missed, err := d.arcsCache(c, aids)
  150. ctx.Convey("Then err should be nil.cached,missed should not be nil.", func(ctx convey.C) {
  151. ctx.So(err, convey.ShouldBeNil)
  152. ctx.So(len(missed)+len(cached), convey.ShouldEqual, len(aids))
  153. fmt.Println(cached)
  154. fmt.Println(missed)
  155. })
  156. })
  157. }