spec/beaker/hypervisor/docker_spec.rb in beaker-2.26.0 vs spec/beaker/hypervisor/docker_spec.rb in beaker-2.27.0
- old
+ new
@@ -1,16 +1,25 @@
require 'spec_helper'
+require 'fakefs/spec_helpers'
# fake the docker-api
module Docker
class Image
end
class Container
end
end
module Beaker
+ platforms = [
+ "ubuntu-14.04-x86_64",
+ "cumulus-2.2-x86_64",
+ "fedora-22-x86_64",
+ "centos-7-x86_64",
+ "sles-12-x86_64"
+ ]
+
describe Docker do
let(:hosts) { make_hosts }
let(:logger) do
logger = double('logger')
@@ -296,44 +305,79 @@
end
end
describe '#dockerfile_for' do
+ FakeFS.deactivate!
before :each do
allow( ::Docker ).to receive(:validate_version!)
end
it 'should raise on an unsupported platform' do
- expect { docker.send(:dockerfile_for, {'platform' => 'a_sidewalk' }) }.to raise_error(/platform a_sidewalk not yet supported on docker/)
+ expect { docker.send(:dockerfile_for, {'platform' => 'a_sidewalk', 'image' => 'foobar' }) }.to raise_error(/platform a_sidewalk not yet supported/)
end
+ it 'should raise on missing image' do
+ expect { docker.send(:dockerfile_for, {'platform' => 'centos-7-x86_64'})}.to raise_error(/Docker image undefined/)
+ end
+
it 'should add docker_image_commands as RUN statements' do
+ FakeFS.deactivate!
+ platforms.each do |platform|
+ dockerfile = docker.send(:dockerfile_for, {
+ 'platform' => platform,
+ 'image' => 'foobar',
+ 'docker_image_commands' => [
+ 'special one',
+ 'special two',
+ 'special three',
+ ]
+ })
+
+ expect( dockerfile ).to be =~ /RUN special one\nRUN special two\nRUN special three/
+ end
+ end
+
+ it 'should add docker_image_entrypoint' do
+ FakeFS.deactivate!
+ platforms.each do |platform|
+ dockerfile = docker.send(:dockerfile_for, {
+ 'platform' => platform,
+ 'image' => 'foobar',
+ 'docker_image_entrypoint' => '/bin/bash'
+ })
+
+ expect( dockerfile ).to be =~ %r{ENTRYPOINT /bin/bash}
+ end
+ end
+
+ it 'should use zypper on sles' do
+ FakeFS.deactivate!
dockerfile = docker.send(:dockerfile_for, {
- 'platform' => 'el-',
- 'docker_image_commands' => [
- 'special one',
- 'special two',
- 'special three',
- ]
+ 'platform' => 'sles-12-x86_64',
+ 'image' => 'foobar',
})
- expect( dockerfile ).to be =~ /RUN special one\nRUN special two\nRUN special three/
+ expect( dockerfile ).to be =~ /RUN zypper -n in openssh/
end
- it 'should add docker_image_entrypoint' do
+ it 'should use dnf on fedora-22' do
+ FakeFS.deactivate!
dockerfile = docker.send(:dockerfile_for, {
- 'platform' => 'el-',
- 'docker_image_entrypoint' => '/bin/bash'
+ 'platform' => 'fedora-22-x86_64',
+ 'image' => 'foobar',
})
- expect( dockerfile ).to be =~ %r{ENTRYPOINT /bin/bash}
+ expect( dockerfile ).to be =~ /RUN dnf install -y sudo/
end
- it 'should use zypper on sles' do
+ it 'should use user dockerfile if specified' do
+ FakeFS.deactivate!
dockerfile = docker.send(:dockerfile_for, {
- 'platform' => 'sles',
+ 'dockerfile' => 'README.md'
})
- expect( dockerfile ).to be =~ /RUN zypper -n in openssh/
+ expect( dockerfile ).to be == File.read('README.md')
end
+
end
end
end