-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
grpc.consumer.spec.ts
59 lines (55 loc) · 1.96 KB
/
grpc.consumer.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* tslint:disable:no-unused-expression no-empty */
import chai from "chai";
import chaiAsPromised from "chai-as-promised";
import { SpecificationVersion, PactV4, LogLevel } from "@pact-foundation/pact";
import { client, getShapeMessage } from "../consumer";
import * as path from "path";
chai.use(chaiAsPromised);
const { expect } = chai;
describe("Plugins - grpc Protocol", () => {
describe("TCP interface", () => {
const pact = new PactV4({
consumer: "area-calculator-consumer-js",
provider: "area-calculator-provider",
spec: SpecificationVersion.SPECIFICATION_VERSION_V4,
logLevel: (process.env.LOG_LEVEL as LogLevel) || "error",
});
const HOST = "127.0.0.1";
describe("with grpc protocol", async () => {
it("generates a pact with success", () => {
const grpcMessage = {
"pact:proto": path.resolve("./proto/area_calculator.proto"),
"pact:proto-service": "Calculator/calculateOne",
"pact:content-type": "application/protobuf",
request: {
rectangle: {
length: "matching(number, 3)",
width: "matching(number, 4)",
},
},
response: { value: ["matching(number, 12)"] },
};
return pact
.addSynchronousInteraction("A gRPC calculateOne request")
.usingPlugin({
plugin: "protobuf",
version: "0.3.13",
})
.withPluginContents(JSON.stringify(grpcMessage), "application/grpc")
.startTransport("grpc", HOST)
.executeTest(async (tc) => {
const delay = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
const grpcClient = client([HOST, tc.port].join(":"));
getShapeMessage(grpcClient, {
rectangle: {
length: 8,
width: 4,
},
});
return await delay(1000);
});
});
});
});
});