forked from sous-chefs/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sous-chefs#1042 from smcavallo/network_alias_fix
fix issues with network_mode
- Loading branch information
Showing
2 changed files
with
83 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Load all the libraries | ||
require 'chef' | ||
require 'docker' | ||
Dir['libraries/*.rb'].each { |f| require File.expand_path(f) } | ||
|
||
describe DockerCookbook::DockerContainer do | ||
let(:resource) { DockerCookbook::DockerContainer.new('hello_world') } | ||
|
||
it 'has a default action of [:run]' do | ||
expect(resource.action).to eql([:run]) | ||
end | ||
|
||
describe 'gets ip_address_from_container_networks' do | ||
let(:options) { { 'id' => rand(10_000).to_s } } | ||
subject do | ||
Docker::Container.send(:new, Docker.connection, options) | ||
end | ||
# https://docs.docker.com/engine/api/version-history/#v121-api-changes | ||
context 'when docker API < 1.21' do | ||
let(:ip_address) { '10.0.0.1' } | ||
let(:options) do | ||
{ | ||
'id' => rand(10_000).to_s, | ||
'IPAddress' => ip_address | ||
} | ||
end | ||
it 'gets ip_address as nil' do | ||
actual = resource.ip_address_from_container_networks(subject) | ||
expect { resource.ip_address_from_container_networks(subject) }.not_to raise_error | ||
expect(actual).to eq(nil) | ||
end | ||
end | ||
context 'when docker API > 1.21' do | ||
let(:ip_address) { '10.0.0.1' } | ||
let(:options) do | ||
{ | ||
'id' => rand(10_000).to_s, | ||
'NetworkSettings' => { | ||
'Networks' => { | ||
'bridge' => { | ||
'IPAMConfig' => { | ||
'IPv4Address' => ip_address | ||
} | ||
} | ||
} | ||
} | ||
} | ||
end | ||
it 'gets ip_address' do | ||
actual = resource.ip_address_from_container_networks(subject) | ||
expect(actual).to eq(ip_address) | ||
end | ||
end | ||
end | ||
end |