Skip to content

Commit

Permalink
Merge pull request #10 from theckman/add_ip4addr_option
Browse files Browse the repository at this point in the history
add support for custom IPv4 address in TunnelBroker::Messenger
  • Loading branch information
theckman committed Apr 7, 2014
2 parents 05bcd82 + 33c09a9 commit 9eef38e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/tunnelbroker/messenger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def call_endpoint
query = {
username: @username, password: @update_key, hostname: @tunnelid
}
query.merge!(myip: @ip4addr) if defined?(@ip4addr)
self.class.get(@url, basic_auth: auth, query: query)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tunnelbroker/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
# The TunnelBroker API client namespace.
#
module TunnelBroker
VERSION ||= '0.0.4'
VERSION ||= '0.0.5'
end
52 changes: 38 additions & 14 deletions spec/unit/tunnelbroker/messenger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,6 @@
end

describe '.call_endpoint' do
before do
allow(TunnelBroker::Messenger).to receive(:get).with(
'test1',
basic_auth: {
username: @opts[:username], password: @opts[:update_key]
},
query: {
username: @opts[:username], password: @opts[:update_key],
hostname: @opts[:tunnelid]
}
).and_return('success!')
end

context 'when given more than one arg' do
it 'should raise ArgumentError' do
expect do
Expand All @@ -94,11 +81,48 @@
end
end

context 'when called with no arguments' do
context 'when called with no arguments and no @ipv4addr' do
before do
allow(TunnelBroker::Messenger).to receive(:get).with(
'test1',
basic_auth: {
username: @opts[:username], password: @opts[:update_key]
},
query: {
username: @opts[:username], password: @opts[:update_key],
hostname: @opts[:tunnelid]
}
).and_return('success!')
end

subject { @messenger.send(:call_endpoint) }

it { should eql 'success!' }
end

context 'when called with no arguments and with @ipv4addr' do
before do
@opts1 = {
url: 'test1', username: 'test2', update_key: 'test3',
tunnelid: 'test4', ip4addr: 'test5'
}
@messenger1 = TunnelBroker::Messenger.new(@opts1)
allow(TunnelBroker::Messenger).to receive(:get).with(
'test1',
basic_auth: {
username: @opts1[:username], password: @opts1[:update_key]
},
query: {
username: @opts1[:username], password: @opts1[:update_key],
hostname: @opts1[:tunnelid], myip: 'test5'
}
).and_return('success2!')
end

subject { @messenger1.send(:call_endpoint) }

it { should eql 'success2!' }
end
end

describe '.call_api' do
Expand Down

0 comments on commit 9eef38e

Please sign in to comment.