mysql_test.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/account-recovery/model"
  6. xtime "go-common/library/time"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoGetStatusByRid(t *testing.T) {
  10. var (
  11. c = context.Background()
  12. rid = int64(1)
  13. )
  14. convey.Convey("GetStatusByRid", t, func(ctx convey.C) {
  15. status, err := d.GetStatusByRid(c, rid)
  16. ctx.Convey("Then err should be nil.status should not be nil.", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. ctx.So(status, convey.ShouldNotBeNil)
  19. })
  20. })
  21. }
  22. func TestDaoGetSuccessCount(t *testing.T) {
  23. var (
  24. c = context.Background()
  25. mid = int64(1234)
  26. )
  27. convey.Convey("GetSuccessCount", t, func(ctx convey.C) {
  28. count, err := d.GetSuccessCount(c, mid)
  29. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  30. ctx.So(err, convey.ShouldBeNil)
  31. ctx.So(count, convey.ShouldNotBeNil)
  32. })
  33. })
  34. }
  35. func TestDaoBatchGetRecoverySuccess(t *testing.T) {
  36. var (
  37. c = context.Background()
  38. mids = []int64{1234}
  39. )
  40. convey.Convey("BatchGetRecoverySuccess", t, func(ctx convey.C) {
  41. countMap, err := d.BatchGetRecoverySuccess(c, mids)
  42. ctx.Convey("Then err should be nil.countMap should not be nil.", func(ctx convey.C) {
  43. ctx.So(err, convey.ShouldBeNil)
  44. ctx.So(countMap, convey.ShouldNotBeNil)
  45. })
  46. })
  47. }
  48. func TestDaoUpdateSuccessCount(t *testing.T) {
  49. var (
  50. c = context.Background()
  51. mid = int64(1234)
  52. )
  53. convey.Convey("UpdateSuccessCount", t, func(ctx convey.C) {
  54. err := d.UpdateSuccessCount(c, mid)
  55. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  56. ctx.So(err, convey.ShouldBeNil)
  57. })
  58. })
  59. }
  60. func TestDaoBatchUpdateSuccessCount(t *testing.T) {
  61. var (
  62. c = context.Background()
  63. mids = "1234"
  64. )
  65. convey.Convey("BatchUpdateSuccessCount", t, func(ctx convey.C) {
  66. err := d.BatchUpdateSuccessCount(c, mids)
  67. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  68. ctx.So(err, convey.ShouldBeNil)
  69. })
  70. })
  71. }
  72. func TestDaoGetNoDeal(t *testing.T) {
  73. var (
  74. c = context.Background()
  75. mid = int64(1234)
  76. )
  77. convey.Convey("GetNoDeal", t, func(ctx convey.C) {
  78. count, err := d.GetNoDeal(c, mid)
  79. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  80. ctx.So(err, convey.ShouldBeNil)
  81. ctx.So(count, convey.ShouldNotBeNil)
  82. })
  83. })
  84. }
  85. func TestDaoUpdateStatus(t *testing.T) {
  86. var (
  87. c = context.Background()
  88. status = int64(1)
  89. rid = int64(1)
  90. operator = "abcd"
  91. optTime xtime.Time
  92. remark = ""
  93. )
  94. convey.Convey("UpdateStatus", t, func(ctx convey.C) {
  95. err := d.UpdateStatus(c, status, rid, operator, optTime, remark)
  96. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  97. ctx.So(err, convey.ShouldBeNil)
  98. })
  99. })
  100. }
  101. func TestDaoUpdateUserType(t *testing.T) {
  102. var (
  103. c = context.Background()
  104. status = int64(1)
  105. rid = int64(1)
  106. )
  107. convey.Convey("UpdateUserType", t, func(ctx convey.C) {
  108. err := d.UpdateUserType(c, status, rid)
  109. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  110. ctx.So(err, convey.ShouldBeNil)
  111. })
  112. })
  113. }
  114. func TestDaoInsertRecoveryInfo(t *testing.T) {
  115. var (
  116. c = context.Background()
  117. uinfo = &model.UserInfoReq{
  118. LoginAddrs: "中国-福州,中国-上海,澳大利亚",
  119. //RegTime:timeS, //变成2018
  120. RegTime: 1533206284, //变成2018 //数据库设置为int(11),so数据库必须设置为tiimestamp
  121. RegType: int8(1),
  122. RegAddr: "中国上海",
  123. Unames: "昵称AA,昵称BB,昵称CC",
  124. Pwds: "密码1,密码2",
  125. Phones: "12345678901,54321678923",
  126. Emails: "2456@sina.com,789@qq.com",
  127. SafeQuestion: int8(1),
  128. SafeAnswer: "心态呀",
  129. CardID: "ISN-1234567890-0987",
  130. CardType: int8(1),
  131. LinkMail: "345678@qq.com",
  132. Mid: 1234,
  133. }
  134. )
  135. convey.Convey("InsertRecoveryInfo", t, func(ctx convey.C) {
  136. lastID, err := d.InsertRecoveryInfo(c, uinfo)
  137. ctx.Convey("Then err should be nil.lastID should not be nil.", func(ctx convey.C) {
  138. ctx.So(err, convey.ShouldBeNil)
  139. ctx.So(lastID, convey.ShouldNotBeNil)
  140. })
  141. })
  142. }
  143. func TestDaoUpdateSysInfo(t *testing.T) {
  144. var (
  145. c = context.Background()
  146. sys = &model.SysInfo{
  147. SysLoginAddrs: "中国-福州,中国-上海,澳大利亚",
  148. SysReg: "对",
  149. SysUNames: "对,错,错",
  150. SysPwds: "对,错",
  151. SysPhones: "对,错",
  152. SysEmails: "对,错",
  153. SysSafe: "对",
  154. SysCard: "对",
  155. }
  156. userType = int64(1)
  157. rid = int64(1)
  158. )
  159. convey.Convey("UpdateSysInfo", t, func(ctx convey.C) {
  160. err := d.UpdateSysInfo(c, sys, userType, rid)
  161. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  162. ctx.So(err, convey.ShouldBeNil)
  163. })
  164. })
  165. }
  166. func TestDaoQueryByID(t *testing.T) {
  167. var (
  168. c = context.Background()
  169. rid = int64(1)
  170. fromTime xtime.Time = 1533120949
  171. endTime xtime.Time = 1535636392
  172. )
  173. convey.Convey("QueryByID", t, func(ctx convey.C) {
  174. res, err := d.QueryByID(c, rid, fromTime, endTime)
  175. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  176. ctx.So(err, convey.ShouldBeNil)
  177. ctx.So(res, convey.ShouldNotBeNil)
  178. })
  179. })
  180. }
  181. func TestDaoQueryInfoByLimit(t *testing.T) {
  182. var (
  183. c = context.Background()
  184. req = &model.DBRecoveryInfoParams{
  185. ExistGame: false,
  186. ExistStatus: false,
  187. ExistMid: false,
  188. Mid: 0,
  189. Game: 0,
  190. Status: 1,
  191. FirstRid: 20,
  192. LastRid: 0,
  193. Size: 2,
  194. StartTime: 1533120949,
  195. EndTime: 1535636392,
  196. SubNum: 1,
  197. CurrPage: 1,
  198. }
  199. )
  200. convey.Convey("QueryInfoByLimit", t, func(ctx convey.C) {
  201. res, total, err := d.QueryInfoByLimit(c, req)
  202. ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
  203. ctx.So(err, convey.ShouldBeNil)
  204. ctx.So(total, convey.ShouldNotBeNil)
  205. ctx.So(res, convey.ShouldNotBeNil)
  206. })
  207. })
  208. }
  209. func TestDaoGetUinfoByRid(t *testing.T) {
  210. var (
  211. c = context.Background()
  212. rid = int64(240)
  213. )
  214. convey.Convey("GetUinfoByRid", t, func(ctx convey.C) {
  215. mid, linkMail, ctime, err := d.GetUinfoByRid(c, rid)
  216. ctx.Convey("Then err should be nil.mid,linkMail,ctime should not be nil.", func(ctx convey.C) {
  217. ctx.So(err, convey.ShouldBeNil)
  218. ctx.So(ctime, convey.ShouldNotBeNil)
  219. ctx.So(linkMail, convey.ShouldNotBeNil)
  220. ctx.So(mid, convey.ShouldNotBeNil)
  221. })
  222. })
  223. }
  224. func TestDaoGetUinfoByRidMore(t *testing.T) {
  225. var (
  226. c = context.Background()
  227. ridsStr = "1,2"
  228. )
  229. convey.Convey("GetUinfoByRidMore", t, func(ctx convey.C) {
  230. bathRes, err := d.GetUinfoByRidMore(c, ridsStr)
  231. ctx.Convey("Then err should be nil.bathRes should not be nil.", func(ctx convey.C) {
  232. ctx.So(err, convey.ShouldBeNil)
  233. ctx.So(bathRes, convey.ShouldNotBeNil)
  234. })
  235. })
  236. }
  237. func TestDaoGetUnCheckInfo(t *testing.T) {
  238. var (
  239. c = context.Background()
  240. rid = int64(1)
  241. )
  242. convey.Convey("GetUnCheckInfo", t, func(ctx convey.C) {
  243. r, err := d.GetUnCheckInfo(c, rid)
  244. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  245. ctx.So(err, convey.ShouldBeNil)
  246. ctx.So(r, convey.ShouldNotBeNil)
  247. })
  248. })
  249. }
  250. func TestDaoGetMailStatus(t *testing.T) {
  251. var (
  252. c = context.Background()
  253. rid = int64(1)
  254. )
  255. convey.Convey("GetMailStatus", t, func(ctx convey.C) {
  256. mailStatus, err := d.GetMailStatus(c, rid)
  257. ctx.Convey("Then err should be nil.mailStatus should not be nil.", func(ctx convey.C) {
  258. ctx.So(err, convey.ShouldBeNil)
  259. ctx.So(mailStatus, convey.ShouldNotBeNil)
  260. })
  261. })
  262. }
  263. func TestDaoUpdateMailStatus(t *testing.T) {
  264. var (
  265. c = context.Background()
  266. rid = int64(1)
  267. )
  268. convey.Convey("UpdateMailStatus", t, func(ctx convey.C) {
  269. err := d.UpdateMailStatus(c, rid)
  270. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  271. ctx.So(err, convey.ShouldBeNil)
  272. })
  273. })
  274. }
  275. func TestDaoGetAllByCon(t *testing.T) {
  276. var (
  277. defint int64
  278. c = context.Background()
  279. aq = &model.QueryRecoveryInfoReq{
  280. //RID: 1,
  281. //UID:2,
  282. Status: &defint,
  283. Game: &defint,
  284. Size: 10,
  285. Page: 1,
  286. StartTime: 1533052800,
  287. EndTime: 1536924163,
  288. //StartTime time.Time `json:"start_time" form:"start_time"`
  289. //EndTime time.Time `json:"end_time" form:"end_time"`
  290. //IsAdvanced bool `json:"-"`
  291. //Page int64 `form:"page"`
  292. }
  293. )
  294. convey.Convey("UpdateMailStatus", t, func(ctx convey.C) {
  295. resultData, total, err := d.GetAllByCon(c, aq)
  296. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  297. ctx.So(resultData, convey.ShouldNotBeNil)
  298. ctx.So(total, convey.ShouldNotBeNil)
  299. ctx.So(err, convey.ShouldBeNil)
  300. ctx.Println(total, " len=", len(resultData))
  301. })
  302. })
  303. }
  304. func TestDaoInsertRecoveryAddit(t *testing.T) {
  305. var (
  306. c = context.Background()
  307. rid int64 = 1
  308. files = "http://uat-i0.hdslb.com/bfs/account/recovery/bca2.zip,http://uat-i0.hdslb.com/bfs/account/recovery/abcd.zip"
  309. extra = `{"GameArea":"ios-A服","GameNames":"崩坏3","GamePlay":"1"}`
  310. )
  311. convey.Convey("InsertRecoveryAddit", t, func(ctx convey.C) {
  312. err := d.InsertRecoveryAddit(c, rid, files, extra)
  313. err = d.InsertRecoveryAddit(c, 2, files, extra)
  314. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  315. ctx.So(err, convey.ShouldBeNil)
  316. })
  317. })
  318. }
  319. func TestDaoUpdateRecoveryAddit(t *testing.T) {
  320. var (
  321. c = context.Background()
  322. rid int64 = 1
  323. files = []string{"http://uat-i0.hdslb.com/bfs/aaaa.zip", "http://uat-i0.hdslb.com/bfs/dddd.zip"}
  324. extra = `{"GameArea":"ios-A服","GameNames":"崩坏3","GamePlay":"1"}`
  325. )
  326. convey.Convey("UpdateMailStatus", t, func(ctx convey.C) {
  327. err := d.UpdateRecoveryAddit(c, rid, files, extra)
  328. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  329. ctx.So(err, convey.ShouldBeNil)
  330. })
  331. })
  332. }
  333. func TestDaoGetRecoveryAddit(t *testing.T) {
  334. var (
  335. c = context.Background()
  336. rid int64 = 1
  337. )
  338. convey.Convey("UpdateMailStatus", t, func(ctx convey.C) {
  339. addit, err := d.GetRecoveryAddit(c, rid)
  340. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  341. ctx.So(err, convey.ShouldBeNil)
  342. ctx.Println(addit, convey.ShouldNotBeNil)
  343. })
  344. })
  345. }
  346. func TestDaoBatchGetRecoveryAddit(t *testing.T) {
  347. var (
  348. c = context.Background()
  349. rids = []int64{1, 2}
  350. )
  351. convey.Convey("BatchGetRecoveryAddit", t, func(ctx convey.C) {
  352. addits, err := d.BatchGetRecoveryAddit(c, rids)
  353. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  354. ctx.So(err, convey.ShouldBeNil)
  355. ctx.So(addits, convey.ShouldNotBeNil)
  356. })
  357. })
  358. }
  359. func TestBatchGetLastSuccess(t *testing.T) {
  360. var (
  361. c = context.Background()
  362. mids = []int64{1234}
  363. )
  364. convey.Convey("BatchGetLastSuccess", t, func(ctx convey.C) {
  365. lastSuccessMap, err := d.BatchGetLastSuccess(c, mids)
  366. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  367. ctx.So(err, convey.ShouldBeNil)
  368. ctx.So(lastSuccessMap, convey.ShouldNotBeNil)
  369. })
  370. })
  371. }
  372. func TestDaoGetLastSuccess(t *testing.T) {
  373. var (
  374. c = context.Background()
  375. mid = int64(1234)
  376. )
  377. convey.Convey("GetLastSuccess", t, func(ctx convey.C) {
  378. res, err := d.GetLastSuccess(c, mid)
  379. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  380. ctx.So(err, convey.ShouldBeNil)
  381. ctx.So(res, convey.ShouldNotBeNil)
  382. })
  383. })
  384. }