From e79ec9a16025066c0b65e6380f4e20896b9ffcfb Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Wed, 29 Jan 2020 12:16:50 -0800 Subject: [PATCH] fix: make sure the order of protos is fixed --- typescript/src/schema/api.ts | 8 ++++--- .../v2/dlp_service_proto_list.json.baseline | 4 ++-- typescript/test/unit/api.ts | 23 +++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/typescript/src/schema/api.ts b/typescript/src/schema/api.ts index 154b6c7db..e00e41a92 100644 --- a/typescript/src/schema/api.ts +++ b/typescript/src/schema/api.ts @@ -120,9 +120,11 @@ export class API { get protoFilesToGenerateJSON() { return JSON.stringify( - this.filesToGenerate.map(file => { - return `../../protos/${file}`; - }), + this.filesToGenerate + .map(file => { + return `../../protos/${file}`; + }) + .sort(), null, ' ' ); diff --git a/typescript/test/testdata/dlp/src/v2/dlp_service_proto_list.json.baseline b/typescript/test/testdata/dlp/src/v2/dlp_service_proto_list.json.baseline index 8e267f82e..482924bde 100644 --- a/typescript/test/testdata/dlp/src/v2/dlp_service_proto_list.json.baseline +++ b/typescript/test/testdata/dlp/src/v2/dlp_service_proto_list.json.baseline @@ -1,4 +1,4 @@ [ - "../../protos/google/privacy/dlp/v2/storage.proto", - "../../protos/google/privacy/dlp/v2/dlp.proto" + "../../protos/google/privacy/dlp/v2/dlp.proto", + "../../protos/google/privacy/dlp/v2/storage.proto" ] diff --git a/typescript/test/unit/api.ts b/typescript/test/unit/api.ts index 6954172e1..cdd2e53be 100644 --- a/typescript/test/unit/api.ts +++ b/typescript/test/unit/api.ts @@ -109,4 +109,27 @@ describe('schema/api.ts', () => { }); assert.deepStrictEqual(api.mainServiceName, 'OverriddenName'); }); + + it('should return list of protos in lexicographical order', () => { + const fd1 = new plugin.google.protobuf.FileDescriptorProto(); + fd1.name = 'google/cloud/example/v1/test.proto'; + fd1.package = 'google.cloud.example.v1'; + + fd1.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; + fd1.service[0].name = 'Service'; + fd1.service[0].options = { + '.google.api.defaultHost': 'hostname.example.com:443', + }; + const fd2 = new plugin.google.protobuf.FileDescriptorProto(); + fd2.name = 'google/cloud/example/v1/example.proto'; + fd2.package = 'google.cloud.example.v1'; + fd2.service = []; + const api = new API([fd1, fd2], 'google.cloud.example.v1', { + grpcServiceConfig: new plugin.grpc.service_config.ServiceConfig(), + }); + assert.deepStrictEqual(JSON.parse(api.protoFilesToGenerateJSON), [ + '../../protos/google/cloud/example/v1/example.proto', + '../../protos/google/cloud/example/v1/test.proto', + ]); + }); });