mysql_test.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "time"
  7. "go-common/app/admin/main/card/model"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoAddGroup(t *testing.T) {
  11. convey.Convey("AddGroup", t, func(ctx convey.C) {
  12. var (
  13. c = context.Background()
  14. arg = &model.AddGroup{
  15. Name: fmt.Sprintf("%v", time.Now().Unix()),
  16. State: 0,
  17. Operator: "superman",
  18. OrderNum: time.Now().Unix(),
  19. }
  20. )
  21. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  22. err := d.AddGroup(c, arg)
  23. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  24. ctx.So(err, convey.ShouldBeNil)
  25. })
  26. })
  27. })
  28. }
  29. func TestDaoUpdateGroup(t *testing.T) {
  30. convey.Convey("UpdateGroup", t, func(ctx convey.C) {
  31. var (
  32. c = context.Background()
  33. arg = &model.UpdateGroup{
  34. ID: 1,
  35. Name: fmt.Sprintf("%v", time.Now().UnixNano()),
  36. State: 0,
  37. Operator: "superman",
  38. }
  39. )
  40. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  41. err := d.UpdateGroup(c, arg)
  42. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  43. ctx.So(err, convey.ShouldBeNil)
  44. })
  45. })
  46. })
  47. }
  48. func TestDaoCards(t *testing.T) {
  49. convey.Convey("Cards", t, func(ctx convey.C) {
  50. var (
  51. c = context.Background()
  52. )
  53. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  54. res, err := d.Cards(c)
  55. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  56. ctx.So(err, convey.ShouldBeNil)
  57. ctx.So(res, convey.ShouldNotBeNil)
  58. })
  59. })
  60. })
  61. }
  62. func TestDaoGroupByName(t *testing.T) {
  63. convey.Convey("GroupByName", t, func(ctx convey.C) {
  64. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  65. _, err := d.GroupByName("te123156544664st")
  66. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  67. ctx.So(err, convey.ShouldBeNil)
  68. })
  69. })
  70. })
  71. }
  72. func TestDaoCardByName(t *testing.T) {
  73. convey.Convey("CardByName", t, func(ctx convey.C) {
  74. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  75. _, err := d.CardByName("tes...t")
  76. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. })
  79. })
  80. })
  81. }
  82. func TestDaoCardsByGid(t *testing.T) {
  83. convey.Convey("CardsByGid", t, func(ctx convey.C) {
  84. var (
  85. c = context.Background()
  86. gid = int64(1)
  87. )
  88. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  89. res, err := d.CardsByGid(c, gid)
  90. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  91. ctx.So(err, convey.ShouldBeNil)
  92. ctx.So(res, convey.ShouldNotBeNil)
  93. })
  94. })
  95. })
  96. }
  97. func TestDaoCardsByIds(t *testing.T) {
  98. convey.Convey("CardsByIds", t, func(ctx convey.C) {
  99. var (
  100. c = context.Background()
  101. ids = []int64{1, 2, 3, 4, 5}
  102. )
  103. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  104. res, err := d.CardsByIds(c, ids)
  105. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  106. ctx.So(err, convey.ShouldBeNil)
  107. ctx.So(res, convey.ShouldNotBeNil)
  108. })
  109. })
  110. })
  111. }
  112. func TestDaoGroupsByIds(t *testing.T) {
  113. convey.Convey("GroupsByIds", t, func(ctx convey.C) {
  114. var (
  115. c = context.Background()
  116. ids = []int64{1, 2, 3, 4, 5}
  117. )
  118. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  119. res, err := d.GroupsByIds(c, ids)
  120. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  121. ctx.So(err, convey.ShouldBeNil)
  122. ctx.So(res, convey.ShouldNotBeNil)
  123. })
  124. })
  125. })
  126. }
  127. func TestDaoAddCard(t *testing.T) {
  128. convey.Convey("AddCard", t, func(ctx convey.C) {
  129. var (
  130. arg = &model.AddCard{
  131. Name: fmt.Sprintf("%v", time.Now().Unix()),
  132. State: 0,
  133. Operator: "superman",
  134. OrderNum: time.Now().Unix(),
  135. CardURL: "http://www.baidu.com",
  136. BigCradURL: "http://www.baidu.com",
  137. }
  138. )
  139. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  140. err := d.AddCard(arg)
  141. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  142. ctx.So(err, convey.ShouldBeNil)
  143. })
  144. })
  145. })
  146. }
  147. func TestDaoUpdateCard(t *testing.T) {
  148. convey.Convey("UpdateCard", t, func(ctx convey.C) {
  149. var (
  150. req = &model.UpdateCard{
  151. ID: 1,
  152. Name: fmt.Sprintf("%v", time.Now().UnixNano()),
  153. State: 0,
  154. Operator: "superman",
  155. }
  156. )
  157. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  158. err := d.UpdateCard(req)
  159. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  160. ctx.So(err, convey.ShouldBeNil)
  161. })
  162. })
  163. })
  164. }
  165. func TestDaoUpdateCardState(t *testing.T) {
  166. convey.Convey("UpdateCardState", t, func(ctx convey.C) {
  167. var (
  168. c = context.Background()
  169. id = int64(0)
  170. state = int8(0)
  171. )
  172. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  173. err := d.UpdateCardState(c, id, state)
  174. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  175. ctx.So(err, convey.ShouldBeNil)
  176. })
  177. })
  178. })
  179. }
  180. func TestDaoDeleteCard(t *testing.T) {
  181. convey.Convey("DeleteCard", t, func(ctx convey.C) {
  182. var (
  183. c = context.Background()
  184. id = int64(0)
  185. )
  186. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  187. err := d.DeleteCard(c, id)
  188. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  189. ctx.So(err, convey.ShouldBeNil)
  190. })
  191. })
  192. })
  193. }
  194. func TestDaoDeleteGroup(t *testing.T) {
  195. convey.Convey("DeleteGroup", t, func(ctx convey.C) {
  196. var (
  197. c = context.Background()
  198. id = int64(0)
  199. )
  200. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  201. err := d.DeleteGroup(c, id)
  202. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  203. ctx.So(err, convey.ShouldBeNil)
  204. })
  205. })
  206. })
  207. }
  208. func TestDaoUpdateGroupState(t *testing.T) {
  209. convey.Convey("UpdateGroupState", t, func(ctx convey.C) {
  210. var (
  211. c = context.Background()
  212. id = int64(0)
  213. state = int8(0)
  214. )
  215. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  216. err := d.UpdateGroupState(c, id, state)
  217. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  218. ctx.So(err, convey.ShouldBeNil)
  219. })
  220. })
  221. })
  222. }
  223. func TestDaoMaxCardOrder(t *testing.T) {
  224. convey.Convey("MaxCardOrder", t, func(ctx convey.C) {
  225. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  226. max, err := d.MaxCardOrder()
  227. ctx.Convey("Then err should be nil.max should not be nil.", func(ctx convey.C) {
  228. ctx.So(err, convey.ShouldBeNil)
  229. ctx.So(max, convey.ShouldNotBeNil)
  230. })
  231. })
  232. })
  233. }
  234. func TestDaoMaxGroupOrder(t *testing.T) {
  235. convey.Convey("MaxGroupOrder", t, func(ctx convey.C) {
  236. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  237. max, err := d.MaxGroupOrder()
  238. ctx.Convey("Then err should be nil.max should not be nil.", func(ctx convey.C) {
  239. ctx.So(err, convey.ShouldBeNil)
  240. ctx.So(max, convey.ShouldNotBeNil)
  241. })
  242. })
  243. })
  244. }
  245. func TestDaoBatchUpdateCardOrder(t *testing.T) {
  246. convey.Convey("BatchUpdateCardOrder", t, func(ctx convey.C) {
  247. var (
  248. c = context.Background()
  249. cs = []*model.Card{{
  250. ID: 1, OrderNum: 1},
  251. {ID: 2, OrderNum: 2}}
  252. )
  253. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  254. err := d.BatchUpdateCardOrder(c, cs)
  255. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  256. ctx.So(err, convey.ShouldBeNil)
  257. })
  258. })
  259. })
  260. }
  261. func TestDaoBatchUpdateCardGroupOrder(t *testing.T) {
  262. convey.Convey("BatchUpdateCardGroupOrder", t, func(ctx convey.C) {
  263. var (
  264. c = context.Background()
  265. cs = []*model.CardGroup{{ID: 2, OrderNum: 2}, {ID: 1, OrderNum: 1}}
  266. )
  267. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  268. err := d.BatchUpdateCardGroupOrder(c, cs)
  269. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  270. ctx.So(err, convey.ShouldBeNil)
  271. })
  272. })
  273. })
  274. }
  275. func TestDaoGroups(t *testing.T) {
  276. convey.Convey("Groups", t, func(ctx convey.C) {
  277. var (
  278. c = context.Background()
  279. arg = &model.ArgQueryGroup{}
  280. )
  281. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  282. res, err := d.Groups(c, arg)
  283. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  284. ctx.So(err, convey.ShouldBeNil)
  285. ctx.So(res, convey.ShouldNotBeNil)
  286. })
  287. })
  288. })
  289. }