grpc_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package service
  2. import (
  3. . "github.com/smartystreets/goconvey/convey"
  4. "go-common/app/admin/ep/melloi/model"
  5. "testing"
  6. )
  7. var (
  8. protoPath = "/data/jmeter-log/test/ep/melloi/test/381016516/"
  9. protoFile = "StreamEvent.proto"
  10. protoModel = model.ProtoPathModel{
  11. RootPath: "/data/jmeter-log/test/ep/melloi/test/445057856/proto", ExtraPath: "account/service/member",
  12. }
  13. scriptID = model.GRPCExecuteScriptRequest{ScriptID: 1}
  14. grpc = model.GRPC{
  15. TaskName: "testGrpc",
  16. Department: "test",
  17. Project: "ep",
  18. APP: "melloi",
  19. Active: 1,
  20. HostName: "172.22.33.22",
  21. Port: 9000,
  22. ServiceName: "Identify",
  23. ProtoClassName: "Api",
  24. PkgPath: "V1",
  25. RequestType: "GetCookieInfo",
  26. RequestMethod: "getCookieInfo",
  27. RequestContent: "{\"Cookie\":\"sid:1ers12;SETDATA:a18jds9234js9sfa24jsdf\"}",
  28. ResponseType: "Reponse",
  29. ScriptPath: "/data/jmeter/log/test/ep/melloi/",
  30. JarPath: "/data/jmeter/log/test/ep/melloi/text.jar",
  31. ThreadsSum: 1,
  32. RampUp: 1,
  33. Loops: -1,
  34. LoadTime: 100,
  35. UpdateBy: "hujianping",
  36. IsDebug: 0,
  37. }
  38. qgr = model.QueryGRPCRequest{
  39. Executor: "hujianping",
  40. GRPC: grpc,
  41. }
  42. gasr = model.GRPCAddScriptRequest{
  43. TaskName: "testGrpc",
  44. Department: "test",
  45. Project: "ep",
  46. APP: "melloi",
  47. Active: 1,
  48. HostName: "172.22.33.22",
  49. Port: 9000,
  50. ServiceName: "Identify",
  51. ProtoClassName: "Api",
  52. PkgPath: "V1",
  53. RequestType: "GetCookieInfo",
  54. RequestMethod: "getCookieInfo",
  55. RequestContent: "{\"Cookie\":\"sid:1ers12;SETDATA:a18jds9234js9sfa24jsdf\"}",
  56. ResponseType: "Reponse",
  57. ScriptPath: "/data/jmeter/log/test/ep/melloi/",
  58. JarPath: "/data/jmeter/log/test/ep/melloi/text.jar",
  59. ThreadsSum: 1,
  60. RampUp: 1,
  61. Loops: -1,
  62. LoadTime: 100,
  63. UpdateBy: "hujianping",
  64. IsDebug: 0,
  65. }
  66. )
  67. func Test_Grpc(t *testing.T) {
  68. Convey("proto parse", t, func() {
  69. _, err := s.ProtoParsing(protoPath, protoFile)
  70. So(err, ShouldBeNil)
  71. })
  72. Convey("create proto dependency dir", t, func() {
  73. err := s.CreateProtoImportDir(&protoModel)
  74. So(err, ShouldBeNil)
  75. })
  76. Convey(" add grpc script", t, func() {
  77. _, err := s.GRPCAddScript(c, &gasr)
  78. So(err, ShouldBeNil)
  79. })
  80. Convey("create jmx file", t, func() {
  81. _, err := s.CreateJmx(c, &gasr)
  82. So(err, ShouldBeNil)
  83. })
  84. Convey("run by script", t, func() {
  85. cookie = "baf4dd3244116f492b71af3532cac03e"
  86. _, err := s.GRPCRunByScriptID(c, &scriptID, userName, cookie)
  87. So(err, ShouldBeNil)
  88. })
  89. Convey("query grpc", t, func() {
  90. _, err := s.QueryGrpc(c, "e2df43ed324d20811e8d1be1a9fb36d5", &qgr)
  91. So(err, ShouldBeNil)
  92. })
  93. Convey("run grpc by model", t, func() {
  94. cookie = "baf4dd3244116f492b71af3532cac03e"
  95. _, err := s.GRPCRunByModel(c, &grpc, userName, cookie)
  96. So(err, ShouldBeNil)
  97. })
  98. Convey("query grpc by id", t, func() {
  99. _, err := s.QueryGrpcById(grpc.ID)
  100. So(err, ShouldBeNil)
  101. })
  102. Convey("update grpc", t, func() {
  103. err := s.UpdateGrpc(&grpc)
  104. So(err, ShouldBeNil)
  105. })
  106. Convey("delete grpc", t, func() {
  107. err := s.DeleteGrpc(grpc.ID)
  108. So(err, ShouldBeNil)
  109. })
  110. Convey("create jmx file ", t, func() {
  111. _, err := s.createJmeterFile(&gasr)
  112. So(err, ShouldBeNil)
  113. })
  114. }