user_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package http
  2. import (
  3. "context"
  4. "encoding/json"
  5. "flag"
  6. "fmt"
  7. "net/http"
  8. "net/url"
  9. "strings"
  10. "testing"
  11. "go-common/app/admin/main/apm/conf"
  12. bm "go-common/library/net/http/blademaster"
  13. . "github.com/smartystreets/goconvey/convey"
  14. )
  15. func TestUserRuleStates(t *testing.T) {
  16. fmt.Println("========UserRuleStates tests========")
  17. Convey("test userAuth", t, func() {
  18. var params = url.Values{}
  19. ctx := userRequest("GET", params)
  20. userRuleStates(&ctx)
  21. data, err := json.Marshal(ctx)
  22. fmt.Println(string(data))
  23. So(err, ShouldBeNil)
  24. })
  25. }
  26. func TestUserApplies(t *testing.T) {
  27. fmt.Println("========UserAppliestests========")
  28. Convey("test userApplies", t, func() {
  29. var params = url.Values{}
  30. ctx := userRequest("GET", params)
  31. userApplies(&ctx)
  32. data, err := json.Marshal(ctx)
  33. fmt.Println(string(data))
  34. So(err, ShouldBeNil)
  35. })
  36. }
  37. // func TestUserApply(t *testing.T) {
  38. // fmt.Println("========UserApply tests========")
  39. // Convey("test userApply", t, func() {
  40. // var params = url.Values{}
  41. // params.Set("item", "APP_AUTH_VIEW,APP_EDIT")
  42. // ctx := userRequest("POST", params)
  43. // userApply(&ctx)
  44. // data, err := json.Marshal(ctx)
  45. // fmt.Println(string(data))
  46. // So(err, ShouldBeNil)
  47. // })
  48. // }
  49. // func TestUserAudit(t *testing.T) {
  50. // fmt.Println("========UserAudit tests========")
  51. // Convey("test userAudit", t, func() {
  52. // var params = url.Values{}
  53. // params.Set("id", "2")
  54. // params.Set("status", "2")
  55. // ctx := userRequest("POST", params)
  56. // userAudit(&ctx)
  57. // data, err := json.Marshal(ctx)
  58. // fmt.Println(string(data))
  59. // So(err, ShouldBeNil)
  60. // })
  61. // }
  62. func userRequest(method string, params url.Values) (ctx bm.Context) {
  63. flag.Set("conf", "../cmd/apm-admin-test.toml")
  64. conf.Init()
  65. //apmSvc = service.New(conf.Conf)
  66. path := "/"
  67. req, _ := http.NewRequest(method, path, strings.NewReader(params.Encode()))
  68. req.Header.Set("X-BACKEND-BILI-REAL-IP", "xxx")
  69. req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
  70. req.Header.Set("Cookie", "_AJSESSIONID=0eac92f0621b11e8b877522233007f8a; username=chengxing; sven-apm=fa7128be35363eb623e4dd5d611daf1f3273316cc09a66655db0e79f616d4f53")
  71. req.ParseForm()
  72. ctx = bm.Context{
  73. Context: context.TODO(),
  74. Request: req,
  75. }
  76. ctx.Set("username", "chengxing")
  77. ctx.Request.ParseForm()
  78. return
  79. }