Skip to content

Commit

Permalink
grpc-loader: add method options test
Browse files Browse the repository at this point in the history
  • Loading branch information
hiepthai authored and n0v1 committed Apr 5, 2024
1 parent fc9db76 commit dfb10f9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/proto-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions packages/proto-loader/test/descriptor_type_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/`;
Expand Down Expand Up @@ -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'
})
})
});
25 changes: 25 additions & 0 deletions packages/proto-loader/test_protos/method_options.proto
Original file line number Diff line number Diff line change
@@ -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';
}
}

0 comments on commit dfb10f9

Please sign in to comment.