mysql_test.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "time"
  7. "go-common/app/service/main/spy/model"
  8. xtime "go-common/library/time"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestDaoService(t *testing.T) {
  12. convey.Convey("Service", t, func(ctx convey.C) {
  13. var (
  14. c = context.Background()
  15. serviceName = "account-service"
  16. )
  17. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  18. service, err := d.Service(c, serviceName)
  19. ctx.Convey("Then err should be nil.service should not be nil.", func(ctx convey.C) {
  20. ctx.So(err, convey.ShouldBeNil)
  21. ctx.So(service, convey.ShouldNotBeNil)
  22. })
  23. })
  24. })
  25. }
  26. func TestDaoEvent(t *testing.T) {
  27. convey.Convey("Event", t, func(ctx convey.C) {
  28. var (
  29. c = context.Background()
  30. eventName = "init_user_info"
  31. )
  32. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  33. _, err := d.Event(c, eventName)
  34. ctx.Convey("Then err should be nil.event should not be nil.", func(ctx convey.C) {
  35. ctx.So(err, convey.ShouldBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestDaoAddService(t *testing.T) {
  41. convey.Convey("AddService", t, func(ctx convey.C) {
  42. var (
  43. c = context.Background()
  44. service = &model.Service{
  45. Name: fmt.Sprintf("ut_%d", time.Now().Unix()),
  46. NickName: "test",
  47. Status: 0,
  48. CTime: xtime.Time(time.Now().Unix()),
  49. MTime: xtime.Time(time.Now().Unix()),
  50. }
  51. )
  52. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  53. id, err := d.AddService(c, service)
  54. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  55. ctx.So(err, convey.ShouldBeNil)
  56. ctx.So(id, convey.ShouldNotBeNil)
  57. })
  58. })
  59. })
  60. }
  61. func TestDaoAddEvent(t *testing.T) {
  62. convey.Convey("AddEvent", t, func(ctx convey.C) {
  63. var (
  64. c = context.Background()
  65. event = &model.Event{
  66. Name: fmt.Sprintf("ut_%d", time.Now().Unix()),
  67. NickName: "test",
  68. Status: 1,
  69. CTime: xtime.Time(time.Now().Unix()),
  70. MTime: xtime.Time(time.Now().Unix()),
  71. }
  72. )
  73. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  74. id, err := d.AddEvent(c, event)
  75. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  76. ctx.So(err, convey.ShouldBeNil)
  77. ctx.So(id, convey.ShouldNotBeNil)
  78. })
  79. })
  80. })
  81. }
  82. func TestDaoFactor(t *testing.T) {
  83. convey.Convey("Factor", t, func(ctx convey.C) {
  84. var (
  85. c = context.Background()
  86. serviceID = int64(1)
  87. eventID = int64(1)
  88. riskLevel = int8(1)
  89. )
  90. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  91. factor, err := d.Factor(c, serviceID, eventID, riskLevel)
  92. ctx.Convey("Then err should be nil.factor should not be nil.", func(ctx convey.C) {
  93. ctx.So(err, convey.ShouldBeNil)
  94. ctx.So(factor, convey.ShouldNotBeNil)
  95. })
  96. })
  97. })
  98. }
  99. func TestDaoFactorGroup(t *testing.T) {
  100. convey.Convey("FactorGroup", t, func(ctx convey.C) {
  101. var (
  102. c = context.Background()
  103. groupName = "基础资料分值"
  104. )
  105. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  106. _, err := d.FactorGroup(c, groupName)
  107. ctx.Convey("Then err should be nil.factorGroup should not be nil.", func(ctx convey.C) {
  108. ctx.So(err, convey.ShouldBeNil)
  109. })
  110. })
  111. })
  112. }
  113. func TestDaohitInfo(t *testing.T) {
  114. convey.Convey("hitInfo", t, func(ctx convey.C) {
  115. var (
  116. id = int64(0)
  117. )
  118. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  119. p1 := hitInfo(id)
  120. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  121. ctx.So(p1, convey.ShouldNotBeNil)
  122. })
  123. })
  124. })
  125. }
  126. func TestDaohitHistory(t *testing.T) {
  127. convey.Convey("hitHistory", t, func(ctx convey.C) {
  128. var (
  129. id = int64(0)
  130. )
  131. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  132. p1 := hitHistory(id)
  133. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  134. ctx.So(p1, convey.ShouldNotBeNil)
  135. })
  136. })
  137. })
  138. }
  139. func TestDaoBeginTran(t *testing.T) {
  140. convey.Convey("BeginTran", t, func(ctx convey.C) {
  141. var (
  142. c = context.Background()
  143. )
  144. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  145. p1, err := d.BeginTran(c)
  146. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  147. ctx.So(err, convey.ShouldBeNil)
  148. ctx.So(p1, convey.ShouldNotBeNil)
  149. })
  150. })
  151. })
  152. }
  153. func TestDaoUserInfo(t *testing.T) {
  154. convey.Convey("UserInfo", t, func(ctx convey.C) {
  155. var (
  156. c = context.Background()
  157. mid = int64(1)
  158. )
  159. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  160. res, err := d.UserInfo(c, mid)
  161. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  162. ctx.So(err, convey.ShouldBeNil)
  163. ctx.So(res, convey.ShouldNotBeNil)
  164. })
  165. })
  166. })
  167. }
  168. func TestDaoTxUpdateInfo(t *testing.T) {
  169. convey.Convey("TxUpdateInfo", t, func(ctx convey.C) {
  170. var (
  171. c = context.Background()
  172. info = &model.UserInfo{
  173. Mid: 1,
  174. }
  175. )
  176. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  177. tx, err := d.BeginTran(c)
  178. ctx.So(err, convey.ShouldBeNil)
  179. err = d.TxUpdateInfo(c, tx, info)
  180. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  181. ctx.So(err, convey.ShouldBeNil)
  182. })
  183. })
  184. })
  185. }
  186. func TestDaoTxAddInfo(t *testing.T) {
  187. convey.Convey("TxAddInfo", t, func(ctx convey.C) {
  188. var (
  189. c = context.Background()
  190. info = &model.UserInfo{
  191. Mid: time.Now().Unix(),
  192. }
  193. id int64
  194. )
  195. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  196. tx, err := d.BeginTran(c)
  197. ctx.So(err, convey.ShouldBeNil)
  198. id, err = d.TxAddInfo(c, tx, info)
  199. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  200. ctx.So(err, convey.ShouldBeNil)
  201. ctx.So(id, convey.ShouldNotBeNil)
  202. })
  203. })
  204. })
  205. }
  206. func TestDaoTxAddEventHistory(t *testing.T) {
  207. convey.Convey("TxAddEventHistory", t, func(ctx convey.C) {
  208. var (
  209. c = context.Background()
  210. ueh = &model.UserEventHistory{
  211. Mid: 1,
  212. Remark: "un_test",
  213. }
  214. )
  215. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  216. tx, err := d.BeginTran(c)
  217. ctx.So(err, convey.ShouldBeNil)
  218. err = d.TxAddEventHistory(c, tx, ueh)
  219. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  220. ctx.So(err, convey.ShouldBeNil)
  221. })
  222. })
  223. })
  224. }
  225. func TestDaoTxAddPunishment(t *testing.T) {
  226. convey.Convey("TxAddPunishment", t, func(ctx convey.C) {
  227. var (
  228. c = context.Background()
  229. mid = int64(1)
  230. no = int8(0)
  231. reason = "unit test"
  232. )
  233. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  234. tx, err := d.BeginTran(c)
  235. ctx.So(err, convey.ShouldBeNil)
  236. err = d.TxAddPunishment(c, tx, mid, no, reason)
  237. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  238. ctx.So(err, convey.ShouldBeNil)
  239. })
  240. })
  241. })
  242. }
  243. func TestDaoTxAddPunishmentQueue(t *testing.T) {
  244. convey.Convey("TxAddPunishmentQueue", t, func(ctx convey.C) {
  245. var (
  246. c = context.Background()
  247. mid = int64(1)
  248. blockNo = int64(1)
  249. )
  250. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  251. tx, err := d.BeginTran(c)
  252. ctx.So(err, convey.ShouldBeNil)
  253. err = d.TxAddPunishmentQueue(c, tx, mid, blockNo)
  254. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  255. ctx.So(err, convey.ShouldBeNil)
  256. })
  257. })
  258. })
  259. }
  260. func TestDaoAddPunishmentQueue(t *testing.T) {
  261. convey.Convey("AddPunishmentQueue", t, func(ctx convey.C) {
  262. var (
  263. c = context.Background()
  264. mid = int64(1)
  265. blockNo = int64(0)
  266. )
  267. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  268. err := d.AddPunishmentQueue(c, mid, blockNo)
  269. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  270. ctx.So(err, convey.ShouldBeNil)
  271. })
  272. })
  273. })
  274. }
  275. func TestDaoTxUpdateEventScore(t *testing.T) {
  276. convey.Convey("TxUpdateEventScore", t, func(ctx convey.C) {
  277. var (
  278. c = context.Background()
  279. mid = int64(0)
  280. escore = int8(0)
  281. score = int8(0)
  282. )
  283. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  284. tx, err := d.BeginTran(c)
  285. ctx.So(err, convey.ShouldBeNil)
  286. err = d.TxUpdateEventScore(c, tx, mid, escore, score)
  287. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  288. ctx.So(err, convey.ShouldBeNil)
  289. })
  290. })
  291. })
  292. }
  293. func TestDaoTxUpdateBaseScore(t *testing.T) {
  294. convey.Convey("TxUpdateBaseScore", t, func(ctx convey.C) {
  295. var (
  296. c = context.Background()
  297. ui = &model.UserInfo{Mid: 1}
  298. )
  299. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  300. tx, err := d.BeginTran(c)
  301. ctx.So(err, convey.ShouldBeNil)
  302. err = d.TxUpdateBaseScore(c, tx, ui)
  303. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  304. ctx.So(err, convey.ShouldBeNil)
  305. })
  306. })
  307. })
  308. }
  309. func TestDaoTxClearReliveTimes(t *testing.T) {
  310. convey.Convey("TxClearReliveTimes", t, func(ctx convey.C) {
  311. var (
  312. c = context.Background()
  313. ui = &model.UserInfo{Mid: 1}
  314. )
  315. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  316. tx, err := d.BeginTran(c)
  317. ctx.So(err, convey.ShouldBeNil)
  318. err = d.TxClearReliveTimes(c, tx, ui)
  319. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  320. ctx.So(err, convey.ShouldBeNil)
  321. })
  322. })
  323. })
  324. }
  325. func TestDaoConfigs(t *testing.T) {
  326. convey.Convey("Configs", t, func(ctx convey.C) {
  327. var (
  328. c = context.Background()
  329. )
  330. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  331. res, err := d.Configs(c)
  332. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  333. ctx.So(err, convey.ShouldBeNil)
  334. ctx.So(res, convey.ShouldNotBeNil)
  335. })
  336. })
  337. })
  338. }
  339. func TestDaoHistoryList(t *testing.T) {
  340. convey.Convey("HistoryList", t, func(ctx convey.C) {
  341. var (
  342. c = context.Background()
  343. mid = int64(1)
  344. size = int(10)
  345. )
  346. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  347. res, err := d.HistoryList(c, mid, size)
  348. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  349. ctx.So(err, convey.ShouldBeNil)
  350. ctx.So(res, convey.ShouldNotBeNil)
  351. })
  352. })
  353. })
  354. }
  355. func TestDaoTxUpdateEventScoreReLive(t *testing.T) {
  356. convey.Convey("TxUpdateEventScoreReLive", t, func(ctx convey.C) {
  357. var (
  358. c = context.Background()
  359. mid = int64(1)
  360. escore = int8(0)
  361. score = int8(0)
  362. )
  363. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  364. tx, err := d.BeginTran(c)
  365. ctx.So(err, convey.ShouldBeNil)
  366. err = d.TxUpdateEventScoreReLive(c, tx, mid, escore, score)
  367. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  368. ctx.So(err, convey.ShouldBeNil)
  369. })
  370. })
  371. })
  372. }
  373. func TestDaoStatListByMid(t *testing.T) {
  374. convey.Convey("StatListByMid", t, func(ctx convey.C) {
  375. var (
  376. c = context.Background()
  377. mid = int64(1)
  378. )
  379. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  380. list, err := d.StatListByMid(c, mid)
  381. ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
  382. ctx.So(err, convey.ShouldBeNil)
  383. ctx.So(list, convey.ShouldNotBeNil)
  384. })
  385. })
  386. })
  387. }
  388. func TestDaoStatListByIDAndMid(t *testing.T) {
  389. convey.Convey("StatListByIDAndMid", t, func(ctx convey.C) {
  390. var (
  391. c = context.Background()
  392. mid = int64(1)
  393. id = int64(0)
  394. )
  395. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  396. list, err := d.StatListByIDAndMid(c, mid, id)
  397. ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
  398. ctx.So(err, convey.ShouldBeNil)
  399. ctx.So(list, convey.ShouldNotBeNil)
  400. })
  401. })
  402. })
  403. }
  404. func TestDaoStatListByID(t *testing.T) {
  405. convey.Convey("StatListByID", t, func(ctx convey.C) {
  406. var (
  407. c = context.Background()
  408. id = int64(0)
  409. )
  410. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  411. list, err := d.StatListByID(c, id)
  412. ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
  413. ctx.So(err, convey.ShouldBeNil)
  414. ctx.So(list, convey.ShouldNotBeNil)
  415. })
  416. })
  417. })
  418. }
  419. func TestDaoAllEvent(t *testing.T) {
  420. convey.Convey("AllEvent", t, func(ctx convey.C) {
  421. var (
  422. c = context.Background()
  423. )
  424. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  425. list, err := d.AllEvent(c)
  426. ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
  427. ctx.So(err, convey.ShouldBeNil)
  428. ctx.So(list, convey.ShouldNotBeNil)
  429. })
  430. })
  431. })
  432. }
  433. func TestDaoTelLevel(t *testing.T) {
  434. convey.Convey("TelLevel", t, func(ctx convey.C) {
  435. var (
  436. c = context.Background()
  437. mid = int64(1)
  438. )
  439. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  440. _, err := d.TelLevel(c, mid)
  441. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  442. ctx.So(err, convey.ShouldBeNil)
  443. })
  444. })
  445. })
  446. }
  447. func TestDaoAddTelLevelInfo(t *testing.T) {
  448. convey.Convey("AddTelLevelInfo", t, func(ctx convey.C) {
  449. var (
  450. c = context.Background()
  451. no = &model.TelRiskLevel{
  452. Mid: time.Now().Unix(),
  453. Level: 1,
  454. Origin: 1,
  455. Ctime: time.Now(),
  456. Mtime: time.Now(),
  457. }
  458. )
  459. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  460. id, err := d.AddTelLevelInfo(c, no)
  461. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  462. ctx.So(err, convey.ShouldBeNil)
  463. ctx.So(id, convey.ShouldNotBeNil)
  464. })
  465. })
  466. })
  467. }