http_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package http
  2. import (
  3. "context"
  4. "encoding/json"
  5. "flag"
  6. "net/url"
  7. "path/filepath"
  8. "testing"
  9. "go-common/app/service/main/archive/conf"
  10. "go-common/app/service/main/archive/service"
  11. ghttp "go-common/library/net/http/blademaster"
  12. . "github.com/smartystreets/goconvey/convey"
  13. )
  14. var (
  15. s *service.Service
  16. client *ghttp.Client
  17. )
  18. func init() {
  19. dir, _ := filepath.Abs("../cmd/archive-service-test.toml")
  20. flag.Set("conf", dir)
  21. conf.Init()
  22. s = service.New(conf.Conf)
  23. Init(conf.Conf, s)
  24. client = ghttp.NewClient(conf.Conf.PlayerClient)
  25. }
  26. func Test_Archive(t *testing.T) {
  27. Convey("/x/internal/v2/archive", t, func() {
  28. p := url.Values{}
  29. p.Set("aid", "10098813")
  30. var res struct {
  31. Code int `json:"code"`
  32. Data json.RawMessage `json:"data"`
  33. }
  34. err := client.Get(context.TODO(), "http://0.0.0.0:6081/x/internal/v2/archive", "", p, &res)
  35. So(err, ShouldBeNil)
  36. So(res.Code, ShouldBeZeroValue)
  37. Printf("code(%d) data(%s)\n", res.Code, res.Data)
  38. })
  39. }
  40. func Test_ArchiveView(t *testing.T) {
  41. Convey("/x/internal/v2/archive/view", t, func() {
  42. p := url.Values{}
  43. p.Set("aid", "10098813")
  44. var res struct {
  45. Code int `json:"code"`
  46. Data json.RawMessage `json:"data"`
  47. }
  48. err := client.Get(context.TODO(), "http://0.0.0.0:6081/x/internal/v2/archive/view", "", p, &res)
  49. So(err, ShouldBeNil)
  50. So(res.Code, ShouldBeZeroValue)
  51. Printf("code(%d) data(%s)\n", res.Code, res.Data)
  52. })
  53. }
  54. func Test_ArchiveViews(t *testing.T) {
  55. Convey("/x/internal/v2/archive/views", t, func() {
  56. p := url.Values{}
  57. p.Set("aids", "10098813,10098825,10098813")
  58. var res struct {
  59. Code int `json:"code"`
  60. Data json.RawMessage `json:"data"`
  61. }
  62. err := client.Get(context.TODO(), "http://0.0.0.0:6081/x/internal/v2/archive/views", "", p, &res)
  63. So(err, ShouldBeNil)
  64. So(res.Code, ShouldBeZeroValue)
  65. Printf("code(%d) data(%s)\n", res.Code, res.Data)
  66. })
  67. }
  68. func Test_RegionArcs(t *testing.T) {
  69. Convey("/x/internal/v2/archive/region", t, func() {
  70. p := url.Values{}
  71. p.Set("rid", "182")
  72. p.Set("ps", "20")
  73. p.Set("pn", "1")
  74. var res struct {
  75. Code int `json:"code"`
  76. Data json.RawMessage `json:"data"`
  77. }
  78. err := client.Get(context.TODO(), "http://0.0.0.0:6081/x/internal/v2/archive/region", "", p, &res)
  79. So(err, ShouldBeNil)
  80. So(res.Code, ShouldBeZeroValue)
  81. Printf("code(%d) data(%s)\n", res.Code, res.Data)
  82. })
  83. }
  84. func Test_ShareAdd(t *testing.T) {
  85. Convey("/x/internal/v2/archive/share/add", t, func() {
  86. p := url.Values{}
  87. p.Set("aid", "5463554")
  88. p.Set("mid", "1684013")
  89. var res struct {
  90. Code int `json:"code"`
  91. Data json.RawMessage `json:"data"`
  92. }
  93. err := client.Post(context.TODO(), "http://0.0.0.0:6081/x/internal/v2/archive/share/add", "", p, &res)
  94. So(err, ShouldBeNil)
  95. So(res.Code, ShouldBeZeroValue)
  96. Printf("code(%d) data(%s)\n", res.Code, res.Data)
  97. })
  98. }
  99. func Test_UpCount(t *testing.T) {
  100. Convey("/x/internal/v2/archive/up/count", t, func() {
  101. p := url.Values{}
  102. p.Set("mid", "27515232")
  103. var res struct {
  104. Code int `json:"code"`
  105. Data json.RawMessage `json:"data"`
  106. }
  107. err := client.Get(context.TODO(), "http://0.0.0.0:6081/x/internal/v2/archive/up/count", "", p, &res)
  108. So(err, ShouldBeNil)
  109. So(res.Code, ShouldBeZeroValue)
  110. Printf("code(%d) data(%s)\n", res.Code, res.Data)
  111. })
  112. }