service_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "path/filepath"
  7. "testing"
  8. "time"
  9. "go-common/app/admin/main/point/conf"
  10. "go-common/app/admin/main/point/model"
  11. pointmol "go-common/app/service/main/point/model"
  12. . "github.com/smartystreets/goconvey/convey"
  13. )
  14. var (
  15. s *Service
  16. c = context.TODO()
  17. )
  18. func init() {
  19. dir, _ := filepath.Abs("../cmd/point-admin.toml")
  20. flag.Set("conf", dir)
  21. conf.Init()
  22. s = New(conf.Conf)
  23. fmt.Printf("%+v", conf.Conf)
  24. time.Sleep(time.Second)
  25. }
  26. func Test_PointHistory(t *testing.T) {
  27. Convey("Test_PointHistory", t, func() {
  28. arg := &model.ArgPointHistory{}
  29. res, err := s.PointHistory(context.TODO(), arg)
  30. So(err, ShouldBeNil)
  31. So(res, ShouldNotBeNil)
  32. })
  33. }
  34. func Test_PointCoinInfo(t *testing.T) {
  35. Convey("Test_PointCoinInfo", t, func() {
  36. res, err := s.PointCoinInfo(context.TODO(), 1)
  37. So(err, ShouldBeNil)
  38. So(res, ShouldNotBeNil)
  39. })
  40. }
  41. func Test_PointCoin(t *testing.T) {
  42. Convey("Test_PointCoin", t, func() {
  43. var (
  44. id int64
  45. err error
  46. res *model.PointConf
  47. )
  48. pc := &model.PointConf{AppID: 1}
  49. id, err = s.PointCoinAdd(context.TODO(), pc)
  50. So(err, ShouldBeNil)
  51. So(id, ShouldBeGreaterThanOrEqualTo, 1)
  52. res, err = s.PointCoinInfo(context.TODO(), id)
  53. So(err, ShouldBeNil)
  54. So(res, ShouldNotBeNil)
  55. So(res.AppID, ShouldEqual, pc.AppID)
  56. })
  57. }
  58. func Test_PointConfList(t *testing.T) {
  59. Convey("Test_PointConfList", t, func() {
  60. res, err := s.PointConfList(context.TODO())
  61. So(err, ShouldBeNil)
  62. So(res, ShouldNotBeNil)
  63. })
  64. }
  65. func TestPointAdd(t *testing.T) {
  66. Convey("TestPointAdd", t, func() {
  67. arg := new(pointmol.ArgPoint)
  68. arg.Mid = int64(2222)
  69. arg.Point = int64(1)
  70. arg.Remark = "系统发放"
  71. arg.Operator = "yubaihai"
  72. arg.ChangeType = model.PointSystem
  73. err := s.PointAdd(c, arg)
  74. So(err, ShouldBeNil)
  75. })
  76. }