message_test.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. package message
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/job/main/reply/conf"
  6. "os"
  7. "testing"
  8. "time"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. d *Dao
  13. )
  14. func TestMain(m *testing.M) {
  15. if os.Getenv("DEPLOY_ENV") != "" {
  16. flag.Set("app_id", "main.community.reply-job")
  17. flag.Set("conf_token", "5deea0665f8a7670b22a719337a39c7d")
  18. flag.Set("tree_id", "2123")
  19. flag.Set("conf_version", "docker-1")
  20. flag.Set("deploy_env", "uat")
  21. flag.Set("conf_host", "config.bilibili.co")
  22. flag.Set("conf_path", "/tmp")
  23. flag.Set("region", "sh")
  24. flag.Set("zone", "sh001")
  25. } else {
  26. flag.Set("conf", "../../cmd/reply-job-test.toml")
  27. }
  28. flag.Parse()
  29. if err := conf.Init(); err != nil {
  30. panic(err)
  31. }
  32. d = NewMessageDao(conf.Conf)
  33. os.Exit(m.Run())
  34. }
  35. func TestMessageNewMessageDao(t *testing.T) {
  36. convey.Convey("NewMessageDao", t, func(ctx convey.C) {
  37. var (
  38. c = conf.Conf
  39. )
  40. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  41. p1 := NewMessageDao(c)
  42. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  43. ctx.So(p1, convey.ShouldNotBeNil)
  44. })
  45. })
  46. })
  47. }
  48. func TestMessageLike(t *testing.T) {
  49. convey.Convey("Like", t, func(ctx convey.C) {
  50. var (
  51. c = context.Background()
  52. mid = int64(0)
  53. tomid = int64(0)
  54. title = ""
  55. msg = ""
  56. extraInfo = ""
  57. now = time.Now()
  58. err error
  59. )
  60. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  61. err = d.Like(c, mid, tomid, title, msg, extraInfo, now)
  62. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  63. ctx.So(msg, convey.ShouldBeBlank)
  64. })
  65. })
  66. })
  67. }
  68. func TestMessageReply(t *testing.T) {
  69. convey.Convey("Reply", t, func(ctx convey.C) {
  70. var (
  71. c = context.Background()
  72. mc = ""
  73. resID = ""
  74. mid = int64(0)
  75. tomid = int64(0)
  76. title = ""
  77. msg = ""
  78. extraInfo = ""
  79. now = time.Now()
  80. err error
  81. )
  82. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  83. err = d.Reply(c, mc, resID, mid, tomid, title, msg, extraInfo, now)
  84. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  85. ctx.So(msg, convey.ShouldBeBlank)
  86. })
  87. })
  88. })
  89. }
  90. func TestMessageDeleteReply(t *testing.T) {
  91. convey.Convey("DeleteReply", t, func(ctx convey.C) {
  92. var (
  93. c = context.Background()
  94. mid = int64(0)
  95. title = ""
  96. msg = ""
  97. now = time.Now()
  98. err error
  99. )
  100. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  101. err = d.DeleteReply(c, mid, title, msg, now)
  102. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  103. ctx.So(msg, convey.ShouldBeBlank)
  104. })
  105. })
  106. })
  107. }
  108. func TestMessageAt(t *testing.T) {
  109. convey.Convey("At", t, func(ctx convey.C) {
  110. var (
  111. c = context.Background()
  112. mid = int64(0)
  113. mids = []int64{}
  114. title = ""
  115. msg = ""
  116. extraInfo = ""
  117. now = time.Now()
  118. err error
  119. )
  120. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  121. err = d.At(c, mid, mids, title, msg, extraInfo, now)
  122. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  123. ctx.So(msg, convey.ShouldBeBlank)
  124. })
  125. })
  126. })
  127. }
  128. func TestMessageAcceptReport(t *testing.T) {
  129. convey.Convey("AcceptReport", t, func(ctx convey.C) {
  130. var (
  131. c = context.Background()
  132. mid = int64(0)
  133. title = ""
  134. msg = ""
  135. now = time.Now()
  136. err error
  137. )
  138. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  139. err = d.AcceptReport(c, mid, title, msg, now)
  140. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  141. ctx.So(msg, convey.ShouldBeBlank)
  142. })
  143. })
  144. })
  145. }
  146. func TestMessageSystem(t *testing.T) {
  147. convey.Convey("System", t, func(ctx convey.C) {
  148. var (
  149. c = context.Background()
  150. mc = ""
  151. resID = ""
  152. mid = int64(0)
  153. title = ""
  154. msg = ""
  155. info = ""
  156. now = time.Now()
  157. err error
  158. )
  159. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  160. err = d.System(c, mc, resID, mid, title, msg, info, now)
  161. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  162. ctx.So(msg, convey.ShouldBeBlank)
  163. })
  164. })
  165. })
  166. }
  167. func TestMessagesend(t *testing.T) {
  168. convey.Convey("send", t, func(ctx convey.C) {
  169. var (
  170. c = context.Background()
  171. mc = ""
  172. resID = ""
  173. title = ""
  174. msg = ""
  175. tp = int(0)
  176. pub = int64(0)
  177. mids = []int64{}
  178. info = ""
  179. ts = int64(0)
  180. err error
  181. )
  182. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  183. err = d.send(c, mc, resID, title, msg, tp, pub, mids, info, ts)
  184. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  185. ctx.So(msg, convey.ShouldBeBlank)
  186. })
  187. })
  188. })
  189. }
  190. func TestMessageconverAt(t *testing.T) {
  191. convey.Convey("converAt", t, func(ctx convey.C) {
  192. var (
  193. title = ""
  194. )
  195. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  196. p1 := converAt(title)
  197. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  198. ctx.So(p1, convey.ShouldBeBlank)
  199. })
  200. })
  201. })
  202. }
  203. func TestMessageconvertMsg(t *testing.T) {
  204. convey.Convey("convertMsg", t, func(ctx convey.C) {
  205. var (
  206. msg = "评"
  207. )
  208. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  209. p1 := convertMsg(msg)
  210. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  211. ctx.So(p1, convey.ShouldEqual, "評")
  212. })
  213. })
  214. })
  215. }