package_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/job/live/gift/internal/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestServiceAddGift(t *testing.T) {
  9. convey.Convey("AddGift", t, func(c convey.C) {
  10. var (
  11. ctx = context.Background()
  12. m = &model.AddFreeGift{
  13. UID: 1,
  14. GiftID: 1,
  15. GiftNum: 1,
  16. ExpireAt: 0,
  17. Source: "test",
  18. }
  19. )
  20. c.Convey("When everything gose positive", func(c convey.C) {
  21. bagId, err := s.AddGift(ctx, m)
  22. c.Convey("Then err should be nil.bagId should not be nil.", func(c convey.C) {
  23. c.So(err, convey.ShouldBeNil)
  24. c.So(bagId, convey.ShouldNotBeNil)
  25. })
  26. })
  27. })
  28. }
  29. func TestServiceGetBagID(t *testing.T) {
  30. convey.Convey("GetBagID", t, func(c convey.C) {
  31. var (
  32. ctx = context.Background()
  33. uid = int64(1)
  34. giftID = int64(1)
  35. expireAt = int64(0)
  36. )
  37. c.Convey("When everything gose positive", func(c convey.C) {
  38. id, err := s.GetBagID(ctx, uid, giftID, expireAt)
  39. c.Convey("Then err should be nil.id should not be nil.", func(c convey.C) {
  40. c.So(err, convey.ShouldBeNil)
  41. c.So(id, convey.ShouldNotBeNil)
  42. })
  43. })
  44. })
  45. }
  46. func TestServiceUpdateFreeGiftCache(t *testing.T) {
  47. convey.Convey("UpdateFreeGiftCache", t, func(c convey.C) {
  48. var (
  49. ctx = context.Background()
  50. uid = int64(0)
  51. giftID = int64(0)
  52. expireAt = int64(0)
  53. num = int64(0)
  54. )
  55. c.Convey("When everything gose positive", func(c convey.C) {
  56. s.UpdateFreeGiftCache(ctx, uid, giftID, expireAt, num)
  57. c.Convey("No return values", func(ctx convey.C) {
  58. })
  59. })
  60. })
  61. }