spec/beaker/hypervisor/docker_spec.rb in beaker-2.25.0 vs spec/beaker/hypervisor/docker_spec.rb in beaker-2.26.0
- old
+ new
@@ -37,10 +37,13 @@
let(:container) do
container = double('Docker::Container')
allow( container ).to receive(:id)
allow( container ).to receive(:start)
+ allow( container ).to receive(:info).and_return(
+ *(0..2).map { |index| { 'Names' => ["/spec-container-#{index}"] } }
+ )
allow( container ).to receive(:json).and_return({
'NetworkSettings' => {
'IPAddress' => '192.0.2.1',
'Ports' => {
'22/tcp' => [
@@ -155,9 +158,38 @@
hosts.each do |host|
expect( ::Docker::Container ).to receive(:create).with({
'Image' => image.id,
'Hostname' => host.name,
})
+ end
+
+ docker.provision
+ end
+
+ it 'should create a named container based on the Image (identified by image.id)' do
+ hosts.each_with_index do |host, index|
+ container_name = "spec-container-#{index}"
+ host['docker_container_name'] = container_name
+
+ expect( ::Docker::Container ).to receive(:all).and_return([])
+
+ expect( ::Docker::Container ).to receive(:create).with({
+ 'Image' => image.id,
+ 'Hostname' => host.name,
+ 'name' => container_name,
+ })
+ end
+
+ docker.provision
+ end
+
+ it 'should not create a container if a named one already exists' do
+ hosts.each_with_index do |host, index|
+ container_name = "spec-container-#{index}"
+ host['docker_container_name'] = container_name
+
+ expect( ::Docker::Container ).to receive(:all).and_return([container])
+ expect( ::Docker::Container ).not_to receive(:create)
end
docker.provision
end