Skip to content

Commit

Permalink
[WIP] adding default parameters for grpc options
Browse files Browse the repository at this point in the history
  • Loading branch information
diegorubin committed Jun 23, 2020
1 parent e4ec417 commit c8e843d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/tshield/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class Configuration
#
attr_reader :request
attr_reader :domains
attr_reader :grpc
attr_reader :tcp_servers
attr_reader :session_path

Expand Down Expand Up @@ -104,6 +103,11 @@ def read_session_path
session_path || '/sessions'
end

def grpc
defaults = { 'port' => 5678, 'proto_dir' => 'proto', 'services' => {} }
defaults.merge(@grpc || {})
end

def self.get_url_for_domain_by_path(path, config)
config['paths'].select { |pattern| path =~ Regexp.new(pattern) }[0]
end
Expand Down
13 changes: 13 additions & 0 deletions spec/tshield/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,17 @@
expect { TShield::Configuration.singleton }.to raise_error RuntimeError
end
end

context 'on config exists without grpc entry' do
before :each do
options_instance = double
allow(options_instance).to receive(:configuration_file)
.and_return('spec/tshield/fixtures/config/tshield-without-grpc.yml')
allow(TShield::Options).to receive(:instance).and_return(options_instance)
@configuration = TShield::Configuration.singleton
end
it 'should set default value for port' do
expect(@configuration.grpc).to eql('port' => 5678, 'proto_dir' => 'proto', 'services' => {})
end
end
end

0 comments on commit c8e843d

Please sign in to comment.