archive_test.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package data
  2. import (
  3. "context"
  4. "go-common/library/ecode"
  5. "reflect"
  6. "testing"
  7. hbase "go-common/library/database/hbase.v2"
  8. "github.com/bouk/monkey"
  9. "github.com/smartystreets/goconvey/convey"
  10. "github.com/tsuna/gohbase/hrpc"
  11. )
  12. func TestDatahbaseMd5Key(t *testing.T) {
  13. var (
  14. aid = int64(0)
  15. )
  16. convey.Convey("hbaseMd5Key", t, func(ctx convey.C) {
  17. p1 := hbaseMd5Key(aid)
  18. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  19. ctx.So(p1, convey.ShouldNotBeNil)
  20. })
  21. })
  22. }
  23. func TestDataVideoQuitPoints(t *testing.T) {
  24. var (
  25. c = context.TODO()
  26. cid = int64(1)
  27. )
  28. convey.Convey("VideoQuitPoints1", t, func(ctx convey.C) {
  29. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  30. res := &hrpc.Result{
  31. Cells: make([]*hrpc.Cell, 0),
  32. }
  33. res.Cells = append(res.Cells, &hrpc.Cell{
  34. Family: HBaseFamilyPlat,
  35. Qualifier: HBaseColumnShare,
  36. })
  37. return res, nil
  38. })
  39. defer guard.Unpatch()
  40. _, err := d.VideoQuitPoints(c, cid)
  41. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  42. ctx.So(err, convey.ShouldBeNil)
  43. })
  44. })
  45. convey.Convey("VideoQuitPoints2", t, func(ctx convey.C) {
  46. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  47. return nil, ecode.CreativeDataErr
  48. })
  49. defer guard.Unpatch()
  50. _, err := d.VideoQuitPoints(c, cid)
  51. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  52. ctx.So(err, convey.ShouldNotBeNil)
  53. })
  54. })
  55. }
  56. func TestDataArchiveStat(t *testing.T) {
  57. var (
  58. c = context.TODO()
  59. aid = int64(1)
  60. err error
  61. )
  62. convey.Convey("1", t, func(ctx convey.C) {
  63. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  64. return nil, ecode.CreativeDataErr
  65. })
  66. defer guard.Unpatch()
  67. _, err = d.ArchiveStat(c, aid)
  68. ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
  69. ctx.So(err, convey.ShouldEqual, ecode.CreativeDataErr)
  70. })
  71. })
  72. convey.Convey("2", t, func(ctx convey.C) {
  73. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  74. res := &hrpc.Result{}
  75. return res, nil
  76. })
  77. defer guard.Unpatch()
  78. _, err = d.ArchiveStat(c, aid)
  79. ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
  80. ctx.So(err, convey.ShouldBeNil)
  81. })
  82. })
  83. convey.Convey("3", t, func(ctx convey.C) {
  84. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  85. return nil, nil
  86. })
  87. defer guard.Unpatch()
  88. _, err = d.ArchiveStat(c, aid)
  89. ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
  90. ctx.So(err, convey.ShouldBeNil)
  91. })
  92. })
  93. convey.Convey("4", t, func(ctx convey.C) {
  94. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  95. res := &hrpc.Result{
  96. Cells: make([]*hrpc.Cell, 0),
  97. }
  98. res.Cells = append(res.Cells, &hrpc.Cell{
  99. Family: HBaseFamilyPlat,
  100. Qualifier: HBaseColumnWebPC,
  101. })
  102. return res, nil
  103. })
  104. defer guard.Unpatch()
  105. _, err = d.ArchiveStat(c, aid)
  106. ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
  107. ctx.So(err, convey.ShouldBeNil)
  108. })
  109. })
  110. convey.Convey("5", t, func(ctx convey.C) {
  111. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  112. res := &hrpc.Result{
  113. Cells: make([]*hrpc.Cell, 0),
  114. }
  115. res.Cells = append(res.Cells, &hrpc.Cell{
  116. Family: HBaseFamilyPlat,
  117. Qualifier: HBaseColumnWebH5,
  118. })
  119. return res, nil
  120. })
  121. defer guard.Unpatch()
  122. _, err = d.ArchiveStat(c, aid)
  123. ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
  124. ctx.So(err, convey.ShouldBeNil)
  125. })
  126. })
  127. convey.Convey("6", t, func(ctx convey.C) {
  128. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  129. res := &hrpc.Result{
  130. Cells: make([]*hrpc.Cell, 0),
  131. }
  132. res.Cells = append(res.Cells, &hrpc.Cell{
  133. Family: HBaseFamilyPlat,
  134. Qualifier: HBaseColumnShare,
  135. })
  136. return res, nil
  137. })
  138. defer guard.Unpatch()
  139. _, err = d.ArchiveStat(c, aid)
  140. ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
  141. ctx.So(err, convey.ShouldBeNil)
  142. })
  143. })
  144. }
  145. func TestDataArchiveArea(t *testing.T) {
  146. var (
  147. c = context.TODO()
  148. aid = int64(1)
  149. )
  150. convey.Convey("ArchiveArea1", t, func(ctx convey.C) {
  151. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  152. return nil, ecode.CreativeDataErr
  153. })
  154. defer guard.Unpatch()
  155. _, err := d.ArchiveArea(c, aid)
  156. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  157. ctx.So(err, convey.ShouldEqual, ecode.CreativeDataErr)
  158. })
  159. })
  160. convey.Convey("ArchiveArea2", t, func(ctx convey.C) {
  161. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  162. res := &hrpc.Result{
  163. Cells: make([]*hrpc.Cell, 0),
  164. }
  165. res.Cells = append(res.Cells, &hrpc.Cell{
  166. Family: HBaseFamilyPlat,
  167. Qualifier: HBaseColumnShare,
  168. })
  169. return res, nil
  170. })
  171. defer guard.Unpatch()
  172. _, err := d.ArchiveArea(c, aid)
  173. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  174. ctx.So(err, convey.ShouldBeNil)
  175. })
  176. })
  177. }
  178. func TestDataBaseUpStat(t *testing.T) {
  179. var (
  180. c = context.TODO()
  181. mid = int64(0)
  182. date = ""
  183. )
  184. convey.Convey("BaseUpStat", t, func(ctx convey.C) {
  185. _, err := d.BaseUpStat(c, mid, date)
  186. ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
  187. ctx.So(err, convey.ShouldEqual, ecode.CreativeDataErr)
  188. })
  189. })
  190. }
  191. func TestDataUpArchiveStatQuery(t *testing.T) {
  192. var (
  193. c = context.TODO()
  194. mid = int64(1)
  195. date = ""
  196. )
  197. convey.Convey("UpArchiveStatQuery1", t, func(ctx convey.C) {
  198. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  199. return nil, ecode.CreativeDataErr
  200. })
  201. defer guard.Unpatch()
  202. _, err := d.UpArchiveStatQuery(c, mid, date)
  203. ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
  204. ctx.So(err, convey.ShouldNotBeNil)
  205. })
  206. })
  207. convey.Convey("UpArchiveStatQuery2", t, func(ctx convey.C) {
  208. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  209. res := &hrpc.Result{}
  210. return res, nil
  211. })
  212. defer guard.Unpatch()
  213. _, err := d.UpArchiveStatQuery(c, mid, date)
  214. ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
  215. ctx.So(err, convey.ShouldBeNil)
  216. })
  217. })
  218. }