Skip to content

Commit

Permalink
Merge branch 'feature/338'
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcbm committed Aug 10, 2016
2 parents ccade80 + ce450eb commit 4b45545
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion manifests/exec.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


if $sanitise_name {
$sanitised_container = regsubst($container, '[^0-9A-Za-z.\-]', '-', 'G')
$sanitised_container = regsubst($container, '[^0-9A-Za-z.\-_]', '-', 'G')
} else {
$sanitised_container = $container
}
Expand Down
6 changes: 3 additions & 3 deletions manifests/run.pp
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,19 @@
volumes_from => any2array($volumes_from),
})

$sanitised_title = regsubst($title, '[^0-9A-Za-z.\-]', '-', 'G')
$sanitised_title = regsubst($title, '[^0-9A-Za-z.\-_]', '-', 'G')
if empty($depends_array) {
$sanitised_depends_array = []
}
else {
$sanitised_depends_array = regsubst($depends_array, '[^0-9A-Za-z.\-]', '-', 'G')
$sanitised_depends_array = regsubst($depends_array, '[^0-9A-Za-z.\-_]', '-', 'G')
}

if empty($after_array) {
$sanitised_after_array = []
}
else {
$sanitised_after_array = regsubst($after_array, '[^0-9A-Za-z.\-]', '-', 'G')
$sanitised_after_array = regsubst($after_array, '[^0-9A-Za-z.\-_]', '-', 'G')
}

if $restart {
Expand Down
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 4b45545

Please sign in to comment.