tidb_test.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. pb "go-common/app/service/main/history/api/grpc"
  7. "go-common/app/service/main/history/model"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. var _history = &model.History{
  11. Mid: 1,
  12. BusinessID: 4,
  13. Business: "pgc",
  14. Kid: 2,
  15. Aid: 3,
  16. Sid: 4,
  17. Epid: 5,
  18. Cid: 6,
  19. SubType: 7,
  20. Device: 8,
  21. Progress: 9,
  22. ViewAt: 10,
  23. }
  24. var hs = []*model.History{_history}
  25. func TestDaoAddHistories(t *testing.T) {
  26. var (
  27. c = context.Background()
  28. )
  29. convey.Convey("AddHistories", t, func(ctx convey.C) {
  30. err := d.AddHistories(c, hs)
  31. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldBeNil)
  33. })
  34. })
  35. }
  36. func TestDaoQueryBusinesses(t *testing.T) {
  37. var (
  38. c = context.Background()
  39. )
  40. convey.Convey("QueryBusinesses", t, func(ctx convey.C) {
  41. res, err := d.QueryBusinesses(c)
  42. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  43. ctx.So(err, convey.ShouldBeNil)
  44. ctx.So(res, convey.ShouldNotBeEmpty)
  45. })
  46. })
  47. }
  48. func TestDaoUserHistories(t *testing.T) {
  49. var (
  50. c = context.Background()
  51. mid = int64(1)
  52. viewAt = time.Now().Unix()
  53. ps = int64(1)
  54. )
  55. convey.Convey("UserHistories all business", t, func(ctx convey.C) {
  56. var businesses []string
  57. res, err := d.UserHistories(c, businesses, mid, viewAt, ps)
  58. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  59. ctx.So(err, convey.ShouldBeNil)
  60. ctx.So(res, convey.ShouldNotBeEmpty)
  61. res["pgc"][0].Ctime = 0
  62. res["pgc"][0].Mtime = 0
  63. ctx.So(res, convey.ShouldResemble, map[string][]*model.History{
  64. "pgc": {_history},
  65. })
  66. })
  67. })
  68. convey.Convey("UserHistories one business", t, func(ctx convey.C) {
  69. var businesses = []string{"pgc"}
  70. res, err := d.UserHistories(c, businesses, mid, viewAt, ps)
  71. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  72. ctx.So(err, convey.ShouldBeNil)
  73. ctx.So(res, convey.ShouldNotBeEmpty)
  74. res["pgc"][0].Ctime = 0
  75. res["pgc"][0].Mtime = 0
  76. ctx.So(res, convey.ShouldResemble, map[string][]*model.History{
  77. "pgc": {_history},
  78. })
  79. })
  80. })
  81. }
  82. func TestDaoHistories(t *testing.T) {
  83. var (
  84. c = context.Background()
  85. business = "pgc"
  86. mid = int64(1)
  87. ids = []int64{2}
  88. )
  89. convey.Convey("Histories", t, func(ctx convey.C) {
  90. res, err := d.Histories(c, business, mid, ids)
  91. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  92. ctx.So(err, convey.ShouldBeNil)
  93. ctx.So(res, convey.ShouldNotBeEmpty)
  94. })
  95. })
  96. }
  97. func TestDaoDeleteHistories(t *testing.T) {
  98. var (
  99. c = context.Background()
  100. h = &pb.DelHistoriesReq{Mid: 1, Records: []*pb.DelHistoriesReq_Record{
  101. {Business: "pgc", ID: 2},
  102. },
  103. }
  104. )
  105. convey.Convey("DeleteHistories", t, func(ctx convey.C) {
  106. d.AddHistories(c, hs)
  107. err := d.DeleteHistories(c, h)
  108. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  109. ctx.So(err, convey.ShouldBeNil)
  110. })
  111. })
  112. }
  113. func TestDaoClearHistory(t *testing.T) {
  114. var (
  115. c = context.Background()
  116. mid = int64(1)
  117. businesses = []string{"pgc"}
  118. )
  119. convey.Convey("ClearHistory", t, func(ctx convey.C) {
  120. d.AddHistories(c, hs)
  121. err := d.ClearHistory(c, mid, businesses)
  122. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  123. ctx.So(err, convey.ShouldBeNil)
  124. })
  125. })
  126. }
  127. func TestDaoClearAllHistory(t *testing.T) {
  128. var (
  129. c = context.Background()
  130. mid = int64(1)
  131. )
  132. convey.Convey("ClearAllHistory", t, func(ctx convey.C) {
  133. err := d.ClearAllHistory(c, mid)
  134. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  135. ctx.So(err, convey.ShouldBeNil)
  136. })
  137. })
  138. }
  139. func TestDaoUpdateUserHide(t *testing.T) {
  140. var (
  141. c = context.Background()
  142. mid = int64(1)
  143. hide = true
  144. )
  145. convey.Convey("UpdateUserHide", t, func(ctx convey.C) {
  146. err := d.UpdateUserHide(c, mid, hide)
  147. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  148. ctx.So(err, convey.ShouldBeNil)
  149. })
  150. })
  151. }
  152. func TestDaoUserHide(t *testing.T) {
  153. var (
  154. c = context.Background()
  155. mid = int64(1)
  156. )
  157. convey.Convey("UserHide", t, func(ctx convey.C) {
  158. hide, err := d.UserHide(c, mid)
  159. ctx.Convey("Then err should be nil.hide should not be nil.", func(ctx convey.C) {
  160. ctx.So(err, convey.ShouldBeNil)
  161. ctx.So(hide, convey.ShouldEqual, true)
  162. })
  163. hide, err = d.UserHide(c, 200)
  164. ctx.Convey("not found .Then err should be nil.hide should not be nil.", func(ctx convey.C) {
  165. ctx.So(err, convey.ShouldBeNil)
  166. ctx.So(hide, convey.ShouldBeFalse)
  167. })
  168. })
  169. }