Skip to content

Commit

Permalink
fix: make sure the order of protos is fixed (#216)
Browse files Browse the repository at this point in the history
Co-authored-by: Justin Beckwith <justin.beckwith@gmail.com>
  • Loading branch information
alexander-fenster and JustinBeckwith committed Feb 1, 2020
1 parent 7ea7034 commit b42d6db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
8 changes: 5 additions & 3 deletions typescript/src/schema/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,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,
' '
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
]
23 changes: 23 additions & 0 deletions typescript/test/unit/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
});
});

0 comments on commit b42d6db

Please sign in to comment.