/
hello_pact_grpc.ts
67 lines (56 loc) · 2.07 KB
/
hello_pact_grpc.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
60
61
62
63
64
65
66
67
import { DenoPact } from "./deno-pact.ts";
import { getShapeMessage } from "./gRPC/area_calculator/areaCalculatorClient.ts";
import * as path from "https://deno.land/std/path/mod.ts";
const main = async () => {
// Setup
const version = DenoPact.getFFIVersion();
DenoPact.setupLoggers(3);
// Arrange
console.log('area calc proto path')
console.log(path.join(Deno.cwd(),'proto','area_calculator.proto'))
const protoPath = path.join(Deno.cwd(),'proto','area_calculator.proto')
const pact_contents = {
"pact:proto": protoPath,
"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)"] }
};
const pact = DenoPact.newPact("consumer-test", "provider-test");
DenoPact.addMetaDataToPact(pact, version);
const message_pact = DenoPact.newSyncMessageInteraction(
pact,
"A gRPC calculateOne request"
);
DenoPact.setPactSpecification(pact, 5);
DenoPact.usingPactPlugin(pact, "protobuf");
DenoPact.withInteractionContents(message_pact, 0, "application/grpc", pact_contents);
// # Start mock server
const mock_server_port = DenoPact.createMockServerForTransport(pact, "grpc");
DenoPact.logMessage(
"pactffi_create_mock_server_for_transport: running on port " +
mock_server_port
);
// Act
const results = await getShapeMessage(mock_server_port);
console.log(results);
// Assert
const matches = DenoPact.checkMatches(mock_server_port);
if (!matches) {
console.log("✅ tests passed 👌");
DenoPact.writePactFiles(mock_server_port, "./pacts");
}
// Cleanup
DenoPact.cleanupMockServer(mock_server_port);
if (matches) {
console.log("🚨 tests failed, check out the errors below 👇");
console.log(JSON.stringify(JSON.parse(matches), null, "\t"));
}
DenoPact.cleanupPlugins(pact);
console.log("🧹 Cleaned up Pact processes");
};
console.log("🚀 Running Pact Protobuf Plugin Test with gRPC 🚀");
await main();
export {};