Skip to content

Commit

Permalink
fix(package.json, mock.ts, keploy.ts, grpc.proto): added proto file i…
Browse files Browse the repository at this point in the history
…n 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 <[email protected]>
  • Loading branch information
Hermione2408 committed Mar 1, 2023
1 parent 0c38447 commit 007c7db
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 9 deletions.
245 changes: 245 additions & 0 deletions grpc.proto
Original file line number Diff line number Diff line change
@@ -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<string, string> 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<string, string> 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<string, StrArr> allKeys = 11;
map<string, StrArr> 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<string, string> URLParams = 5;
map<string, StrArr> 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<string, StrArr> 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<string, string> tcsId = 1;
}
message deNoiseResponse {
string message = 1;
}
message testResponse{
map<string, bool> 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<string, StrArr> 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<string, string> Metadata = 1;
repeated Object Objects = 2;
HttpReq Req = 3;
HttpResp Res = 4;
repeated string Mocks = 5;
map<string, StrArr> 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<string, string> 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);
}
2 changes: 1 addition & 1 deletion mock/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]:keploy/typescript-sdk.git",
"author": "Rajat Sharma <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/keploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 007c7db

Please sign in to comment.