diff --git a/spec/defines/exec_spec.rb b/spec/defines/exec_spec.rb index 56e15e361..e8e184b3d 100644 --- a/spec/defines/exec_spec.rb +++ b/spec/defines/exec_spec.rb @@ -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 diff --git a/spec/defines/run_spec.rb b/spec/defines/run_spec.rb index a30f5fbb1..cb5fbfd16 100755 --- a/spec/defines/run_spec.rb +++ b/spec/defines/run_spec.rb @@ -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 @@ -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