xref: /aosp_15_r20/external/grpc-grpc/src/ruby/end2end/package_with_underscore_test.rb (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1# Copyright 2018 gRPC authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15require 'open3'
16require 'tmpdir'
17
18def main
19  root_dir = File.join(File.dirname(__FILE__), '..', '..', '..')
20  pb_dir = File.join(root_dir, 'src', 'ruby', 'end2end', 'protos')
21
22  bins_dir = File.join(root_dir, 'cmake', 'build')
23  plugin = File.join(bins_dir, 'grpc_ruby_plugin')
24  protoc = File.join(bins_dir, 'third_party', 'protobuf', 'protoc')
25
26  got = nil
27
28  Dir.mktmpdir do |tmp_dir|
29    gen_out = File.join(tmp_dir, 'package_with_underscore', 'service_services_pb.rb')
30
31    pid = spawn(
32      protoc,
33      "--proto_path=#{pb_dir}",
34      'package_with_underscore/service.proto',
35      "--grpc_out=#{tmp_dir}",
36      "--plugin=protoc-gen-grpc=#{plugin}"
37    )
38    Process.waitpid2(pid)
39    File.open(gen_out) { |f| got = f.read }
40  end
41
42  correct_modularized_rpc = 'rpc :TestOne, ' \
43                            '::Grpc::Testing::PackageWithUnderscore::Data::Request, ' \
44                            '::Grpc::Testing::PackageWithUnderscore::Data::Response'
45
46  return if got.include?(correct_modularized_rpc)
47
48  fail 'generated file does not match with correct_modularized_rpc'
49end
50
51main
52