share_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package dao
  2. import (
  3. "context"
  4. "math/rand"
  5. "testing"
  6. "go-common/app/service/main/share/model"
  7. "go-common/library/ecode"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoShares(t *testing.T) {
  11. var (
  12. c = context.TODO()
  13. oids = []int64{1, 2}
  14. tp = int(0)
  15. )
  16. convey.Convey("Shares", t, func(ctx convey.C) {
  17. shares, err := d.Shares(c, oids, tp)
  18. ctx.Convey("Then err should be nil.shares should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(shares, convey.ShouldNotBeNil)
  21. })
  22. })
  23. }
  24. func TestDaoShareCount(t *testing.T) {
  25. var (
  26. c = context.TODO()
  27. oid = int64(rand.Intn(100000000))
  28. tp = int(2)
  29. )
  30. convey.Convey("ShareCount", t, func(ctx convey.C) {
  31. count, err := d.ShareCount(c, oid, tp)
  32. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  33. ctx.So(err, convey.ShouldBeNil)
  34. ctx.So(count, convey.ShouldNotBeNil)
  35. })
  36. })
  37. }
  38. func TestDaoAdd(t *testing.T) {
  39. convey.Convey("Add", t, func(ctx convey.C) {
  40. oid := rand.Intn(1000000)
  41. mid := rand.Intn(1000000)
  42. p := &model.ShareParams{
  43. OID: int64(oid),
  44. MID: int64(mid),
  45. TP: int(3),
  46. IP: "",
  47. }
  48. shared, err := d.Add(context.Background(), p)
  49. if err == ecode.ShareAlreadyAdd {
  50. err = nil
  51. }
  52. ctx.Convey("Then err should be nil.shared should not be nil.", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. ctx.So(shared, convey.ShouldNotBeNil)
  55. })
  56. })
  57. }