Skip to content

Commit 46d24ed

Browse files
committed
add remote_file::{owner,group} optional params
1 parent 41bbfba commit 46d24ed

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

manifests/remote_file.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
define foreman_proxy::remote_file (
44
Stdlib::Filesource $remote_location,
55
Stdlib::Filemode $mode = '0644',
6+
Optional[String[1]] $owner = undef,
7+
Optional[String[1]] $group = undef,
68
) {
79
$parent = dirname($title)
810
File <| title == $parent |>
@@ -13,6 +15,8 @@
1315
-> file { $title:
1416
source => $remote_location,
1517
mode => $mode,
18+
owner => $owner,
19+
group => $group,
1620
replace => false,
1721
}
1822
}
Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,64 @@
11
require 'spec_helper'
22

3+
shared_examples 'remote_file' do
4+
it { is_expected.to contain_exec('mkdir -p /tmp') }
5+
end
6+
37
describe 'foreman_proxy::remote_file' do
48
let(:title) { '/tmp/a' }
59

6-
let(:params) do
7-
{
8-
remote_location: 'https://example.com/tmp/a',
9-
mode: '0664'
10-
}
11-
end
10+
context 'without owner/group params' do
11+
let(:params) do
12+
{
13+
remote_location: 'https://example.com/tmp/a',
14+
mode: '0664'
15+
}
16+
end
1217

13-
context 'default scenario' do
14-
it { is_expected.to contain_exec('mkdir -p /tmp') }
18+
context 'default scenario' do
19+
include_examples 'remote_file'
1520

16-
it do
17-
is_expected.to contain_file('/tmp/a')
18-
.with_source('https://example.com/tmp/a')
19-
.with_mode('0664')
20-
.that_requires('Exec[mkdir -p /tmp]')
21+
it do
22+
is_expected.to contain_file('/tmp/a').with(
23+
source: 'https://example.com/tmp/a',
24+
mode: '0664',
25+
owner: nil,
26+
group: nil,
27+
).without(
28+
).that_requires('Exec[mkdir -p /tmp]')
29+
end
30+
end
31+
32+
context 'with parent file defined' do
33+
let :pre_condition do
34+
"file { '/tmp': }"
35+
end
36+
37+
include_examples 'remote_file'
38+
39+
it { is_expected.to contain_exec('mkdir -p /tmp').that_requires('File[/tmp]') }
2140
end
2241
end
2342

24-
context 'with parent file defined' do
25-
let :pre_condition do
26-
"file { '/tmp': }"
43+
context 'with owner/group params' do
44+
let(:params) do
45+
{
46+
remote_location: 'https://example.com/tmp/a',
47+
mode: '0664',
48+
owner: 'foo',
49+
group: 'bar',
50+
}
2751
end
2852

29-
it { is_expected.to contain_exec('mkdir -p /tmp').that_requires('File[/tmp]') }
53+
include_examples 'remote_file'
54+
55+
it do
56+
is_expected.to contain_file('/tmp/a').with(
57+
source: 'https://example.com/tmp/a',
58+
mode: '0664',
59+
owner: 'foo',
60+
group: 'bar',
61+
).that_requires('Exec[mkdir -p /tmp]')
62+
end
3063
end
3164
end

0 commit comments

Comments
 (0)