Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webhook: Fix default parameter values and add unit tests #630

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,11 @@ Default value:
```puppet
{
enabled => false,
service => '',
channel => '',
user => '',
auth_token => '',
server_uri => '',
service => undef,
channel => undef,
user => undef,
auth_token => undef,
server_uri => undef,
}
```

Expand Down Expand Up @@ -699,7 +699,7 @@ Default value:
command_path => '/opt/puppetlabs/puppet/bin/r10k',
config_path => '/etc/puppetlabs/r10k/r10k.yaml',
default_branch => 'production',
prefix => '',
prefix => undef,
allow_uppercase => false,
verbose => true,
deploy_modules => true,
Expand Down
12 changes: 6 additions & 6 deletions manifests/webhook.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
String $config_path = '/etc/voxpupuli/webhook.yml',
R10k::Webhook::Config::ChatOps $chatops = {
enabled => false,
service => '',
channel => '',
user => '',
auth_token => '',
server_uri => '',
service => undef,
channel => undef,
user => undef,
auth_token => undef,
server_uri => undef,
},
R10k::Webhook::Config::Server::Tls $tls = {
enabled => false,
Expand All @@ -38,7 +38,7 @@
command_path => '/opt/puppetlabs/puppet/bin/r10k',
config_path => '/etc/puppetlabs/r10k/r10k.yaml',
default_branch => 'production',
prefix => '',
prefix => undef,
allow_uppercase => false,
verbose => true,
deploy_modules => true,
Expand Down
133 changes: 74 additions & 59 deletions spec/classes/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,60 @@
os_facts
end

let :params do
{
ensure: true,
version: '1.0.0',
service_ensure: 'running',
service_enabled: true,
config_ensure: 'file',
config_path: '/etc/voxpupuli/webhook.yml',
chatops: {
enabled: true,
service: 'slack',
channel: '#channel',
user: 'root',
auth_token: 'ABCDEF123456789',
server_uri: 'https://webhook.slack.com/endpoint',
},
server: {
protected: true,
user: 'puppet',
password: 'puppet',
port: 4000,
tls: {
context 'with default params' do
if %w[archlinux-rolling-x86_64 gentoo-2-x86_64].include?(os)
it { is_expected.not_to compile }
else
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('r10k::webhook::package') }
it { is_expected.to contain_class('r10k::webhook::service') }
it { is_expected.to contain_class('r10k::webhook::config') }
it { is_expected.to contain_package('webhook-go').with_ensure('present') }
it { is_expected.to contain_service('webhook-go').with_ensure('running') }
end
end

context 'with params' do
let :params do
{
ensure: true,
version: '1.0.0',
service_ensure: 'running',
service_enabled: true,
config_ensure: 'file',
config_path: '/etc/voxpupuli/webhook.yml',
chatops: {
enabled: true,
certificate: '/path/to/cert',
key: '/path/to/key',
service: 'slack',
channel: '#channel',
user: 'root',
auth_token: 'ABCDEF123456789',
server_uri: 'https://webhook.slack.com/endpoint',
},
server: {
protected: true,
user: 'puppet',
password: 'puppet',
port: 4000,
tls: {
enabled: true,
certificate: '/path/to/cert',
key: '/path/to/key',
},
},
},
r10k: {
command_path: '/opt/puppetlabs/puppet/bin/r10k',
config_path: '/etc/puppetlabs/r10k/r10k.yaml',
default_branch: 'production',
allow_uppercase: false,
verbose: true,
deploy_modules: true,
generate_types: true,
r10k: {
command_path: '/opt/puppetlabs/puppet/bin/r10k',
config_path: '/etc/puppetlabs/r10k/r10k.yaml',
default_branch: 'production',
allow_uppercase: false,
verbose: true,
deploy_modules: true,
generate_types: true,
}
}
}
end
end

content = '---
content = '---
server:
protected: true
user: puppet
Expand All @@ -74,34 +88,35 @@
deploy_modules: true
generate_types: true
'
context 'with default install_method' do
if %w[archlinux-rolling-x86_64 gentoo-2-x86_64].include?(os)
it { is_expected.not_to compile }
else
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('r10k::webhook::package') }
it { is_expected.to contain_class('r10k::webhook::service') }
it { is_expected.to contain_class('r10k::webhook::config') }
it { is_expected.to contain_package('webhook-go').with_ensure('present') }
it { is_expected.to contain_service('webhook-go').with_ensure('running') }
it { is_expected.to contain_file('webhook.yml').with_content(content) }
context 'with default install_method' do
if %w[archlinux-rolling-x86_64 gentoo-2-x86_64].include?(os)
it { is_expected.not_to compile }
else
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('r10k::webhook::package') }
it { is_expected.to contain_class('r10k::webhook::service') }
it { is_expected.to contain_class('r10k::webhook::config') }
it { is_expected.to contain_package('webhook-go').with_ensure('present') }
it { is_expected.to contain_service('webhook-go').with_ensure('running') }
it { is_expected.to contain_file('webhook.yml').with_content(content) }

if os_facts[:os]['family'] == 'RedHat'
it { is_expected.to contain_file('/tmp/webhook-go.rpm') }
it { is_expected.not_to contain_file('/tmp/webhook-go.deb') }
elsif os_facts[:os]['family'] == 'Debian'
it { is_expected.not_to contain_file('/tmp/webhook-go.rpm') }
it { is_expected.to contain_file('/tmp/webhook-go.deb') }
if os_facts[:os]['family'] == 'RedHat'
it { is_expected.to contain_file('/tmp/webhook-go.rpm') }
it { is_expected.not_to contain_file('/tmp/webhook-go.deb') }
elsif os_facts[:os]['family'] == 'Debian'
it { is_expected.not_to contain_file('/tmp/webhook-go.rpm') }
it { is_expected.to contain_file('/tmp/webhook-go.deb') }
end
end
end
end

context 'with install_method = none' do
let :params do
super().merge({ install_method: 'none' })
end
context 'with install_method = none' do
let :params do
super().merge({ install_method: 'none' })
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to compile.with_all_deps }
end
end
end
end
Expand Down