From a78de98a877959ab6032648959abd618f7a66501 Mon Sep 17 00:00:00 2001 From: Hermione Dadheech Date: Wed, 1 Mar 2023 19:34:22 +0530 Subject: [PATCH 1/3] fix(sdk build, package.json): added a copy-files script which is OS independent Previously we were using cp command to copy services.proto file from proto folder to dist folder but cp command doesnt work for windows and hence the build fails in windows. I added "copy-files" script which uses copyfiles npm module to copy proto file and is OS independent. fix #51 Signed-off-by: Hermione Dadheech --- package.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8ea57c5..6c59d27 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,10 @@ "dist" ], "scripts": { - "build": "tsc && cp ./proto/services.proto ./dist/proto/", + "build": "tsc && yarn copy-files", "prepare": "npm run build", - "commit": "cz" + "commit": "cz", + "copy-files":"copyfiles -u 1 ./proto/services.proto ./dist/proto/" }, "repository": "git@github.com:keploy/typescript-sdk.git", "author": "Rajat Sharma ", @@ -49,6 +50,7 @@ "import-in-the-middle": "^1.3.4", "merge-descriptors": "^1.0.1", "node-fetch": "^2.6.7", - "require-in-the-middle": "^5.1.0" + "require-in-the-middle": "^5.1.0", + "copyfiles": "^2.4.1" } } From 71a5fc7c3badab4cd91477b45a983c1b29517269 Mon Sep 17 00:00:00 2001 From: Hermione Dadheech Date: Thu, 2 Mar 2023 00:30:13 +0530 Subject: [PATCH 2/3] fix(package.json, mock.ts, keploy.ts, grpc.proto): added proto file in build for grpc connection Added .proto file as a part of build file and used it in grpc connection. fix #51 Signed-off-by: Hermione Dadheech --- grpc.proto | 245 ++++++++++++++++++++++++++++++++++++++++++++++++++ mock/mock.ts | 2 +- package.json | 13 ++- src/keploy.ts | 2 +- 4 files changed, 253 insertions(+), 9 deletions(-) create mode 100644 grpc.proto diff --git a/grpc.proto b/grpc.proto new file mode 100644 index 0000000..9526307 --- /dev/null +++ b/grpc.proto @@ -0,0 +1,245 @@ +syntax = "proto3"; +option java_package = "io.keploy.grpc.stubs"; +option go_package = "go.keploy.io/server/grpc/regression"; +package services; + +message Dependency { + string Name = 1; + string Type = 2; + map Meta = 3; + repeated DataBytes Data = 4; +} + +message DataBytes { + bytes Bin = 1; +} + +message TestCaseReq { + int64 Captured = 1; + string AppID = 2; + string URI = 3; + HttpReq HttpReq = 4; + HttpResp HttpResp = 5; + repeated Dependency Dependency = 6; + string TestCasePath = 7; + string MockPath = 8; + repeated Mock Mocks = 9; + repeated string Remove = 10; + map Replace = 11; + string Type = 12; + GrpcReq GrpcReq = 13; + GrpcResp GrpcResp = 14; +} + + +message TestReq { + string ID = 1; + string AppID = 2; + string RunID = 3; + HttpResp Resp = 4; + string TestCasePath = 5; + string MockPath = 6; + string Type = 7; + GrpcResp GrpcResp = 8; +} + +message TestCase { + string id = 1; + int64 created = 2; + int64 updated = 3; + int64 captured = 4; + string CID = 5; + string appID = 6; + string URI = 7; + HttpReq HttpReq = 8; + HttpResp HttpResp = 9; + repeated Dependency Deps = 10; + map allKeys = 11; + map anchors = 12; + repeated string noise = 13; + repeated Mock Mocks = 14; +} + +message Method { + string Method = 1; +} +message HttpReq { + string Method = 1; + int64 ProtoMajor = 2; + int64 ProtoMinor = 3; + string URL = 4; + map URLParams = 5; + map Header = 6; + string Body = 7 [deprecated = true]; + bytes BodyData = 10; + string Binary = 8; + repeated FormData Form = 9; +} + +//for multipart request +message FormData { + string Key = 1; //partName + repeated string Values = 2; + repeated string Paths = 3; +} + +message StrArr { + repeated string Value = 1; +} + +message HttpResp { + int64 StatusCode = 1; + map Header = 2; + string Body = 3 [deprecated = true]; + bytes BodyData = 8; + string StatusMessage = 4; + int64 ProtoMajor = 5; + int64 ProtoMinor = 6; + string Binary = 7; +} + +message endRequest { + string status = 1; + string id = 2; +} + +message endResponse { + string message = 1; +} + +message startRequest { + string total = 1; + string app = 2; + string TestCasePath = 3; + string MockPath = 4; +} + +message startResponse { + string id = 1; +} + +message getTCRequest { + string id = 1; + string app = 2; +} +message getTCSRequest{ + string app = 1; + string offset = 2; + string limit = 3; + string TestCasePath = 4; + string MockPath = 5; +} +message getTCSResponse{ + repeated TestCase tcs = 1; + bool eof = 2; +} +message postTCResponse{ + map tcsId = 1; +} +message deNoiseResponse { + string message = 1; +} +message testResponse{ + map pass = 1; +} +message GrpcReq { + string Body = 1; + string Method = 2; +} +message GrpcResp { + string Body = 1; + string Err = 2; +} + +message Mock { + message Request { + string Method = 1; + int64 ProtoMajor = 2; + int64 ProtoMinor = 3; + string URL = 4; + map Header = 5; + string Body = 6; + } + message Object { + string Type = 1; + bytes Data = 2; + } + + string Version = 1; + string Name = 2; + string Kind = 3; + message SpecSchema { + map Metadata = 1; + repeated Object Objects = 2; + HttpReq Req = 3; + HttpResp Res = 4; + repeated string Mocks = 5; + map Assertions = 6; + int64 Created = 7; + // for sql + string Type = 8; + optional Table Table = 9; + int64 Int = 10; // change it to rows commited + repeated string Err = 11; + GrpcReq GrpcRequest = 12; + GrpcResp GrpcResp = 13; + } + SpecSchema Spec = 4; +} + +message Table{ + repeated SqlCol Cols = 1; + repeated string Rows = 2; +} + +message SqlCol { + string Name = 1; + string Type = 2; + //optional fields + int64 Precision = 3; + int64 Scale = 4; +} + +message PutMockReq { + Mock Mock = 1; + string Path = 2; + repeated string Remove = 3; + map Replace = 4; +} + +message PutMockResp { + int64 Inserted = 1; +} + +message GetMockReq { + string Path = 1; + string Name = 2; +} + +message getMockResp { + repeated Mock Mocks = 1; +} + +message StartMockReq { + string Path = 1; + string Mode = 2; + bool OverWrite = 3; + string Name = 4; +} + +message StartMockResp { + bool Exists = 1; +} + +service RegressionService{ + rpc End (endRequest) returns (endResponse); + rpc Start (startRequest) returns (startResponse); + rpc GetTC (getTCRequest) returns (TestCase); + rpc GetTCS (getTCSRequest) returns (getTCSResponse); + rpc PostTC (TestCaseReq) returns (postTCResponse); + rpc DeNoise (TestReq) returns(deNoiseResponse); + rpc Test (TestReq) returns (testResponse); + rpc PutMock (PutMockReq) returns (PutMockResp); + rpc GetMocks (GetMockReq) returns (getMockResp); + rpc StartMocking (StartMockReq) returns (StartMockResp); +} \ No newline at end of file diff --git a/mock/mock.ts b/mock/mock.ts index 3c8cfc9..2de6c14 100644 --- a/mock/mock.ts +++ b/mock/mock.ts @@ -8,7 +8,7 @@ import { createExecutionContext, getExecutionContext } from "../src/context"; import { startRecordingMocks } from "./utils"; const PORT = 6789; -const PROTO_FILE = "../proto/services.proto"; +const PROTO_FILE = "../../grpc.proto"; const packageDef = protoLoader.loadSync(path.resolve(__dirname, PROTO_FILE)); const grpcObj = grpc.loadPackageDefinition( packageDef diff --git a/package.json b/package.json index 6c59d27..7d9d17a 100644 --- a/package.json +++ b/package.json @@ -3,14 +3,14 @@ "version": "1.0.0", "main": "dist/src/index.js", "files": [ - "dist" + "dist", + "grpc.proto" ], "scripts": { - "build": "tsc && yarn copy-files", + "build": "tsc", "prepare": "npm run build", - "commit": "cz", - "copy-files":"copyfiles -u 1 ./proto/services.proto ./dist/proto/" - }, + "commit": "cz" + }, "repository": "git@github.com:keploy/typescript-sdk.git", "author": "Rajat Sharma ", "license": "MIT", @@ -50,7 +50,6 @@ "import-in-the-middle": "^1.3.4", "merge-descriptors": "^1.0.1", "node-fetch": "^2.6.7", - "require-in-the-middle": "^5.1.0", - "copyfiles": "^2.4.1" + "require-in-the-middle": "^5.1.0" } } diff --git a/src/keploy.ts b/src/keploy.ts index 1de2cca..6d424c7 100644 --- a/src/keploy.ts +++ b/src/keploy.ts @@ -15,7 +15,7 @@ import { StrArr } from "../proto/services/StrArr"; import assert = require("assert"); import { createExecutionContext, getExecutionContext } from "./context"; -const PROTO_PATH = "../proto/services.proto"; +const PROTO_PATH = "../../grpc.proto"; const packageDef = protoLoader.loadSync(path.resolve(__dirname, PROTO_PATH)); const grpcObj = grpc.loadPackageDefinition( packageDef From 4b580a2a060144907c68ab66d5b08f69edcdb0e0 Mon Sep 17 00:00:00 2001 From: Hermione Dadheech Date: Fri, 3 Mar 2023 01:38:41 +0530 Subject: [PATCH 3/3] fix: adding serives.proto instead of new grpc.proto fix #51 Signed-off-by: Hermione Dadheech --- grpc.proto | 245 -------------------------------------------------- mock/mock.ts | 2 +- package.json | 2 +- src/keploy.ts | 2 +- 4 files changed, 3 insertions(+), 248 deletions(-) delete mode 100644 grpc.proto diff --git a/grpc.proto b/grpc.proto deleted file mode 100644 index 9526307..0000000 --- a/grpc.proto +++ /dev/null @@ -1,245 +0,0 @@ -syntax = "proto3"; -option java_package = "io.keploy.grpc.stubs"; -option go_package = "go.keploy.io/server/grpc/regression"; -package services; - -message Dependency { - string Name = 1; - string Type = 2; - map Meta = 3; - repeated DataBytes Data = 4; -} - -message DataBytes { - bytes Bin = 1; -} - -message TestCaseReq { - int64 Captured = 1; - string AppID = 2; - string URI = 3; - HttpReq HttpReq = 4; - HttpResp HttpResp = 5; - repeated Dependency Dependency = 6; - string TestCasePath = 7; - string MockPath = 8; - repeated Mock Mocks = 9; - repeated string Remove = 10; - map Replace = 11; - string Type = 12; - GrpcReq GrpcReq = 13; - GrpcResp GrpcResp = 14; -} - - -message TestReq { - string ID = 1; - string AppID = 2; - string RunID = 3; - HttpResp Resp = 4; - string TestCasePath = 5; - string MockPath = 6; - string Type = 7; - GrpcResp GrpcResp = 8; -} - -message TestCase { - string id = 1; - int64 created = 2; - int64 updated = 3; - int64 captured = 4; - string CID = 5; - string appID = 6; - string URI = 7; - HttpReq HttpReq = 8; - HttpResp HttpResp = 9; - repeated Dependency Deps = 10; - map allKeys = 11; - map anchors = 12; - repeated string noise = 13; - repeated Mock Mocks = 14; -} - -message Method { - string Method = 1; -} -message HttpReq { - string Method = 1; - int64 ProtoMajor = 2; - int64 ProtoMinor = 3; - string URL = 4; - map URLParams = 5; - map Header = 6; - string Body = 7 [deprecated = true]; - bytes BodyData = 10; - string Binary = 8; - repeated FormData Form = 9; -} - -//for multipart request -message FormData { - string Key = 1; //partName - repeated string Values = 2; - repeated string Paths = 3; -} - -message StrArr { - repeated string Value = 1; -} - -message HttpResp { - int64 StatusCode = 1; - map Header = 2; - string Body = 3 [deprecated = true]; - bytes BodyData = 8; - string StatusMessage = 4; - int64 ProtoMajor = 5; - int64 ProtoMinor = 6; - string Binary = 7; -} - -message endRequest { - string status = 1; - string id = 2; -} - -message endResponse { - string message = 1; -} - -message startRequest { - string total = 1; - string app = 2; - string TestCasePath = 3; - string MockPath = 4; -} - -message startResponse { - string id = 1; -} - -message getTCRequest { - string id = 1; - string app = 2; -} -message getTCSRequest{ - string app = 1; - string offset = 2; - string limit = 3; - string TestCasePath = 4; - string MockPath = 5; -} -message getTCSResponse{ - repeated TestCase tcs = 1; - bool eof = 2; -} -message postTCResponse{ - map tcsId = 1; -} -message deNoiseResponse { - string message = 1; -} -message testResponse{ - map pass = 1; -} -message GrpcReq { - string Body = 1; - string Method = 2; -} -message GrpcResp { - string Body = 1; - string Err = 2; -} - -message Mock { - message Request { - string Method = 1; - int64 ProtoMajor = 2; - int64 ProtoMinor = 3; - string URL = 4; - map Header = 5; - string Body = 6; - } - message Object { - string Type = 1; - bytes Data = 2; - } - - string Version = 1; - string Name = 2; - string Kind = 3; - message SpecSchema { - map Metadata = 1; - repeated Object Objects = 2; - HttpReq Req = 3; - HttpResp Res = 4; - repeated string Mocks = 5; - map Assertions = 6; - int64 Created = 7; - // for sql - string Type = 8; - optional Table Table = 9; - int64 Int = 10; // change it to rows commited - repeated string Err = 11; - GrpcReq GrpcRequest = 12; - GrpcResp GrpcResp = 13; - } - SpecSchema Spec = 4; -} - -message Table{ - repeated SqlCol Cols = 1; - repeated string Rows = 2; -} - -message SqlCol { - string Name = 1; - string Type = 2; - //optional fields - int64 Precision = 3; - int64 Scale = 4; -} - -message PutMockReq { - Mock Mock = 1; - string Path = 2; - repeated string Remove = 3; - map Replace = 4; -} - -message PutMockResp { - int64 Inserted = 1; -} - -message GetMockReq { - string Path = 1; - string Name = 2; -} - -message getMockResp { - repeated Mock Mocks = 1; -} - -message StartMockReq { - string Path = 1; - string Mode = 2; - bool OverWrite = 3; - string Name = 4; -} - -message StartMockResp { - bool Exists = 1; -} - -service RegressionService{ - rpc End (endRequest) returns (endResponse); - rpc Start (startRequest) returns (startResponse); - rpc GetTC (getTCRequest) returns (TestCase); - rpc GetTCS (getTCSRequest) returns (getTCSResponse); - rpc PostTC (TestCaseReq) returns (postTCResponse); - rpc DeNoise (TestReq) returns(deNoiseResponse); - rpc Test (TestReq) returns (testResponse); - rpc PutMock (PutMockReq) returns (PutMockResp); - rpc GetMocks (GetMockReq) returns (getMockResp); - rpc StartMocking (StartMockReq) returns (StartMockResp); -} \ No newline at end of file diff --git a/mock/mock.ts b/mock/mock.ts index 2de6c14..26aeb87 100644 --- a/mock/mock.ts +++ b/mock/mock.ts @@ -8,7 +8,7 @@ import { createExecutionContext, getExecutionContext } from "../src/context"; import { startRecordingMocks } from "./utils"; const PORT = 6789; -const PROTO_FILE = "../../grpc.proto"; +const PROTO_FILE = "../../proto/services.proto"; const packageDef = protoLoader.loadSync(path.resolve(__dirname, PROTO_FILE)); const grpcObj = grpc.loadPackageDefinition( packageDef diff --git a/package.json b/package.json index 7d9d17a..c6945ba 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "main": "dist/src/index.js", "files": [ "dist", - "grpc.proto" + "proto/services.proto" ], "scripts": { "build": "tsc", diff --git a/src/keploy.ts b/src/keploy.ts index 6d424c7..b599054 100644 --- a/src/keploy.ts +++ b/src/keploy.ts @@ -15,7 +15,7 @@ import { StrArr } from "../proto/services/StrArr"; import assert = require("assert"); import { createExecutionContext, getExecutionContext } from "./context"; -const PROTO_PATH = "../../grpc.proto"; +const PROTO_PATH = "../../proto/services.proto"; const packageDef = protoLoader.loadSync(path.resolve(__dirname, PROTO_PATH)); const grpcObj = grpc.loadPackageDefinition( packageDef