dao_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/job/main/point/conf"
  9. "go-common/app/job/main/point/model"
  10. xtime "go-common/library/time"
  11. . "github.com/smartystreets/goconvey/convey"
  12. )
  13. var (
  14. mid int64 = 7593623
  15. d *Dao
  16. c = context.TODO()
  17. )
  18. func init() {
  19. dir, _ := filepath.Abs("../cmd/point-job.toml")
  20. flag.Set("conf", dir)
  21. conf.Init()
  22. d = New(conf.Conf)
  23. }
  24. func TestAddPoint(t *testing.T) {
  25. Convey("TestAddPoint", t, func() {
  26. p := &model.VipPoint{
  27. Mid: 111,
  28. PointBalance: 1,
  29. Ver: 1,
  30. }
  31. _, err := d.AddPoint(c, p)
  32. So(err, ShouldBeNil)
  33. })
  34. }
  35. // go test -test.v -test.run TestUpdatePoint
  36. func TestUpdatePoint(t *testing.T) {
  37. Convey("TestUpdatePoint", t, func() {
  38. p := &model.VipPoint{
  39. Mid: 111,
  40. PointBalance: 2,
  41. Ver: 1,
  42. }
  43. oldp := &model.VipPoint{
  44. Ver: 1,
  45. }
  46. _, err := d.UpdatePoint(c, p, oldp.Ver)
  47. So(err, ShouldBeNil)
  48. })
  49. }
  50. // go test -test.v -test.run TestChangeHistory
  51. func TestChangeHistory(t *testing.T) {
  52. Convey("TestChangeHistory", t, func() {
  53. h := &model.VipPointChangeHistory{
  54. Mid: 111,
  55. Point: 2,
  56. OrderID: "wqwqe22112",
  57. ChangeType: 10,
  58. ChangeTime: xtime.Time(time.Now().Unix()),
  59. RelationID: "11",
  60. PointBalance: 111,
  61. }
  62. _, err := d.AddPointHistory(c, h)
  63. So(err, ShouldBeNil)
  64. })
  65. }
  66. // go test -test.v -test.run TestDeletePointCache
  67. func TestDeletePointCache(t *testing.T) {
  68. Convey("TestDeletePointCache", t, func() {
  69. err := d.DelPointInfoCache(c, mid)
  70. So(err, ShouldBeNil)
  71. })
  72. }