mysql_test.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/admin/main/vip/model"
  6. "testing"
  7. "time"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaojoinPoolCondition(t *testing.T) {
  11. convey.Convey("joinPoolCondition", t, func(ctx convey.C) {
  12. var (
  13. sqlStr = ""
  14. q = &model.ResoucePoolBo{}
  15. pn = int(0)
  16. ps = int(0)
  17. )
  18. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  19. p1 := d.joinPoolCondition(sqlStr, q, pn, ps)
  20. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  21. ctx.So(p1, convey.ShouldNotBeNil)
  22. })
  23. })
  24. })
  25. }
  26. func TestDaojoinHistoryCondition(t *testing.T) {
  27. convey.Convey("joinHistoryCondition", t, func(ctx convey.C) {
  28. var (
  29. sql = ""
  30. u = &model.UserChangeHistoryReq{}
  31. iscount bool
  32. )
  33. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  34. p1 := d.joinHistoryCondition(sql, u, iscount)
  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 TestDaoSelPoolByName(t *testing.T) {
  42. convey.Convey("SelPoolByName", t, func(ctx convey.C) {
  43. var (
  44. c = context.Background()
  45. name = ""
  46. )
  47. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  48. _, err := d.SelPoolByName(c, name)
  49. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  50. ctx.So(err, convey.ShouldBeNil)
  51. })
  52. })
  53. })
  54. }
  55. func TestDaoSelCountPool(t *testing.T) {
  56. convey.Convey("SelCountPool", t, func(ctx convey.C) {
  57. var (
  58. c = context.Background()
  59. r = &model.ResoucePoolBo{}
  60. )
  61. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  62. count, err := d.SelCountPool(c, r)
  63. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  64. ctx.So(err, convey.ShouldBeNil)
  65. ctx.So(count, convey.ShouldNotBeNil)
  66. })
  67. })
  68. })
  69. }
  70. func TestDaoSelPool(t *testing.T) {
  71. convey.Convey("SelPool", t, func(ctx convey.C) {
  72. var (
  73. c = context.Background()
  74. r = &model.ResoucePoolBo{}
  75. pn = int(0)
  76. ps = int(0)
  77. )
  78. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  79. res, err := d.SelPool(c, r, pn, ps)
  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.So(res, convey.ShouldNotBeNil)
  83. })
  84. })
  85. })
  86. }
  87. func TestDaoSelPoolRow(t *testing.T) {
  88. convey.Convey("SelPoolRow", t, func(ctx convey.C) {
  89. var (
  90. c = context.Background()
  91. id = int(0)
  92. )
  93. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  94. _, err := d.SelPoolRow(c, id)
  95. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  96. ctx.So(err, convey.ShouldBeNil)
  97. })
  98. })
  99. })
  100. }
  101. func TestDaoAddPool(t *testing.T) {
  102. convey.Convey("AddPool", t, func(ctx convey.C) {
  103. var (
  104. c = context.Background()
  105. r = &model.ResoucePoolBo{}
  106. )
  107. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  108. a, err := d.AddPool(c, r)
  109. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  110. ctx.So(err, convey.ShouldBeNil)
  111. ctx.So(a, convey.ShouldNotBeNil)
  112. })
  113. })
  114. })
  115. }
  116. func TestDaoUpdatePool(t *testing.T) {
  117. convey.Convey("UpdatePool", t, func(ctx convey.C) {
  118. var (
  119. c = context.Background()
  120. r = &model.ResoucePoolBo{}
  121. )
  122. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  123. a, err := d.UpdatePool(c, r)
  124. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  125. ctx.So(err, convey.ShouldBeNil)
  126. ctx.So(a, convey.ShouldNotBeNil)
  127. })
  128. })
  129. })
  130. }
  131. func TestDaoSelBatchRow(t *testing.T) {
  132. convey.Convey("SelBatchRow", t, func(ctx convey.C) {
  133. var (
  134. c = context.Background()
  135. id = int(0)
  136. )
  137. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  138. _, err := d.SelBatchRow(c, id)
  139. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  140. ctx.So(err, convey.ShouldBeNil)
  141. })
  142. })
  143. })
  144. }
  145. func TestDaoSelBatchRows(t *testing.T) {
  146. convey.Convey("SelBatchRows", t, func(ctx convey.C) {
  147. var (
  148. c = context.Background()
  149. poolID = int(0)
  150. )
  151. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  152. _, err := d.SelBatchRows(c, poolID)
  153. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  154. ctx.So(err, convey.ShouldBeNil)
  155. })
  156. })
  157. })
  158. }
  159. func TestDaoAddBatch(t *testing.T) {
  160. convey.Convey("AddBatch", t, func(ctx convey.C) {
  161. var (
  162. c = context.Background()
  163. r = &model.ResouceBatchBo{}
  164. )
  165. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  166. a, err := d.AddBatch(c, r)
  167. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  168. ctx.So(err, convey.ShouldBeNil)
  169. ctx.So(a, convey.ShouldNotBeNil)
  170. })
  171. })
  172. })
  173. }
  174. func TestDaoUpdateBatch(t *testing.T) {
  175. convey.Convey("UpdateBatch", t, func(ctx convey.C) {
  176. var (
  177. c = context.Background()
  178. r = &model.VipResourceBatch{}
  179. ver = int(0)
  180. )
  181. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  182. a, err := d.UpdateBatch(c, r, ver)
  183. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  184. ctx.So(err, convey.ShouldBeNil)
  185. ctx.So(a, convey.ShouldNotBeNil)
  186. })
  187. })
  188. })
  189. }
  190. func TestDaoUseBatch(t *testing.T) {
  191. convey.Convey("UseBatch", t, func(ctx convey.C) {
  192. var (
  193. r = &model.VipResourceBatch{}
  194. ver = int(0)
  195. )
  196. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  197. tx, err := d.BeginTran(context.Background())
  198. ctx.So(err, convey.ShouldBeNil)
  199. ctx.So(tx, convey.ShouldNotBeNil)
  200. a, err := d.UseBatch(tx, r, ver)
  201. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  202. ctx.So(err, convey.ShouldBeNil)
  203. ctx.So(a, convey.ShouldNotBeNil)
  204. })
  205. })
  206. })
  207. }
  208. func TestDaoSelBusiness(t *testing.T) {
  209. convey.Convey("SelBusiness", t, func(ctx convey.C) {
  210. var (
  211. c = context.Background()
  212. id = int(0)
  213. )
  214. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  215. _, err := d.SelBusiness(c, id)
  216. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  217. ctx.So(err, convey.ShouldBeNil)
  218. })
  219. })
  220. })
  221. }
  222. func TestDaoSelBusinessByQuery(t *testing.T) {
  223. convey.Convey("SelBusinessByQuery", t, func(ctx convey.C) {
  224. var (
  225. c = context.Background()
  226. arg = &model.QueryBusinessInfo{}
  227. )
  228. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  229. r, err := d.SelBusinessByQuery(c, arg)
  230. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  231. ctx.So(err, convey.ShouldBeNil)
  232. ctx.So(r, convey.ShouldNotBeNil)
  233. })
  234. })
  235. })
  236. }
  237. func TestDaoAllVersion(t *testing.T) {
  238. convey.Convey("AllVersion", t, func(ctx convey.C) {
  239. var (
  240. c = context.Background()
  241. )
  242. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  243. res, err := d.AllVersion(c)
  244. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  245. ctx.So(err, convey.ShouldBeNil)
  246. ctx.So(res, convey.ShouldNotBeNil)
  247. })
  248. })
  249. })
  250. }
  251. func TestDaoUpdateVersion(t *testing.T) {
  252. convey.Convey("UpdateVersion", t, func(ctx convey.C) {
  253. var (
  254. c = context.Background()
  255. v = &model.VipAppVersion{}
  256. )
  257. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  258. ret, err := d.UpdateVersion(c, v)
  259. ctx.Convey("Then err should be nil.ret should not be nil.", func(ctx convey.C) {
  260. ctx.So(err, convey.ShouldBeNil)
  261. ctx.So(ret, convey.ShouldNotBeNil)
  262. })
  263. })
  264. })
  265. }
  266. func TestDaoBussinessList(t *testing.T) {
  267. convey.Convey("BussinessList", t, func(ctx convey.C) {
  268. var (
  269. c = context.Background()
  270. pn = int(0)
  271. ps = int(0)
  272. status = int(0)
  273. )
  274. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  275. _, err := d.BussinessList(c, pn, ps, status)
  276. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  277. ctx.So(err, convey.ShouldBeNil)
  278. })
  279. })
  280. })
  281. }
  282. func TestDaoBussinessCount(t *testing.T) {
  283. convey.Convey("BussinessCount", t, func(ctx convey.C) {
  284. var (
  285. c = context.Background()
  286. status = int(0)
  287. )
  288. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  289. count, err := d.BussinessCount(c, status)
  290. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  291. ctx.So(err, convey.ShouldBeNil)
  292. ctx.So(count, convey.ShouldNotBeNil)
  293. })
  294. })
  295. })
  296. }
  297. func TestDaoUpdateBusiness(t *testing.T) {
  298. convey.Convey("UpdateBusiness", t, func(ctx convey.C) {
  299. var (
  300. c = context.Background()
  301. r = &model.VipBusinessInfo{}
  302. )
  303. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  304. a, err := d.UpdateBusiness(c, r)
  305. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  306. ctx.So(err, convey.ShouldBeNil)
  307. ctx.So(a, convey.ShouldNotBeNil)
  308. })
  309. })
  310. })
  311. }
  312. func TestDaoAddBusiness(t *testing.T) {
  313. convey.Convey("AddBusiness", t, func(ctx convey.C) {
  314. var (
  315. c = context.Background()
  316. r = &model.VipBusinessInfo{
  317. AppKey: fmt.Sprintf("a:%d", time.Now().Unix()),
  318. }
  319. )
  320. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  321. a, err := d.AddBusiness(c, r)
  322. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  323. ctx.So(err, convey.ShouldBeNil)
  324. ctx.So(a, convey.ShouldNotBeNil)
  325. })
  326. })
  327. })
  328. }
  329. func TestDaoHistoryCount(t *testing.T) {
  330. convey.Convey("HistoryCount", t, func(ctx convey.C) {
  331. var (
  332. c = context.Background()
  333. u = &model.UserChangeHistoryReq{}
  334. )
  335. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  336. count, err := d.HistoryCount(c, u)
  337. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  338. ctx.So(err, convey.ShouldBeNil)
  339. ctx.So(count, convey.ShouldNotBeNil)
  340. })
  341. })
  342. })
  343. }
  344. func TestDaoHistoryList(t *testing.T) {
  345. convey.Convey("HistoryList", t, func(ctx convey.C) {
  346. var (
  347. c = context.Background()
  348. u = &model.UserChangeHistoryReq{}
  349. )
  350. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  351. res, err := d.HistoryList(c, u)
  352. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  353. ctx.So(err, convey.ShouldBeNil)
  354. ctx.So(res, convey.ShouldNotBeNil)
  355. })
  356. })
  357. })
  358. }