mysql_coin_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoUpdateCoin(t *testing.T) {
  8. var (
  9. c = context.TODO()
  10. mid = int64(0)
  11. coin = float64(0)
  12. )
  13. convey.Convey("UpdateCoin", t, func(ctx convey.C) {
  14. err := d.UpdateCoin(c, mid, coin)
  15. ctx.Convey("Error should be nil", func(ctx convey.C) {
  16. ctx.So(err, convey.ShouldBeNil)
  17. })
  18. })
  19. }
  20. func TestDaoTxUpdateCoins(t *testing.T) {
  21. var (
  22. c = context.TODO()
  23. tx, _ = d.BeginTran(c)
  24. mid = int64(1)
  25. coin = float64(20)
  26. )
  27. convey.Convey("TxUpdateCoins", t, func(ctx convey.C) {
  28. err := d.TxUpdateCoins(c, tx, mid, coin)
  29. ctx.Convey("Error should be nil", func(ctx convey.C) {
  30. if err != nil {
  31. tx.Rollback()
  32. }
  33. ctx.So(err, convey.ShouldBeNil)
  34. tx.Commit()
  35. })
  36. })
  37. }
  38. func TestDaoTxUserCoin(t *testing.T) {
  39. var (
  40. c = context.TODO()
  41. tx, _ = d.BeginTran(c)
  42. mid = int64(0)
  43. )
  44. convey.Convey("TxUserCoin", t, func(ctx convey.C) {
  45. count, err := d.TxUserCoin(c, tx, mid)
  46. ctx.Convey("Error should be nil", func(ctx convey.C) {
  47. if err != nil {
  48. tx.Rollback()
  49. }
  50. ctx.So(err, convey.ShouldBeNil)
  51. })
  52. ctx.Convey("count should not be nil", func(ctx convey.C) {
  53. if count != 0 {
  54. tx.Commit()
  55. }
  56. ctx.So(count, convey.ShouldNotBeNil)
  57. })
  58. })
  59. }
  60. func TestDaoRawUserCoin(t *testing.T) {
  61. var (
  62. c = context.TODO()
  63. mid = int64(0)
  64. )
  65. convey.Convey("RawUserCoin", t, func(ctx convey.C) {
  66. res, err := d.RawUserCoin(c, mid)
  67. ctx.Convey("Error should be nil", func(ctx convey.C) {
  68. ctx.So(err, convey.ShouldBeNil)
  69. })
  70. ctx.Convey("res should not be nil", func(ctx convey.C) {
  71. ctx.So(res, convey.ShouldNotBeNil)
  72. })
  73. })
  74. }