Skip to content

Commit a7928ff

Browse files
authored
Merge pull request #630 from bastelfreak/webhookdata
webhook: Fix default parameter values and add unit tests
2 parents 22212f6 + 8102b0c commit a7928ff

File tree

3 files changed

+86
-71
lines changed

3 files changed

+86
-71
lines changed

REFERENCE.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,11 @@ Default value:
644644
```puppet
645645
{
646646
enabled => false,
647-
service => '',
648-
channel => '',
649-
user => '',
650-
auth_token => '',
651-
server_uri => '',
647+
service => undef,
648+
channel => undef,
649+
user => undef,
650+
auth_token => undef,
651+
server_uri => undef,
652652
}
653653
```
654654

@@ -699,7 +699,7 @@ Default value:
699699
command_path => '/opt/puppetlabs/puppet/bin/r10k',
700700
config_path => '/etc/puppetlabs/r10k/r10k.yaml',
701701
default_branch => 'production',
702-
prefix => '',
702+
prefix => undef,
703703
allow_uppercase => false,
704704
verbose => true,
705705
deploy_modules => true,

manifests/webhook.pp

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
String $config_path = '/etc/voxpupuli/webhook.yml',
1717
R10k::Webhook::Config::ChatOps $chatops = {
1818
enabled => false,
19-
service => '',
20-
channel => '',
21-
user => '',
22-
auth_token => '',
23-
server_uri => '',
19+
service => undef,
20+
channel => undef,
21+
user => undef,
22+
auth_token => undef,
23+
server_uri => undef,
2424
},
2525
R10k::Webhook::Config::Server::Tls $tls = {
2626
enabled => false,
@@ -38,7 +38,7 @@
3838
command_path => '/opt/puppetlabs/puppet/bin/r10k',
3939
config_path => '/etc/puppetlabs/r10k/r10k.yaml',
4040
default_branch => 'production',
41-
prefix => '',
41+
prefix => undef,
4242
allow_uppercase => false,
4343
verbose => true,
4444
deploy_modules => true,

spec/classes/webhook_spec.rb

+74-59
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,60 @@
99
os_facts
1010
end
1111

12-
let :params do
13-
{
14-
ensure: true,
15-
version: '1.0.0',
16-
service_ensure: 'running',
17-
service_enabled: true,
18-
config_ensure: 'file',
19-
config_path: '/etc/voxpupuli/webhook.yml',
20-
chatops: {
21-
enabled: true,
22-
service: 'slack',
23-
channel: '#channel',
24-
user: 'root',
25-
auth_token: 'ABCDEF123456789',
26-
server_uri: 'https://webhook.slack.com/endpoint',
27-
},
28-
server: {
29-
protected: true,
30-
user: 'puppet',
31-
password: 'puppet',
32-
port: 4000,
33-
tls: {
12+
context 'with default params' do
13+
if %w[archlinux-rolling-x86_64 gentoo-2-x86_64].include?(os)
14+
it { is_expected.not_to compile }
15+
else
16+
it { is_expected.to compile.with_all_deps }
17+
it { is_expected.to contain_class('r10k::webhook::package') }
18+
it { is_expected.to contain_class('r10k::webhook::service') }
19+
it { is_expected.to contain_class('r10k::webhook::config') }
20+
it { is_expected.to contain_package('webhook-go').with_ensure('present') }
21+
it { is_expected.to contain_service('webhook-go').with_ensure('running') }
22+
end
23+
end
24+
25+
context 'with params' do
26+
let :params do
27+
{
28+
ensure: true,
29+
version: '1.0.0',
30+
service_ensure: 'running',
31+
service_enabled: true,
32+
config_ensure: 'file',
33+
config_path: '/etc/voxpupuli/webhook.yml',
34+
chatops: {
3435
enabled: true,
35-
certificate: '/path/to/cert',
36-
key: '/path/to/key',
36+
service: 'slack',
37+
channel: '#channel',
38+
user: 'root',
39+
auth_token: 'ABCDEF123456789',
40+
server_uri: 'https://webhook.slack.com/endpoint',
41+
},
42+
server: {
43+
protected: true,
44+
user: 'puppet',
45+
password: 'puppet',
46+
port: 4000,
47+
tls: {
48+
enabled: true,
49+
certificate: '/path/to/cert',
50+
key: '/path/to/key',
51+
},
3752
},
38-
},
39-
r10k: {
40-
command_path: '/opt/puppetlabs/puppet/bin/r10k',
41-
config_path: '/etc/puppetlabs/r10k/r10k.yaml',
42-
default_branch: 'production',
43-
allow_uppercase: false,
44-
verbose: true,
45-
deploy_modules: true,
46-
generate_types: true,
53+
r10k: {
54+
command_path: '/opt/puppetlabs/puppet/bin/r10k',
55+
config_path: '/etc/puppetlabs/r10k/r10k.yaml',
56+
default_branch: 'production',
57+
allow_uppercase: false,
58+
verbose: true,
59+
deploy_modules: true,
60+
generate_types: true,
61+
}
4762
}
48-
}
49-
end
63+
end
5064

51-
content = '---
65+
content = '---
5266
server:
5367
protected: true
5468
user: puppet
@@ -74,34 +88,35 @@
7488
deploy_modules: true
7589
generate_types: true
7690
'
77-
context 'with default install_method' do
78-
if %w[archlinux-rolling-x86_64 gentoo-2-x86_64].include?(os)
79-
it { is_expected.not_to compile }
80-
else
81-
it { is_expected.to compile.with_all_deps }
82-
it { is_expected.to contain_class('r10k::webhook::package') }
83-
it { is_expected.to contain_class('r10k::webhook::service') }
84-
it { is_expected.to contain_class('r10k::webhook::config') }
85-
it { is_expected.to contain_package('webhook-go').with_ensure('present') }
86-
it { is_expected.to contain_service('webhook-go').with_ensure('running') }
87-
it { is_expected.to contain_file('webhook.yml').with_content(content) }
91+
context 'with default install_method' do
92+
if %w[archlinux-rolling-x86_64 gentoo-2-x86_64].include?(os)
93+
it { is_expected.not_to compile }
94+
else
95+
it { is_expected.to compile.with_all_deps }
96+
it { is_expected.to contain_class('r10k::webhook::package') }
97+
it { is_expected.to contain_class('r10k::webhook::service') }
98+
it { is_expected.to contain_class('r10k::webhook::config') }
99+
it { is_expected.to contain_package('webhook-go').with_ensure('present') }
100+
it { is_expected.to contain_service('webhook-go').with_ensure('running') }
101+
it { is_expected.to contain_file('webhook.yml').with_content(content) }
88102

89-
if os_facts[:os]['family'] == 'RedHat'
90-
it { is_expected.to contain_file('/tmp/webhook-go.rpm') }
91-
it { is_expected.not_to contain_file('/tmp/webhook-go.deb') }
92-
elsif os_facts[:os]['family'] == 'Debian'
93-
it { is_expected.not_to contain_file('/tmp/webhook-go.rpm') }
94-
it { is_expected.to contain_file('/tmp/webhook-go.deb') }
103+
if os_facts[:os]['family'] == 'RedHat'
104+
it { is_expected.to contain_file('/tmp/webhook-go.rpm') }
105+
it { is_expected.not_to contain_file('/tmp/webhook-go.deb') }
106+
elsif os_facts[:os]['family'] == 'Debian'
107+
it { is_expected.not_to contain_file('/tmp/webhook-go.rpm') }
108+
it { is_expected.to contain_file('/tmp/webhook-go.deb') }
109+
end
95110
end
96111
end
97-
end
98112

99-
context 'with install_method = none' do
100-
let :params do
101-
super().merge({ install_method: 'none' })
102-
end
113+
context 'with install_method = none' do
114+
let :params do
115+
super().merge({ install_method: 'none' })
116+
end
103117

104-
it { is_expected.to compile.with_all_deps }
118+
it { is_expected.to compile.with_all_deps }
119+
end
105120
end
106121
end
107122
end

0 commit comments

Comments
 (0)