roomNotice_test.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package notice
  2. import (
  3. "context"
  4. "go-common/app/service/live/xuserex/conf"
  5. "testing"
  6. "time"
  7. "flag"
  8. "github.com/smartystreets/goconvey/convey"
  9. "os"
  10. )
  11. var (
  12. d *Dao
  13. UID = int64(10000)
  14. targetID = int64(10000)
  15. date = "20190101"
  16. term = time.Now()
  17. )
  18. func TestMain(m *testing.M) {
  19. if os.Getenv("DEPLOY_ENV") != "" {
  20. flag.Set("app_id", "live.live.xuserex")
  21. flag.Set("conf_token", "4e6ace268a9ee6d04fad131ad551f61e")
  22. flag.Set("tree_id", "82470")
  23. flag.Set("conf_version", "docker-1")
  24. flag.Set("deploy_env", "uat")
  25. flag.Set("conf_host", "config.bilibili.co")
  26. flag.Set("conf_path", "/tmp")
  27. flag.Set("region", "sh")
  28. flag.Set("zone", "sh001")
  29. } else {
  30. flag.Set("conf", "../../cmd/test.toml")
  31. flag.Set("deploy.env", "uat")
  32. }
  33. flag.Parse()
  34. if err := conf.Init(); err != nil {
  35. panic(err)
  36. }
  37. d = New(conf.Conf)
  38. m.Run()
  39. os.Exit(0)
  40. }
  41. func TestRoomNoticeNew(t *testing.T) {
  42. convey.Convey("New", t, func(ctx convey.C) {
  43. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  44. ctx.Convey("Then dao should not be nil.", func(ctx convey.C) {
  45. ctx.So(d, convey.ShouldNotBeNil)
  46. })
  47. })
  48. })
  49. }
  50. func TestRoomNoticekeyShouldNotice(t *testing.T) {
  51. convey.Convey("keyShouldNotice", t, func(ctx convey.C) {
  52. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  53. p1 := keyShouldNotice(UID, targetID, date)
  54. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  55. ctx.So(p1, convey.ShouldNotBeNil)
  56. })
  57. })
  58. })
  59. }
  60. func TestRoomNoticeIsNotice(t *testing.T) {
  61. convey.Convey("IsNotice", t, func(ctx convey.C) {
  62. convey.Convey("When everything goes positive", func(ctx convey.C) {
  63. c := context.TODO()
  64. p1, err := d.IsNotice(c, UID, targetID)
  65. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  66. ctx.So(err, convey.ShouldBeNil)
  67. ctx.So(p1, convey.ShouldNotBeNil)
  68. })
  69. })
  70. })
  71. }
  72. func TestRoomNoticegetThreshold(t *testing.T) {
  73. convey.Convey("getThreshold", t, func(ctx convey.C) {
  74. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  75. threshold, err := d.getThreshold()
  76. ctx.Convey("Then err should be nil.threshold should not be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. ctx.So(threshold, convey.ShouldNotBeNil)
  79. })
  80. })
  81. })
  82. }
  83. func TestRoomNoticegetShouldNotice(t *testing.T) {
  84. convey.Convey("getShouldNotice", t, func() {
  85. var (
  86. ctx = context.Background()
  87. )
  88. convey.Convey("When everything goes positive", func() {
  89. shouldNotice, err := d.getShouldNotice(ctx, UID, targetID, term)
  90. convey.Convey("Then err should be nil.shouldNotice should not be nil.", func(ctx convey.C) {
  91. ctx.So(err, convey.ShouldBeNil)
  92. ctx.So(shouldNotice, convey.ShouldNotBeNil)
  93. })
  94. })
  95. })
  96. }
  97. func TestRoomNoticehbaseRowKey(t *testing.T) {
  98. convey.Convey("hbaseRowKey", t, func(ctx convey.C) {
  99. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  100. p1 := hbaseRowKey(UID, targetID, date)
  101. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  102. ctx.So(p1, convey.ShouldNotBeNil)
  103. })
  104. })
  105. })
  106. }
  107. func TestRoomNoticeRawMonthConsume(t *testing.T) {
  108. convey.Convey("RawMonthConsume", t, func(ctx convey.C) {
  109. var (
  110. c = context.Background()
  111. )
  112. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  113. res, err := d.RawMonthConsume(c, UID, targetID, date)
  114. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  115. ctx.So(err, convey.ShouldBeNil)
  116. ctx.So(res, convey.ShouldNotBeNil)
  117. })
  118. })
  119. })
  120. }
  121. func TestRoomNoticeGetTermBegin(t *testing.T) {
  122. convey.Convey("GetTermBegin", t, func(ctx convey.C) {
  123. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  124. p1 := d.GetTermBegin()
  125. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  126. ctx.So(p1, convey.ShouldNotBeNil)
  127. })
  128. })
  129. })
  130. }
  131. func TestRoomNoticeGetTermEnd(t *testing.T) {
  132. convey.Convey("GetTermEnd", t, func(ctx convey.C) {
  133. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  134. p1 := d.GetTermEnd()
  135. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  136. ctx.So(p1, convey.ShouldNotBeNil)
  137. })
  138. })
  139. })
  140. }
  141. func TestRoomNoticeIsValidTerm(t *testing.T) {
  142. convey.Convey("IsValidTerm", t, func(ctx convey.C) {
  143. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  144. p1 := d.IsValidTerm(term)
  145. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  146. ctx.So(p1, convey.ShouldNotBeNil)
  147. })
  148. })
  149. })
  150. }
  151. func TestRoomNoticeisGuard(t *testing.T) {
  152. convey.Convey("isGuard", t, func(ctx convey.C) {
  153. var (
  154. c = context.Background()
  155. )
  156. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  157. isGuard, err := d.isGuard(c, UID, targetID)
  158. ctx.Convey("Then err should be nil.isGuard should not be nil.", func(ctx convey.C) {
  159. ctx.So(err, convey.ShouldBeNil)
  160. ctx.So(isGuard, convey.ShouldNotBeNil)
  161. })
  162. })
  163. })
  164. }
  165. func TestGetTaskFinish(t *testing.T) {
  166. convey.Convey("GetTaskFinish", t, func(ctx convey.C) {
  167. var (
  168. c = context.Background()
  169. )
  170. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  171. term := d.GetTermBegin()
  172. isFinish, err := d.GetTaskFinish(c, term)
  173. ctx.Convey("Then err should be nil.isGuard should not be nil.", func(ctx convey.C) {
  174. ctx.So(err, convey.ShouldBeNil)
  175. ctx.So(isFinish, convey.ShouldNotBeNil)
  176. })
  177. })
  178. })
  179. }