help_test.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. xtime "time"
  6. "go-common/app/interface/main/web/model"
  7. "go-common/library/time"
  8. "github.com/smartystreets/goconvey/convey"
  9. "gopkg.in/h2non/gock.v1"
  10. )
  11. func TestDaoHelpList(t *testing.T) {
  12. convey.Convey("HelpList", t, func(ctx convey.C) {
  13. var (
  14. c = context.Background()
  15. pTypeID = ""
  16. )
  17. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  18. defer gock.OffAll()
  19. httpMock("GET", d.helpListURL).Reply(200).JSON(`{"retCode":"000000"}`)
  20. data, err := d.HelpList(c, pTypeID)
  21. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  22. ctx.So(err, convey.ShouldBeNil)
  23. ctx.Printf("%+v", data)
  24. })
  25. })
  26. })
  27. }
  28. func TestDaokeyHl(t *testing.T) {
  29. convey.Convey("keyHl", t, func(ctx convey.C) {
  30. var (
  31. pTypeID = ""
  32. )
  33. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  34. p1 := keyHl(pTypeID)
  35. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  36. ctx.So(p1, convey.ShouldNotBeNil)
  37. })
  38. })
  39. })
  40. }
  41. func TestDaokeyHd(t *testing.T) {
  42. convey.Convey("keyHd", t, func(ctx convey.C) {
  43. var (
  44. qTypeID = ""
  45. keyFlag = int(0)
  46. pn = int(0)
  47. ps = int(0)
  48. )
  49. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  50. p1 := keyHd(qTypeID, keyFlag, pn, ps)
  51. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  52. ctx.So(p1, convey.ShouldNotBeNil)
  53. })
  54. })
  55. })
  56. }
  57. func TestDaoSetHlCache(t *testing.T) {
  58. convey.Convey("SetHlCache", t, func(ctx convey.C) {
  59. var (
  60. c = context.Background()
  61. pTypeID = ""
  62. Hl = []*model.HelpList{}
  63. )
  64. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  65. err := d.SetHlCache(c, pTypeID, Hl)
  66. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  67. ctx.So(err, convey.ShouldBeNil)
  68. })
  69. })
  70. })
  71. }
  72. func TestDaoHlCache(t *testing.T) {
  73. convey.Convey("HlCache", t, func(ctx convey.C) {
  74. var (
  75. c = context.Background()
  76. pTypeID = ""
  77. )
  78. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  79. res, err := d.HlCache(c, pTypeID)
  80. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. ctx.Printf("%+v", res)
  83. })
  84. })
  85. })
  86. }
  87. func TestDaoHelpDetail(t *testing.T) {
  88. convey.Convey("HelpDetail", t, func(ctx convey.C) {
  89. var (
  90. c = context.Background()
  91. qTypeID = ""
  92. keyFlag = int(0)
  93. pn = int(0)
  94. ps = int(0)
  95. ip = ""
  96. )
  97. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  98. defer gock.OffAll()
  99. httpMock("GET", d.helpSearchURL).Reply(200).JSON(`{"retCode":"000000", "total":1}`)
  100. data, total, err := d.HelpDetail(c, qTypeID, keyFlag, pn, ps, ip)
  101. ctx.Convey("Then err should be nil.data,total should not be nil.", func(ctx convey.C) {
  102. ctx.So(err, convey.ShouldBeNil)
  103. ctx.So(total, convey.ShouldNotBeNil)
  104. ctx.Printf("%+v", data)
  105. })
  106. })
  107. })
  108. }
  109. func TestDaoHelpSearch(t *testing.T) {
  110. convey.Convey("HelpSearch", t, func(ctx convey.C) {
  111. var (
  112. c = context.Background()
  113. pTypeID = ""
  114. keyWords = ""
  115. keyFlag = int(0)
  116. pn = int(0)
  117. ps = int(0)
  118. )
  119. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  120. defer gock.OffAll()
  121. httpMock("GET", d.helpSearchURL).Reply(200).JSON(`{"retCode":"000000", "total":1}`)
  122. data, total, err := d.HelpSearch(c, pTypeID, keyWords, keyFlag, pn, ps)
  123. ctx.Convey("Then err should be nil.data,total should not be nil.", func(ctx convey.C) {
  124. ctx.So(err, convey.ShouldBeNil)
  125. ctx.So(total, convey.ShouldNotBeNil)
  126. ctx.Printf("%+v", data)
  127. })
  128. })
  129. })
  130. }
  131. func TestDaoSetDetailCache(t *testing.T) {
  132. convey.Convey("SetDetailCache", t, func(ctx convey.C) {
  133. var (
  134. c = context.Background()
  135. qTypeID = ""
  136. keyFlag = int(0)
  137. pn = int(0)
  138. ps = int(0)
  139. total = int(0)
  140. data = []*model.HelpDeatil{{AllTypeName: "1111"}, {AllTypeName: "2222"}}
  141. )
  142. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  143. err := d.SetDetailCache(c, qTypeID, keyFlag, pn, ps, total, data)
  144. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  145. ctx.So(err, convey.ShouldBeNil)
  146. })
  147. })
  148. })
  149. }
  150. func TestDaoDetailCache(t *testing.T) {
  151. convey.Convey("DetailCache", t, func(ctx convey.C) {
  152. var (
  153. c = context.Background()
  154. qTypeID = ""
  155. keyFlag = int(0)
  156. pn = int(0)
  157. ps = int(0)
  158. )
  159. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  160. res, count, err := d.DetailCache(c, qTypeID, keyFlag, pn, ps)
  161. ctx.Convey("Then err should be nil.res,count should not be nil.", func(ctx convey.C) {
  162. ctx.So(err, convey.ShouldBeNil)
  163. ctx.So(count, convey.ShouldNotBeNil)
  164. convey.Printf("%+v", res)
  165. })
  166. })
  167. })
  168. }
  169. func TestDaofromHd(t *testing.T) {
  170. convey.Convey("fromHd", t, func(ctx convey.C) {
  171. var (
  172. i = int64(0)
  173. )
  174. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  175. p1 := fromHd(i)
  176. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  177. ctx.So(p1, convey.ShouldNotBeNil)
  178. })
  179. })
  180. })
  181. }
  182. func TestDaocombineHd(t *testing.T) {
  183. convey.Convey("combineHd", t, func(ctx convey.C) {
  184. var (
  185. create = time.Time(xtime.Now().Unix())
  186. count = int(0)
  187. )
  188. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  189. p1 := combineHd(create, count)
  190. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  191. ctx.So(p1, convey.ShouldNotBeNil)
  192. })
  193. })
  194. })
  195. }