Skip to content

Commit 007c7db

Browse files
committed
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 <hermionedadheech@gmail.com>
1 parent 0c38447 commit 007c7db

File tree

4 files changed

+253
-9
lines changed

4 files changed

+253
-9
lines changed

grpc.proto

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
syntax = "proto3";
2+
option java_package = "io.keploy.grpc.stubs";
3+
option go_package = "go.keploy.io/server/grpc/regression";
4+
package services;
5+
6+
message Dependency {
7+
string Name = 1;
8+
string Type = 2;
9+
map<string, string> Meta = 3;
10+
repeated DataBytes Data = 4;
11+
}
12+
13+
message DataBytes {
14+
bytes Bin = 1;
15+
}
16+
17+
message TestCaseReq {
18+
int64 Captured = 1;
19+
string AppID = 2;
20+
string URI = 3;
21+
HttpReq HttpReq = 4;
22+
HttpResp HttpResp = 5;
23+
repeated Dependency Dependency = 6;
24+
string TestCasePath = 7;
25+
string MockPath = 8;
26+
repeated Mock Mocks = 9;
27+
repeated string Remove = 10;
28+
map<string, string> Replace = 11;
29+
string Type = 12;
30+
GrpcReq GrpcReq = 13;
31+
GrpcResp GrpcResp = 14;
32+
}
33+
34+
35+
message TestReq {
36+
string ID = 1;
37+
string AppID = 2;
38+
string RunID = 3;
39+
HttpResp Resp = 4;
40+
string TestCasePath = 5;
41+
string MockPath = 6;
42+
string Type = 7;
43+
GrpcResp GrpcResp = 8;
44+
}
45+
46+
message TestCase {
47+
string id = 1;
48+
int64 created = 2;
49+
int64 updated = 3;
50+
int64 captured = 4;
51+
string CID = 5;
52+
string appID = 6;
53+
string URI = 7;
54+
HttpReq HttpReq = 8;
55+
HttpResp HttpResp = 9;
56+
repeated Dependency Deps = 10;
57+
map<string, StrArr> allKeys = 11;
58+
map<string, StrArr> anchors = 12;
59+
repeated string noise = 13;
60+
repeated Mock Mocks = 14;
61+
}
62+
63+
message Method {
64+
string Method = 1;
65+
}
66+
message HttpReq {
67+
string Method = 1;
68+
int64 ProtoMajor = 2;
69+
int64 ProtoMinor = 3;
70+
string URL = 4;
71+
map<string, string> URLParams = 5;
72+
map<string, StrArr> Header = 6;
73+
string Body = 7 [deprecated = true];
74+
bytes BodyData = 10;
75+
string Binary = 8;
76+
repeated FormData Form = 9;
77+
}
78+
79+
//for multipart request
80+
message FormData {
81+
string Key = 1; //partName
82+
repeated string Values = 2;
83+
repeated string Paths = 3;
84+
}
85+
86+
message StrArr {
87+
repeated string Value = 1;
88+
}
89+
90+
message HttpResp {
91+
int64 StatusCode = 1;
92+
map<string, StrArr> Header = 2;
93+
string Body = 3 [deprecated = true];
94+
bytes BodyData = 8;
95+
string StatusMessage = 4;
96+
int64 ProtoMajor = 5;
97+
int64 ProtoMinor = 6;
98+
string Binary = 7;
99+
}
100+
101+
message endRequest {
102+
string status = 1;
103+
string id = 2;
104+
}
105+
106+
message endResponse {
107+
string message = 1;
108+
}
109+
110+
message startRequest {
111+
string total = 1;
112+
string app = 2;
113+
string TestCasePath = 3;
114+
string MockPath = 4;
115+
}
116+
117+
message startResponse {
118+
string id = 1;
119+
}
120+
121+
message getTCRequest {
122+
string id = 1;
123+
string app = 2;
124+
}
125+
message getTCSRequest{
126+
string app = 1;
127+
string offset = 2;
128+
string limit = 3;
129+
string TestCasePath = 4;
130+
string MockPath = 5;
131+
}
132+
message getTCSResponse{
133+
repeated TestCase tcs = 1;
134+
bool eof = 2;
135+
}
136+
message postTCResponse{
137+
map<string, string> tcsId = 1;
138+
}
139+
message deNoiseResponse {
140+
string message = 1;
141+
}
142+
message testResponse{
143+
map<string, bool> pass = 1;
144+
}
145+
message GrpcReq {
146+
string Body = 1;
147+
string Method = 2;
148+
}
149+
message GrpcResp {
150+
string Body = 1;
151+
string Err = 2;
152+
}
153+
154+
message Mock {
155+
message Request {
156+
string Method = 1;
157+
int64 ProtoMajor = 2;
158+
int64 ProtoMinor = 3;
159+
string URL = 4;
160+
map<string, StrArr> Header = 5;
161+
string Body = 6;
162+
}
163+
message Object {
164+
string Type = 1;
165+
bytes Data = 2;
166+
}
167+
168+
string Version = 1;
169+
string Name = 2;
170+
string Kind = 3;
171+
message SpecSchema {
172+
map<string, string> Metadata = 1;
173+
repeated Object Objects = 2;
174+
HttpReq Req = 3;
175+
HttpResp Res = 4;
176+
repeated string Mocks = 5;
177+
map<string, StrArr> Assertions = 6;
178+
int64 Created = 7;
179+
// for sql
180+
string Type = 8;
181+
optional Table Table = 9;
182+
int64 Int = 10; // change it to rows commited
183+
repeated string Err = 11;
184+
GrpcReq GrpcRequest = 12;
185+
GrpcResp GrpcResp = 13;
186+
}
187+
SpecSchema Spec = 4;
188+
}
189+
190+
message Table{
191+
repeated SqlCol Cols = 1;
192+
repeated string Rows = 2;
193+
}
194+
195+
message SqlCol {
196+
string Name = 1;
197+
string Type = 2;
198+
//optional fields
199+
int64 Precision = 3;
200+
int64 Scale = 4;
201+
}
202+
203+
message PutMockReq {
204+
Mock Mock = 1;
205+
string Path = 2;
206+
repeated string Remove = 3;
207+
map<string, string> Replace = 4;
208+
}
209+
210+
message PutMockResp {
211+
int64 Inserted = 1;
212+
}
213+
214+
message GetMockReq {
215+
string Path = 1;
216+
string Name = 2;
217+
}
218+
219+
message getMockResp {
220+
repeated Mock Mocks = 1;
221+
}
222+
223+
message StartMockReq {
224+
string Path = 1;
225+
string Mode = 2;
226+
bool OverWrite = 3;
227+
string Name = 4;
228+
}
229+
230+
message StartMockResp {
231+
bool Exists = 1;
232+
}
233+
234+
service RegressionService{
235+
rpc End (endRequest) returns (endResponse);
236+
rpc Start (startRequest) returns (startResponse);
237+
rpc GetTC (getTCRequest) returns (TestCase);
238+
rpc GetTCS (getTCSRequest) returns (getTCSResponse);
239+
rpc PostTC (TestCaseReq) returns (postTCResponse);
240+
rpc DeNoise (TestReq) returns(deNoiseResponse);
241+
rpc Test (TestReq) returns (testResponse);
242+
rpc PutMock (PutMockReq) returns (PutMockResp);
243+
rpc GetMocks (GetMockReq) returns (getMockResp);
244+
rpc StartMocking (StartMockReq) returns (StartMockResp);
245+
}

mock/mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { createExecutionContext, getExecutionContext } from "../src/context";
88
import { startRecordingMocks } from "./utils";
99

1010
const PORT = 6789;
11-
const PROTO_FILE = "../proto/services.proto";
11+
const PROTO_FILE = "../../grpc.proto";
1212
const packageDef = protoLoader.loadSync(path.resolve(__dirname, PROTO_FILE));
1313
const grpcObj = grpc.loadPackageDefinition(
1414
packageDef

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"version": "1.0.0",
44
"main": "dist/src/index.js",
55
"files": [
6-
"dist"
6+
"dist",
7+
"grpc.proto"
78
],
89
"scripts": {
9-
"build": "tsc && yarn copy-files",
10+
"build": "tsc",
1011
"prepare": "npm run build",
11-
"commit": "cz",
12-
"copy-files":"copyfiles -u 1 ./proto/services.proto ./dist/proto/"
13-
},
12+
"commit": "cz"
13+
},
1414
"repository": "git@github.com:keploy/typescript-sdk.git",
1515
"author": "Rajat Sharma <lunasunkaiser@gmail.com>",
1616
"license": "MIT",
@@ -50,7 +50,6 @@
5050
"import-in-the-middle": "^1.3.4",
5151
"merge-descriptors": "^1.0.1",
5252
"node-fetch": "^2.6.7",
53-
"require-in-the-middle": "^5.1.0",
54-
"copyfiles": "^2.4.1"
53+
"require-in-the-middle": "^5.1.0"
5554
}
5655
}

src/keploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { StrArr } from "../proto/services/StrArr";
1515
import assert = require("assert");
1616
import { createExecutionContext, getExecutionContext } from "./context";
1717

18-
const PROTO_PATH = "../proto/services.proto";
18+
const PROTO_PATH = "../../grpc.proto";
1919
const packageDef = protoLoader.loadSync(path.resolve(__dirname, PROTO_PATH));
2020
const grpcObj = grpc.loadPackageDefinition(
2121
packageDef

0 commit comments

Comments
 (0)