cache_test.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package datadao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDatadaodescHelper(t *testing.T) {
  9. convey.Convey("descHelper", t, func(ctx convey.C) {
  10. var (
  11. d = &CacheBaseLoader{}
  12. )
  13. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  14. key := descHelper(d)
  15. ctx.Convey("Then key should not be nil.", func(ctx convey.C) {
  16. ctx.So(key, convey.ShouldNotBeNil)
  17. })
  18. })
  19. })
  20. }
  21. func TestDatadaonewCacheBaseLoader(t *testing.T) {
  22. convey.Convey("newCacheBaseLoader", t, func(ctx convey.C) {
  23. var (
  24. signID = int64(0)
  25. date = time.Now()
  26. val = interface{}(0)
  27. desc = ""
  28. )
  29. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  30. p1 := newCacheBaseLoader(signID, date, val, desc)
  31. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  32. ctx.So(p1, convey.ShouldNotBeNil)
  33. })
  34. })
  35. })
  36. }
  37. func TestDatadaoKeyCacheBaseLoader(t *testing.T) {
  38. var (
  39. c = CacheBaseLoader{}
  40. )
  41. convey.Convey("Key", t, func(ctx convey.C) {
  42. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  43. key := c.Key()
  44. ctx.Convey("Then key should not be nil.", func(ctx convey.C) {
  45. ctx.So(key, convey.ShouldNotBeNil)
  46. })
  47. })
  48. })
  49. }
  50. func TestDatadaoValueCacheBaseLoader(t *testing.T) {
  51. var (
  52. c = CacheBaseLoader{Val: 1}
  53. )
  54. convey.Convey("Value", t, func(ctx convey.C) {
  55. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  56. value := c.Value()
  57. ctx.Convey("Then value should not be nil.", func(ctx convey.C) {
  58. ctx.So(value, convey.ShouldNotBeNil)
  59. })
  60. })
  61. })
  62. }
  63. func TestDatadaoExpireCacheBaseLoader(t *testing.T) {
  64. var (
  65. c = CacheBaseLoader{Val: 1}
  66. )
  67. convey.Convey("Expire", t, func(ctx convey.C) {
  68. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  69. p1 := c.Expire()
  70. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  71. ctx.So(p1, convey.ShouldNotBeNil)
  72. })
  73. })
  74. })
  75. }
  76. func TestDatadaoDesc(t *testing.T) {
  77. var (
  78. c = CacheBaseLoader{Val: 1}
  79. )
  80. convey.Convey("Desc", t, func(ctx convey.C) {
  81. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  82. p1 := c.Desc()
  83. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  84. ctx.So(p1, convey.ShouldNotBeNil)
  85. })
  86. })
  87. })
  88. }
  89. func TestDatadaoNewCacheMcnDataWithTp(t *testing.T) {
  90. convey.Convey("NewCacheMcnDataWithTp", t, func(ctx convey.C) {
  91. var (
  92. signID = int64(0)
  93. date = time.Now()
  94. tp = ""
  95. val = interface{}(0)
  96. desc = ""
  97. loadFunc LoadFuncWithTp
  98. )
  99. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  100. p1 := NewCacheMcnDataWithTp(signID, date, tp, val, desc, loadFunc)
  101. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  102. ctx.So(p1, convey.ShouldNotBeNil)
  103. })
  104. })
  105. })
  106. }
  107. func TestDatadaoKeyCacheMcnDataWithTp(t *testing.T) {
  108. var (
  109. s = cacheMcnDataWithTp{CacheBaseLoader: CacheBaseLoader{Val: 1}}
  110. )
  111. convey.Convey("Key", t, func(ctx convey.C) {
  112. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  113. key := s.Key()
  114. ctx.Convey("Then key should not be nil.", func(ctx convey.C) {
  115. ctx.So(key, convey.ShouldNotBeNil)
  116. })
  117. })
  118. })
  119. }
  120. func TestDatadaoLoadValuecacheMcnDataWithTp(t *testing.T) {
  121. convey.Convey("LoadValue", t, func(ctx convey.C) {
  122. var (
  123. c = context.Background()
  124. s = cacheMcnDataWithTp{
  125. CacheBaseLoader: CacheBaseLoader{Val: 1},
  126. LoadFunc: func(c context.Context, signID int64, date time.Time, tp string) (res interface{}, err error) {
  127. return d.GetIndexSource(c, signID, date, tp)
  128. },
  129. }
  130. )
  131. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  132. value, err := s.LoadValue(c)
  133. ctx.Convey("Then err should be nil.value should not be nil.", func(ctx convey.C) {
  134. ctx.So(err, convey.ShouldBeNil)
  135. ctx.So(value, convey.ShouldNotBeNil)
  136. })
  137. })
  138. })
  139. }
  140. func TestDatadaoNewCacheMcnDataSignID(t *testing.T) {
  141. convey.Convey("NewCacheMcnDataSignID", t, func(ctx convey.C) {
  142. var (
  143. signID = int64(0)
  144. date = time.Now()
  145. val = interface{}(0)
  146. desc = ""
  147. loadFunc LoadFuncOnlySign
  148. )
  149. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  150. p1 := NewCacheMcnDataSignID(signID, date, val, desc, loadFunc)
  151. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  152. ctx.So(p1, convey.ShouldNotBeNil)
  153. })
  154. })
  155. })
  156. }
  157. func TestDatadaoKeycacheMcnDataSignID(t *testing.T) {
  158. var (
  159. s = cacheMcnDataSignID{CacheBaseLoader: CacheBaseLoader{Val: 1}}
  160. )
  161. convey.Convey("Key", t, func(ctx convey.C) {
  162. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  163. key := s.Key()
  164. ctx.Convey("Then key should not be nil.", func(ctx convey.C) {
  165. ctx.So(key, convey.ShouldNotBeNil)
  166. })
  167. })
  168. })
  169. }
  170. func TestDatadaoLoadValuecacheMcnDataSignID(t *testing.T) {
  171. convey.Convey("LoadValue", t, func(ctx convey.C) {
  172. var (
  173. c = context.Background()
  174. s = cacheMcnDataSignID{
  175. CacheBaseLoader: CacheBaseLoader{Val: 1},
  176. LoadFunc: func(c context.Context, signID int64, date time.Time) (res interface{}, err error) {
  177. return d.GetMcnFans(c, signID, date)
  178. },
  179. }
  180. )
  181. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  182. value, err := s.LoadValue(c)
  183. ctx.Convey("Then err should be nil.value should not be nil.", func(ctx convey.C) {
  184. ctx.So(err, convey.ShouldBeNil)
  185. ctx.So(value, convey.ShouldNotBeNil)
  186. })
  187. })
  188. })
  189. }