server_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package server
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "path/filepath"
  7. "testing"
  8. item "go-common/app/service/openplatform/ticket-item/api/grpc/v1"
  9. "go-common/app/service/openplatform/ticket-item/conf"
  10. "go-common/app/service/openplatform/ticket-item/model"
  11. "go-common/app/service/openplatform/ticket-item/service"
  12. . "github.com/smartystreets/goconvey/convey"
  13. )
  14. var (
  15. s *server
  16. ctx = context.TODO()
  17. )
  18. func init() {
  19. dir, _ := filepath.Abs("../../cmd/item.toml")
  20. flag.Set("conf", dir)
  21. if err := conf.Init(); err != nil {
  22. panic(fmt.Sprintf("conf.Init() error(%v)", err))
  23. }
  24. s = &server{
  25. is: service.New(conf.Conf),
  26. }
  27. }
  28. // Test_Info
  29. func TestInfo(t *testing.T) {
  30. Convey("get data", t, func() {
  31. res, err := s.Info(ctx, &item.InfoRequest{ID: model.DataID})
  32. So(err, ShouldBeNil)
  33. So(res, ShouldNotBeNil)
  34. So(res, ShouldNotBeEmpty)
  35. })
  36. Convey("no data", t, func() {
  37. res, err := s.Info(ctx, &item.InfoRequest{ID: model.NoDataID})
  38. So(err, ShouldNotBeNil)
  39. So(res, ShouldNotBeEmpty)
  40. })
  41. }
  42. // Test_Cards
  43. func TestCards(t *testing.T) {
  44. Convey("get data", t, func() {
  45. res, err := s.Cards(ctx, &item.CardsRequest{IDs: model.DataIDs})
  46. So(err, ShouldBeNil)
  47. So(res, ShouldNotBeNil)
  48. So(res, ShouldNotBeEmpty)
  49. })
  50. Convey("no data", t, func() {
  51. res, err := s.Cards(ctx, &item.CardsRequest{IDs: model.NoDataIDs})
  52. So(err, ShouldNotBeNil)
  53. So(res, ShouldNotBeNil)
  54. })
  55. }
  56. // TestBillInfo
  57. func TestBillInfo(t *testing.T) {
  58. Convey("get data", t, func() {
  59. res, err := s.BillInfo(ctx, &item.BillRequest{
  60. IDs: model.DataIDs,
  61. ScIDs: model.DataSIDs,
  62. TkIDs: model.DataTIDs,
  63. })
  64. So(err, ShouldBeNil)
  65. So(res, ShouldNotBeNil)
  66. So(res, ShouldNotBeEmpty)
  67. })
  68. Convey("no data", t, func() {
  69. res, err := s.BillInfo(ctx, &item.BillRequest{
  70. IDs: model.NoDataIDs,
  71. ScIDs: model.NoDataSIDs,
  72. TkIDs: model.NoDataTIDs,
  73. })
  74. So(err, ShouldNotBeNil)
  75. So(res, ShouldNotBeNil)
  76. })
  77. }
  78. // TestWish
  79. func TestWish(t *testing.T) {
  80. Convey("add wish", t, func() {
  81. res, err := s.Wish(ctx, &item.WishRequest{
  82. ItemID: 1,
  83. MID: 1,
  84. Face: "",
  85. })
  86. So(err, ShouldBeNil)
  87. So(res, ShouldNotBeNil)
  88. })
  89. }
  90. // TestWish
  91. func TestFav(t *testing.T) {
  92. Convey("fav add", t, func() {
  93. res, err := s.Fav(ctx, &item.FavRequest{
  94. ItemID: 1,
  95. MID: 1,
  96. Type: 1,
  97. Status: 1,
  98. })
  99. So(err, ShouldBeNil)
  100. So(res, ShouldNotBeNil)
  101. })
  102. Convey("fav del", t, func() {
  103. res, err := s.Fav(ctx, &item.FavRequest{
  104. ItemID: 1,
  105. MID: 1,
  106. Type: 1,
  107. Status: 0,
  108. })
  109. So(err, ShouldBeNil)
  110. So(res, ShouldNotBeNil)
  111. })
  112. }