api_test.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/interface/main/videoup/model/archive"
  5. upapi "go-common/app/service/main/up/api/v1"
  6. "go-common/library/ecode"
  7. "testing"
  8. "github.com/golang/mock/gomock"
  9. . "github.com/smartystreets/goconvey/convey"
  10. "gopkg.in/h2non/gock.v1"
  11. )
  12. func TestPing(t *testing.T) {
  13. Convey("Ping", t, func(ctx C) {
  14. var (
  15. c = context.Background()
  16. )
  17. ctx.Convey("When everything goes positive", func(ctx C) {
  18. err := d.Ping(c)
  19. ctx.Convey("Then err should be nil.a,vs should not be nil.", func(ctx C) {
  20. ctx.So(err, ShouldNotBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestArchiveView(t *testing.T) {
  26. Convey("View", t, func(ctx C) {
  27. var (
  28. c = context.Background()
  29. aid = int64(10110826)
  30. ip = "127.0.0.1"
  31. )
  32. ctx.Convey("When everything goes positive", func(ctx C) {
  33. defer gock.OffAll()
  34. httpMock("GET", d.viewURI).Reply(200).JSON(`{"code":20001,"data":""}`)
  35. a, vs, err := d.View(c, aid, ip)
  36. ctx.Convey("Then err should be nil.a,vs should not be nil.", func(ctx C) {
  37. ctx.So(err, ShouldNotBeNil)
  38. ctx.So(vs, ShouldBeNil)
  39. ctx.So(a, ShouldBeNil)
  40. })
  41. })
  42. })
  43. }
  44. func TestArchiveAdd(t *testing.T) {
  45. Convey("Add", t, func(ctx C) {
  46. var (
  47. c = context.Background()
  48. ap = &archive.ArcParam{}
  49. ip = "127.0.0.1"
  50. )
  51. ctx.Convey("When everything goes positive", func(ctx C) {
  52. defer gock.OffAll()
  53. httpMock("Post", d.addURI).Reply(200).JSON(`{"code":20001,"data":""}`)
  54. aid, err := d.Add(c, ap, ip)
  55. ctx.Convey("Then err should be nil.aid should not be nil.", func(ctx C) {
  56. ctx.So(err, ShouldNotBeNil)
  57. ctx.So(aid, ShouldNotBeNil)
  58. })
  59. })
  60. })
  61. }
  62. func TestArchiveEdit(t *testing.T) {
  63. Convey("Edit", t, func(ctx C) {
  64. var (
  65. c = context.Background()
  66. ap = &archive.ArcParam{}
  67. ip = "127.0.0.1"
  68. )
  69. ctx.Convey("When everything goes positive", func(ctx C) {
  70. defer gock.OffAll()
  71. httpMock("Post", d.editURI).Reply(200).JSON(`{"code":20001,"data":""}`)
  72. err := d.Edit(c, ap, ip)
  73. ctx.Convey("Then err should be nil.", func(ctx C) {
  74. ctx.So(err, ShouldNotBeNil)
  75. })
  76. })
  77. })
  78. }
  79. func TestArchiveDescFormat(t *testing.T) {
  80. Convey("DescFormat", t, func(ctx C) {
  81. var (
  82. c = context.Background()
  83. )
  84. ctx.Convey("When everything goes positive", func(ctx C) {
  85. descFormats, err := d.DescFormat(c)
  86. ctx.Convey("Then err should be nil.descFormats should not be nil.", func(ctx C) {
  87. ctx.So(err, ShouldBeNil)
  88. ctx.So(descFormats, ShouldNotBeNil)
  89. })
  90. })
  91. })
  92. }
  93. func TestArchiveTagUp(t *testing.T) {
  94. Convey("TagUp", t, func(ctx C) {
  95. var (
  96. c = context.Background()
  97. aid = int64(10110826)
  98. tag = "iamatag"
  99. ip = "127.0.0.1"
  100. )
  101. ctx.Convey("When everything goes positive", func(ctx C) {
  102. err := d.TagUp(c, aid, tag, ip)
  103. ctx.Convey("Then err should be nil.", func(ctx C) {
  104. ctx.So(err, ShouldBeNil)
  105. })
  106. })
  107. })
  108. }
  109. func TestArchivePorderCfgList(t *testing.T) {
  110. Convey("PorderCfgList", t, func(ctx C) {
  111. var (
  112. c = context.Background()
  113. )
  114. ctx.Convey("When everything goes positive", func(ctx C) {
  115. cfgs, err := d.PorderCfgList(c)
  116. ctx.Convey("Then err should be nil.cfgs should not be nil.", func(ctx C) {
  117. ctx.So(err, ShouldBeNil)
  118. ctx.So(cfgs, ShouldNotBeNil)
  119. })
  120. })
  121. })
  122. }
  123. func TestArchiveGameList(t *testing.T) {
  124. Convey("GameList", t, func(ctx C) {
  125. var (
  126. c = context.Background()
  127. )
  128. ctx.Convey("When everything goes positive", func(ctx C) {
  129. defer gock.OffAll()
  130. httpMock("GET", d.viewURI).Reply(200).JSON(`{"code":20051,"data":""}`)
  131. gameMap, err := d.GameList(c)
  132. ctx.Convey("Then err should be nil.gameMap should not be nil.", func(ctx C) {
  133. ctx.So(err, ShouldNotBeNil)
  134. ctx.So(gameMap, ShouldNotBeNil)
  135. })
  136. })
  137. })
  138. }
  139. func TestUpSpecial(t *testing.T) {
  140. var (
  141. c = context.Background()
  142. res map[int64]int64
  143. err error
  144. )
  145. Convey("UpSpecial", t, func(ctx C) {
  146. res, err = d.UpSpecial(c, 17)
  147. So(res, ShouldNotBeNil)
  148. So(err, ShouldBeNil)
  149. })
  150. }
  151. func TestDao_ApplyStaffs(t *testing.T) {
  152. var (
  153. c = context.Background()
  154. aid = int64(10110826)
  155. ip = "127.0.0.1"
  156. err error
  157. )
  158. Convey("ApplyStaffs", t, func(ctx C) {
  159. httpMock("GET", d.applyStaffs).Reply(200).JSON(`{"code":0}`)
  160. _, err = d.ApplyStaffs(c, aid, ip)
  161. So(err, ShouldBeNil)
  162. })
  163. }
  164. func WithMock(t *testing.T, f func(mock *gomock.Controller)) func() {
  165. return func() {
  166. mockCtrl := gomock.NewController(t)
  167. defer mockCtrl.Finish()
  168. f(mockCtrl)
  169. }
  170. }
  171. func TestDao_StaffUps(t *testing.T) {
  172. Convey("StaffUps", t, WithMock(t, func(mockCtrl *gomock.Controller) {
  173. var (
  174. c = context.Background()
  175. err error
  176. ups map[int64]int64
  177. )
  178. mock := upapi.NewMockUpClient(mockCtrl)
  179. d.UpClient = mock
  180. mockReq := &upapi.UpGroupMidsReq{
  181. GroupID: 1,
  182. Pn: 1,
  183. Ps: 1,
  184. }
  185. mock.EXPECT().UpGroupMids(gomock.Any(), mockReq).Return(nil, ecode.CreativeAccServiceErr)
  186. ups, err = d.StaffUps(c)
  187. So(err, ShouldNotBeNil)
  188. So(ups, ShouldBeNil)
  189. }))
  190. }
  191. func TestDao_StaffTypeConfig(t *testing.T) {
  192. var (
  193. c = context.Background()
  194. err error
  195. )
  196. Convey("StaffTypeConfig", t, func(ctx C) {
  197. httpMock("GET", d.staffConfigURI).Reply(200).JSON(`{"code":0,"data":{"is_gray":true,"typelist":[{"typeid":22,"max_staff":6}]}}`)
  198. _, _, err = d.StaffTypeConfig(c)
  199. So(err, ShouldBeNil)
  200. })
  201. }