dm_test.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package danmu
  2. import (
  3. "context"
  4. "encoding/json"
  5. "go-common/app/interface/main/creative/model/danmu"
  6. "testing"
  7. "github.com/smartystreets/goconvey/convey"
  8. gock "gopkg.in/h2non/gock.v1"
  9. )
  10. func TestDanmuList(t *testing.T) {
  11. var (
  12. c = context.TODO()
  13. cid = int64(0)
  14. mid = int64(2089809)
  15. page = int(1)
  16. size = int(10)
  17. order = "ctime"
  18. pool = "0"
  19. midStr = ""
  20. ip = "127.0.0.1"
  21. )
  22. convey.Convey("List", t, func(ctx convey.C) {
  23. dmList, err := d.List(c, cid, mid, page, size, order, pool, midStr, ip)
  24. ctx.Convey("Then err should be nil.dmList should not be nil.", func(ctx convey.C) {
  25. ctx.So(err, convey.ShouldBeNil)
  26. ctx.So(dmList, convey.ShouldNotBeNil)
  27. })
  28. })
  29. }
  30. func TestDanmuEdit(t *testing.T) {
  31. var (
  32. c = context.TODO()
  33. mid = int64(2089809)
  34. cid = int64(0)
  35. state = int8(0)
  36. dmids = []int64{}
  37. ip = "127.0.0.1"
  38. )
  39. convey.Convey("Edit", t, func(ctx convey.C) {
  40. defer gock.OffAll()
  41. httpMock("POST", d.dmEditURL).Reply(200).JSON(`{"code":0,"data":""}`)
  42. err := d.Edit(c, mid, cid, state, dmids, ip)
  43. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. })
  46. })
  47. }
  48. func TestDanmuTransfer(t *testing.T) {
  49. var (
  50. c = context.TODO()
  51. mid = int64(2089809)
  52. fromCID = int64(1)
  53. toCID = int64(2)
  54. offset = float64(10.0)
  55. ak = "ak"
  56. ck = "ck"
  57. ip = "127.0.0.1"
  58. )
  59. convey.Convey("Transfer", t, func(ctx convey.C) {
  60. defer gock.OffAll()
  61. httpMock("POST", d.dmTransferURL).Reply(200).JSON(`{"code":0,"data":""}`)
  62. err := d.Transfer(c, mid, fromCID, toCID, offset, ak, ck, ip)
  63. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  64. ctx.So(err, convey.ShouldBeNil)
  65. })
  66. })
  67. }
  68. func TestDanmuUpPool(t *testing.T) {
  69. var (
  70. c = context.TODO()
  71. mid = int64(2089809)
  72. cid = int64(0)
  73. dmids = []int64{}
  74. pool = int8(0)
  75. )
  76. convey.Convey("UpPool", t, func(ctx convey.C) {
  77. defer gock.OffAll()
  78. httpMock("POST", d.dmPoolURL).Reply(200).JSON(`{"code":0,"data":""}`)
  79. err := d.UpPool(c, mid, cid, dmids, pool)
  80. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. })
  83. })
  84. }
  85. func TestDanmuDistri(t *testing.T) {
  86. var (
  87. c = context.TODO()
  88. mid = int64(2089809)
  89. cid = int64(1)
  90. ip = "127.0.0.1"
  91. )
  92. convey.Convey("Distri", t, func(ctx convey.C) {
  93. defer gock.OffAll()
  94. httpMock("Get", d.dmDistriURL).Reply(200).JSON(`{"code":0,"message":"0","ttl":1,"data":{"1":1}}`)
  95. distri, err := d.Distri(c, mid, cid, ip)
  96. ctx.Convey("Then err should be nil.distri should not be nil.", func(ctx convey.C) {
  97. ctx.So(err, convey.ShouldBeNil)
  98. ctx.So(distri, convey.ShouldNotBeNil)
  99. })
  100. })
  101. }
  102. func TestDanmuRecent(t *testing.T) {
  103. var (
  104. c = context.TODO()
  105. mid = int64(2089809)
  106. pn = int64(1)
  107. ps = int64(10)
  108. ip = "127.0.0.1"
  109. )
  110. convey.Convey("Recent", t, func(ctx convey.C) {
  111. var res struct {
  112. Code int `json:"code"`
  113. ResNewRecent *danmu.ResNewRecent `json:"data"`
  114. }
  115. res.ResNewRecent = &danmu.ResNewRecent{
  116. Page: &danmu.RecentPage{
  117. Pn: 1,
  118. Ps: 10,
  119. Total: 20,
  120. },
  121. }
  122. res.ResNewRecent.Result = append(res.ResNewRecent.Result, &danmu.DMMember{
  123. ID: 1,
  124. Aid: 99,
  125. })
  126. defer gock.OffAll()
  127. js, _ := json.Marshal(res)
  128. httpMock("Get", d.dmRecentURL).Reply(200).JSON(string(js))
  129. dmRecent, aids, err := d.Recent(c, mid, pn, ps, ip)
  130. ctx.Convey("Recent", func(ctx convey.C) {
  131. ctx.So(err, convey.ShouldBeNil)
  132. ctx.So(aids, convey.ShouldNotBeNil)
  133. ctx.So(dmRecent, convey.ShouldNotBeNil)
  134. })
  135. })
  136. }
  137. func TestDanmuisProtect(t *testing.T) {
  138. var (
  139. attrs = ""
  140. num = int64(0)
  141. )
  142. convey.Convey("isProtect", t, func(ctx convey.C) {
  143. p1 := d.isProtect(attrs, num)
  144. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  145. ctx.So(p1, convey.ShouldNotBeNil)
  146. })
  147. })
  148. }