mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
add grpc server (#4758)
This commit is contained in:
parent
b17df4a78d
commit
6285ab8b0f
@ -30,6 +30,9 @@ In a second terminal run/debug/step through smoke tests
|
||||
# Run tests
|
||||
npm run test:smoke:dev
|
||||
|
||||
# Run individual tests
|
||||
npm run test:smoke:dev -- oauth
|
||||
|
||||
# Debug tests with playwright logs
|
||||
DEBUG=pw:api npm run test:smoke:dev
|
||||
|
||||
|
@ -7,14 +7,14 @@ resources:
|
||||
parentId: wrk_b7d0b61f8cc446f9972d4cc42cdf4e2b
|
||||
modified: 1651485249670
|
||||
created: 1651484553856
|
||||
url: grpc://grpcbin.test.k6.io:9000
|
||||
name: hello k6
|
||||
url: grpc://localhost:50051
|
||||
name: say hi!
|
||||
description: ""
|
||||
protoFileId: pf_ed00515515cd4d25bd71e9eab2cfd8ba
|
||||
protoMethodName: /hello.HelloService/SayHello
|
||||
metadata: []
|
||||
body:
|
||||
text: "{}"
|
||||
text: '{"greeting":"hi"}'
|
||||
metaSortKey: -1651484553856
|
||||
isPrivate: false
|
||||
_type: grpc_request
|
||||
|
38017
packages/insomnia-smoke-test/package-lock.json
generated
38017
packages/insomnia-smoke-test/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -23,11 +23,12 @@
|
||||
"test:build": "xvfb-maybe cross-env BUNDLE=build playwright test",
|
||||
"test:package": "xvfb-maybe cross-env BUNDLE=package playwright test",
|
||||
"cli": "jest --detectOpenHandles --testPathPattern cli",
|
||||
"serve": "ts-node server/index.ts",
|
||||
"with-mock": "concurrently --names server,app --success first --kill-others \"npm run serve\"",
|
||||
"test:cli": "npm run with-mock \"npm run cli\""
|
||||
"serve": "concurrently -n http,grpc \"ts-node server/index.ts\" \"ts-node server/grpc.ts\"",
|
||||
"test:cli": "concurrently --names server,cli --success first --kill-others \"ts-node server/index.ts\" \"npm run cli\""
|
||||
},
|
||||
"devDependencies": {
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"@grpc/proto-loader": "^0.6.11",
|
||||
"@playwright/test": "^1.20.2",
|
||||
"@types/concurrently": "^6.0.1",
|
||||
"@types/express": "^4.17.11",
|
||||
|
40
packages/insomnia-smoke-test/server/grpc.ts
Normal file
40
packages/insomnia-smoke-test/server/grpc.ts
Normal file
@ -0,0 +1,40 @@
|
||||
// inspiration: https://github.com/grpc/grpc/blob/e963544eef6a76f9f86d43418ee2ac57aebba6f6/examples/node/dynamic_codegen/greeter_server.js
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
import * as protoLoader from '@grpc/proto-loader';
|
||||
import path from 'path';
|
||||
|
||||
const PROTO_PATH = path.resolve('../../packages/insomnia/src/network/grpc/__fixtures__/library/hello.proto');
|
||||
const packageDefinition = protoLoader.loadSync(
|
||||
PROTO_PATH,
|
||||
{
|
||||
keepCase: true,
|
||||
longs: String,
|
||||
enums: String,
|
||||
defaults: true,
|
||||
oneofs: true,
|
||||
});
|
||||
|
||||
const helloProto = grpc.loadPackageDefinition(packageDefinition).hello;
|
||||
|
||||
/**
|
||||
* Implements the SayHello RPC method.
|
||||
*/
|
||||
function sayHello(call, callback) {
|
||||
callback(null, { reply: call.request.greeting });
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts an RPC server that receives requests for the Greeter service at the
|
||||
* sample server port
|
||||
*/
|
||||
function main() {
|
||||
const server = new grpc.Server();
|
||||
// @ts-expect-error generated from proto file
|
||||
server.addService(helloProto.HelloService.service, { sayHello: sayHello });
|
||||
server.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => {
|
||||
console.log('Listening at grpc://0.0.0.0:50051');
|
||||
server.start();
|
||||
});
|
||||
}
|
||||
|
||||
main();
|
@ -19,8 +19,8 @@ test('can send gRPC requests', async ({ app, page }) => {
|
||||
await page.click('button:has-text("Clipboard")');
|
||||
await page.click('text=CollectionSmoke gRPCjust now');
|
||||
|
||||
await page.click('button:has-text("gRPChello k6")');
|
||||
await page.click('button:has-text("gRPCsay hi!")');
|
||||
await page.click('text=Send');
|
||||
await expect(statusTag).toContainText('0 OK');
|
||||
await expect(responseBody).toContainText('hello noname');
|
||||
await expect(responseBody).toContainText('"reply": "hi"');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user