| 1 |
# Copyright 2016 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 |
|
| 15 |
require 'spec_helper' |
| 16 |
require 'open3' |
| 17 |
require 'tmpdir' |
| 18 |
|
| 19 |
def can_run_codegen_check |
| 20 |
system('which grpc_ruby_plugin') && system('which protoc') |
| 21 |
end |
| 22 |
|
| 23 |
describe 'Ping protobuf code generation' do |
| 24 |
if !can_run_codegen_check |
| 25 |
skip 'protoc || grpc_ruby_plugin missing, cannot verify ping code-gen' |
| 26 |
else |
| 27 |
it 'should have the same content as created by code generation' do |
| 28 |
root_dir = File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..') |
| 29 |
|
| 30 |
# Get the current content |
| 31 |
service_path = File.join(root_dir, 'src', 'ruby', 'pb', 'grpc', |
| 32 |
'testing', 'duplicate', |
| 33 |
'echo_duplicate_services_pb.rb') |
| 34 |
want = nil |
| 35 |
File.open(service_path) { |f| want = f.read } |
| 36 |
|
| 37 |
# Regenerate it |
| 38 |
plugin, = Open3.capture2('which', 'grpc_ruby_plugin') |
| 39 |
plugin = plugin.strip |
| 40 |
got = nil |
| 41 |
Dir.mktmpdir do |tmp_dir| |
| 42 |
gen_out = File.join(tmp_dir, 'src', 'proto', 'grpc', 'testing', |
| 43 |
'duplicate', 'echo_duplicate_services_pb.rb') |
| 44 |
pid = spawn( |
| 45 |
'protoc', |
| 46 |
'-I.', |
| 47 |
'src/proto/grpc/testing/duplicate/echo_duplicate.proto', |
| 48 |
"--grpc_out=#{tmp_dir}", |
| 49 |
"--plugin=protoc-gen-grpc=#{plugin}", |
| 50 |
chdir: root_dir) |
| 51 |
Process.wait(pid) |
| 52 |
File.open(gen_out) { |f| got = f.read } |
| 53 |
end |
| 54 |
expect(got).to eq(want) |
| 55 |
end |
| 56 |
end |
| 57 |
end |