grpc-loader: add method options test

This commit is contained in:
Hiep Thai 2022-09-21 10:47:27 +07:00 committed by Christopher Fenn
parent fc9db761a9
commit dfb10f9ac4
3 changed files with 43 additions and 0 deletions

View File

@ -57,6 +57,7 @@
"@types/node": "^10.17.26",
"@types/yargs": "^17.0.24",
"clang-format": "^1.2.2",
"google-proto-files": "^3.0.2",
"gts": "^3.1.0",
"rimraf": "^3.0.2",
"ts-node": "^10.9.2",

View File

@ -20,6 +20,7 @@ import { rpcFileDescriptorSet } from '../test_protos/rpc.desc';
import { readFileSync } from 'fs';
import * as proto_loader from '../src/index';
import { dirname } from "path";
// Relative path from build output directory to test_protos directory
const TEST_PROTO_DIR = `${__dirname}/../../test_protos/`;
@ -128,4 +129,20 @@ describe('Descriptor types', () => {
// This will throw if the file descriptor object cannot be parsed
proto_loader.loadFileDescriptorSetFromObject(rpcFileDescriptorSet);
});
it('Can parse method options into object correctly', () => {
const includeDirs = [
dirname(require.resolve('google-proto-files/package.json'))
];
const packageDefinition = proto_loader.loadSync(`${TEST_PROTO_DIR}/method_options.proto`, { includeDirs });
assert('Hello' in packageDefinition);
const service = packageDefinition.Hello as proto_loader.ServiceDefinition
assert.deepStrictEqual(service.Hello.options, {
deprecated: true,
idempotency_level: 'IDEMPOTENCY_UNKNOWN',
uninterpreted_option: { identifier_value: 'foo' },
'(google.api.http)': { post: '/hello' },
'(google.api.method_signature)': 'bar'
})
})
});

View File

@ -0,0 +1,25 @@
syntax = "proto3";
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/httpbody.proto";
message Empty {}
message MethodSignature {
repeated string method_signature = 0;
}
service Hello {
rpc Hello (Empty) returns (Empty) {
option deprecated = true;
option idempotency_level = IDEMPOTENCY_UNKNOWN;
option uninterpreted_option = {
identifier_value: 'foo'
};
option (google.api.http) = {
post: "/hello"
};
option (google.api.method_signature) = 'bar';
}
}