Skip to content

Commit

Permalink
Adding test of underscores in title that need sanitisation
Browse files Browse the repository at this point in the history
Adding test of sanitised depends and after arrays

Add test of container name sanitisation

Add sanitise_name param to sanitisation test

Trying to fix exec name sanitisation test

syntax error
  • Loading branch information
bmcbm committed Aug 10, 2016
1 parent fcd7019 commit ce450eb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions spec/defines/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@
let(:params) { {'command' => 'command', 'container' => 'container', 'interactive' => true,} }
it { should contain_exec('docker exec --interactive=true container command').with_unless (nil) }
end

context 'with title that need sanitisation' do
let(:params) { {'command' => 'command', 'container' => 'container_sample/1', 'detach' => true, 'sanitise_name' => true} }
it { should contain_exec('docker exec --detach=true container_sample-1 command') }
end
end
30 changes: 28 additions & 2 deletions spec/defines/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,51 @@
end

context 'when passing `after` containers' do
let(:params) { {'command' => 'command', 'image' => 'base', 'after' => ['foo', 'bar']} }
let(:params) { {'command' => 'command', 'image' => 'base', 'after' => ['foo', 'bar', 'foo_bar/baz']} }
if (systemd)
it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-foo.service/) }
it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-bar.service/) }
it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-foo_bar-baz.service/) }
it { should contain_file(initscript).with_content(/Wants=(.*\s+)?docker-foo.service/) }
it { should contain_file(initscript).with_content(/Wants=(.*\s+)?docker-bar.service/) }
it { should contain_file(initscript).with_content(/Wants=(.*\s+)?docker-foo_bar-baz.service/) }
else
if (osfamily == 'Gentoo')
it { should contain_file(initscript).with_content(/after.*\s+docker-foo/) }
it { should contain_file(initscript).with_content(/after.*\s+docker-bar/) }
it { should contain_file(initscript).with_content(/after.*\s+docker-foo_bar-baz/) }
else
it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-foo/) }
it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-bar/) }
it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-foo_bar-baz/) }
end
end
end

context 'when passing `depends` containers' do
let(:params) { {'command' => 'command', 'image' => 'base', 'depends' => ['foo', 'bar']} }
let(:params) { {'command' => 'command', 'image' => 'base', 'depends' => ['foo', 'bar', 'foo_bar/baz']} }
if (systemd)
it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-foo.service/) }
it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-bar.service/) }
it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-foo_bar-baz.service/) }
it { should contain_file(initscript).with_content(/Requires=(.*\s+)?docker-foo.service/) }
it { should contain_file(initscript).with_content(/Requires=(.*\s+)?docker-bar.service/) }
it { should contain_file(initscript).with_content(/Requires=(.*\s+)?docker-foo_bar-baz.service/) }
else
if (osfamily == 'Gentoo')
it { should contain_file(initscript).with_content(/after.*\s+docker-foo/) }
it { should contain_file(initscript).with_content(/after.*\s+docker-bar/) }
it { should contain_file(initscript).with_content(/after.*\s+docker-foo_bar-baz/) }
it { should contain_file(initscript).with_content(/need.*\s+docker-foo/) }
it { should contain_file(initscript).with_content(/need.*\s+docker-bar/) }
it { should contain_file(initscript).with_content(/need.*\s+docker-foo_bar-baz/) }
else
it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-foo/) }
it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-bar/) }
it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-foo_bar-baz/) }
it { should contain_file(initscript).with_content(/Required-Stop:.*\s+docker-foo/) }
it { should contain_file(initscript).with_content(/Required-Stop:.*\s+docker-bar/) }
it { should contain_file(initscript).with_content(/Required-Stop:.*\s+docker-foo_bar-baz/) }
end
end
end
Expand Down Expand Up @@ -526,6 +536,22 @@
it { should contain_file(new_initscript) }
end

context 'with title that need sanitisation' do
let(:title) { 'this/that_other' }
let(:params) { {'image' => 'base' } }

if osfamily == 'Debian'
new_initscript = '/etc/init.d/docker-this-that_other'
elsif osfamily == 'Archlinux'
new_initscript = '/etc/systemd/system/docker-this-that_other.service'
else
new_initscript = '/etc/init.d/docker-this-that_other'
end

it { should contain_service('docker-this-that_other') }
it { should contain_file(new_initscript) }
end

context 'with an invalid title' do
let(:title) { 'with spaces' }
it do
Expand Down

0 comments on commit ce450eb

Please sign in to comment.