1# Copyright 2017 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. 14require 'spec_helper' 15 16describe GRPC::InterceptorRegistry do 17 let(:server) { new_rpc_server_for_testing } 18 let(:interceptor) { TestServerInterceptor.new } 19 let(:interceptors) { [interceptor] } 20 let(:registry) { described_class.new(interceptors) } 21 22 describe 'initialization' do 23 subject { registry } 24 25 context 'with an interceptor extending GRPC::ServerInterceptor' do 26 it 'should add the interceptor to the registry' do 27 subject 28 is = registry.instance_variable_get('@interceptors') 29 expect(is.count).to eq 1 30 expect(is.first).to eq interceptor 31 end 32 end 33 34 context 'with multiple interceptors' do 35 let(:interceptor2) { TestServerInterceptor.new } 36 let(:interceptor3) { TestServerInterceptor.new } 37 let(:interceptors) { [interceptor, interceptor2, interceptor3] } 38 39 it 'should maintain order of insertion when iterated against' do 40 subject 41 is = registry.instance_variable_get('@interceptors') 42 expect(is.count).to eq 3 43 is.each_with_index do |i, idx| 44 case idx 45 when 0 46 expect(i).to eq interceptor 47 when 1 48 expect(i).to eq interceptor2 49 when 2 50 expect(i).to eq interceptor3 51 end 52 end 53 end 54 end 55 56 context 'with an interceptor not extending GRPC::ServerInterceptor' do 57 let(:interceptor) { Class } 58 let(:err) { GRPC::InterceptorRegistry::DescendantError } 59 60 it 'should raise an InvalidArgument exception' do 61 expect { subject }.to raise_error(err) 62 end 63 end 64 end 65end 66