mysql_test.go 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "testing"
  8. "go-common/app/service/main/ugcpay/model"
  9. xsql "go-common/library/database/sql"
  10. "github.com/smartystreets/goconvey/convey"
  11. )
  12. func TestDaoBeginTran(t *testing.T) {
  13. convey.Convey("BeginTran", t, func(ctx convey.C) {
  14. var (
  15. c = context.Background()
  16. )
  17. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  18. tx, err := d.BeginTran(c)
  19. ctx.Convey("Then err should be nil.tx should not be nil.", func(ctx convey.C) {
  20. ctx.So(err, convey.ShouldBeNil)
  21. ctx.So(tx, convey.ShouldNotBeNil)
  22. })
  23. })
  24. })
  25. }
  26. func TestDaoRawOrderUser(t *testing.T) {
  27. convey.Convey("RawOrderUser", t, func(ctx convey.C) {
  28. var (
  29. c = context.Background()
  30. id = ""
  31. )
  32. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  33. data, err := d.RawOrderUser(c, id)
  34. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  35. ctx.So(err, convey.ShouldBeNil)
  36. ctx.So(data, convey.ShouldNotBeNil)
  37. })
  38. })
  39. })
  40. }
  41. func TestDaoInsertOrderUser(t *testing.T) {
  42. convey.Convey("InsertOrderUser", t, func(ctx convey.C) {
  43. var (
  44. c = context.Background()
  45. data = &model.Order{
  46. OrderID: strconv.FormatInt(time.Now().Unix(), 10),
  47. MID: 35858,
  48. Biz: "asset",
  49. Platform: "ios",
  50. OID: 2333,
  51. OType: "archive",
  52. Fee: 1300,
  53. Currency: "bp",
  54. State: "created",
  55. }
  56. )
  57. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  58. id, err := d.InsertOrderUser(c, data)
  59. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  60. ctx.So(err, convey.ShouldBeNil)
  61. ctx.So(id, convey.ShouldNotBeNil)
  62. })
  63. })
  64. })
  65. }
  66. func TestDaoRawAsset(t *testing.T) {
  67. convey.Convey("RawAsset", t, func(ctx convey.C) {
  68. var (
  69. c = context.Background()
  70. oid = int64(2333)
  71. otype = "archive"
  72. currency = "bp"
  73. )
  74. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  75. data, err := d.RawAsset(c, oid, otype, currency)
  76. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. ctx.So(data, convey.ShouldNotBeNil)
  79. })
  80. })
  81. })
  82. }
  83. func TestDaoUpsertAsset(t *testing.T) {
  84. convey.Convey("UpsertAsset", t, func(ctx convey.C) {
  85. var (
  86. c = context.Background()
  87. data = &model.Asset{
  88. MID: 46333,
  89. OID: 2333,
  90. OType: "archive",
  91. Currency: "bp",
  92. Price: 1000,
  93. State: "valid",
  94. }
  95. )
  96. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  97. err := d.UpsertAsset(c, data)
  98. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  99. ctx.So(err, convey.ShouldBeNil)
  100. })
  101. })
  102. })
  103. }
  104. func TestDaoRawAssetRelation(t *testing.T) {
  105. convey.Convey("RawAssetRelation", t, func(ctx convey.C) {
  106. var (
  107. c = context.Background()
  108. mid = int64(35858)
  109. oid = int64(2333)
  110. otype = "archive"
  111. )
  112. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  113. data, err := d.RawAssetRelation(c, mid, oid, otype)
  114. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  115. ctx.So(err, convey.ShouldBeNil)
  116. ctx.So(data, convey.ShouldNotBeNil)
  117. })
  118. })
  119. })
  120. }
  121. func TestDaoUpsertAssetRelation(t *testing.T) {
  122. convey.Convey("UpsertAssetRelation", t, func(ctx convey.C) {
  123. var (
  124. c = context.Background()
  125. data = &model.AssetRelation{
  126. OID: 2333,
  127. OType: "archive",
  128. MID: 35858,
  129. State: "paid",
  130. }
  131. )
  132. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  133. _, err := d.UpsertAssetRelation(c, data)
  134. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  135. ctx.So(err, convey.ShouldBeNil)
  136. })
  137. })
  138. })
  139. }
  140. func TestDaoRawAggrIncomeUser(t *testing.T) {
  141. convey.Convey("RawAggrIncomeUser", t, func(ctx convey.C) {
  142. var (
  143. c = context.Background()
  144. mid = int64(46333)
  145. cur = "bp"
  146. )
  147. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  148. data, err := d.RawAggrIncomeUser(c, mid, cur)
  149. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  150. ctx.So(err, convey.ShouldBeNil)
  151. ctx.So(data, convey.ShouldNotBeNil)
  152. })
  153. })
  154. })
  155. }
  156. func TestDaoRawAggrIncomeUserMonthly(t *testing.T) {
  157. convey.Convey("RawAggrIncomeUserMonthly", t, func(ctx convey.C) {
  158. var (
  159. c = context.Background()
  160. mid = int64(46333)
  161. cur = "bp"
  162. ver = int64(201809)
  163. )
  164. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  165. data, err := d.RawAggrIncomeUserAssetList(c, mid, cur, ver, 1000)
  166. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  167. ctx.So(err, convey.ShouldBeNil)
  168. ctx.So(data, convey.ShouldNotBeNil)
  169. })
  170. })
  171. })
  172. }
  173. func TestDaoRawAggrIncomeUserAsset(t *testing.T) {
  174. convey.Convey("RawAggrIncomeUserAsset", t, func(ctx convey.C) {
  175. var (
  176. c = context.Background()
  177. mid = int64(46333)
  178. cur = "bp"
  179. ver = int64(201809)
  180. oid = int64(10110842)
  181. otype = "archive"
  182. )
  183. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  184. data, err := d.RawAggrIncomeUserAsset(c, mid, cur, oid, otype, ver)
  185. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  186. ctx.So(err, convey.ShouldBeNil)
  187. ctx.So(data, convey.ShouldNotBeNil)
  188. })
  189. })
  190. })
  191. }
  192. func TestDaoRawBillUserDaily(t *testing.T) {
  193. convey.Convey("RawBillUserDaily", t, func(ctx convey.C) {
  194. var (
  195. c = context.Background()
  196. mid = int64(46333)
  197. biz = "asset"
  198. cur = "bp"
  199. ver = int64(20181030)
  200. )
  201. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  202. data, err := d.RawBillUserDaily(c, mid, biz, cur, ver)
  203. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  204. ctx.So(err, convey.ShouldBeNil)
  205. ctx.So(data, convey.ShouldNotBeNil)
  206. t.Log(data)
  207. })
  208. })
  209. })
  210. }
  211. func TestDaoRawBillUserDailyListByMonthVer(t *testing.T) {
  212. convey.Convey("RawBillUserDailyListByMonthVer", t, func(ctx convey.C) {
  213. var (
  214. c = context.Background()
  215. mid = int64(46333)
  216. biz = "asset"
  217. cur = "bp"
  218. ver = int64(201811)
  219. )
  220. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  221. datas, err := d.RawBillUserDailyByMonthVer(c, mid, biz, cur, ver)
  222. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  223. ctx.So(err, convey.ShouldBeNil)
  224. ctx.So(datas, convey.ShouldNotBeNil)
  225. })
  226. })
  227. })
  228. }
  229. func TestDaoTXInsertOrderUserLog(t *testing.T) {
  230. convey.Convey("TestDaoTXInsertOrderUserLog", t, func(ctx convey.C) {
  231. var (
  232. c = context.Background()
  233. log = &model.LogOrder{
  234. OrderID: "test",
  235. FromState: "ut1",
  236. ToState: "ut2",
  237. Desc: "hahah",
  238. }
  239. tx *xsql.Tx
  240. )
  241. tx, err := d.BeginTran(c)
  242. convey.So(err, convey.ShouldBeNil)
  243. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  244. id, err := d.TXInsertOrderUserLog(c, tx, log)
  245. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  246. ctx.So(err, convey.ShouldBeNil)
  247. ctx.So(id, convey.ShouldBeGreaterThan, 0)
  248. })
  249. })
  250. })
  251. }
  252. func TestDaoOrderRechargeShell(t *testing.T) {
  253. convey.Convey("TestDaoOrderRechargeShell", t, func(ctx convey.C) {
  254. var (
  255. c = context.Background()
  256. orderID = "23656019181109210220"
  257. )
  258. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  259. data, err := d.RawOrderRechargeShell(c, orderID)
  260. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  261. ctx.So(err, convey.ShouldBeNil)
  262. ctx.So(data, convey.ShouldNotBeNil)
  263. })
  264. })
  265. })
  266. }
  267. func TestDaoTXUpdateOrderRechargeShell(t *testing.T) {
  268. convey.Convey("TestDaoTXOrderRechargeShell", t, func(ctx convey.C) {
  269. var (
  270. c = context.Background()
  271. data = &model.OrderRechargeShell{
  272. MID: 46333,
  273. OrderID: "123",
  274. Biz: "asset",
  275. Amount: 1,
  276. PayMSG: "ut test",
  277. State: "test",
  278. Ver: 201811,
  279. }
  280. )
  281. tx, err := d.BeginTran(c)
  282. convey.So(err, convey.ShouldBeNil)
  283. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  284. err := d.TXUpdateOrderRechargeShell(c, tx, data)
  285. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  286. ctx.So(err, convey.ShouldBeNil)
  287. })
  288. })
  289. })
  290. }
  291. func TestDaoTXInsertOrderRechargeShellLog(t *testing.T) {
  292. convey.Convey("TestDaoTXInsertOrderRechargeShellLog", t, func(ctx convey.C) {
  293. var (
  294. c = context.Background()
  295. data = &model.OrderRechargeShellLog{
  296. OrderID: "233",
  297. FromState: "ut1",
  298. ToState: "ut2",
  299. Desc: "ut test",
  300. BillUserMonthlyID: fmt.Sprintf("ut_%d", time.Now().Unix()),
  301. }
  302. )
  303. tx, err := d.BeginTran(c)
  304. convey.So(err, convey.ShouldBeNil)
  305. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  306. id, err := d.TXInsertOrderRechargeShellLog(c, tx, data)
  307. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  308. ctx.So(err, convey.ShouldBeNil)
  309. ctx.So(id, convey.ShouldBeGreaterThan, 0)
  310. })
  311. })
  312. })
  313. }
  314. func TestDaoTXUpdateOrderUser(t *testing.T) {
  315. convey.Convey("TXUpdateOrderUser", t, func(ctx convey.C) {
  316. var (
  317. c = context.Background()
  318. tx, _ = d.BeginTran(c)
  319. data = &model.Order{
  320. OrderID: "96841175181102170810",
  321. State: "ut test",
  322. }
  323. )
  324. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  325. _, err := d.TXUpdateOrderUser(c, tx, data)
  326. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  327. ctx.So(err, convey.ShouldBeNil)
  328. })
  329. })
  330. ctx.Reset(func() {
  331. tx.Commit()
  332. })
  333. })
  334. }