From cf98ae5dbe2b90ded7581b15920e4fe434429a6b Mon Sep 17 00:00:00 2001 From: David Hollinger III Date: Tue, 30 May 2023 23:08:25 -0500 Subject: [PATCH] add unit tests and minor fixes --- .fixtures.yml | 4 +++- manifests/params.pp | 9 ++++++--- manifests/webhook.pp | 4 ++-- spec/classes/webhook_spec.rb | 31 ++++++++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index b716e9dd..3ca95ea1 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -8,11 +8,13 @@ fixtures: inifile: https://github.com/puppetlabs/puppetlabs-inifile.git mcollective: https://github.com/choria-io/puppet-mcollective.git ruby: https://github.com/puppetlabs/puppetlabs-ruby.git - stdlib: https://github.com/puppetlabs/puppetlabs-stdlib.git systemd: https://github.com/voxpupuli/puppet-systemd.git vcsrepo: https://github.com/puppetlabs/puppetlabs-vcsrepo.git yumrepo_core: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git forge_modules: + stdlib: + repo: "puppetlabs/stdlib" + ref: "8.6.0" mcollective_agent_filemgr: "choria/mcollective_agent_filemgr" mcollective_agent_package: "choria/mcollective_agent_package" mcollective_agent_puppet: "choria/mcollective_agent_puppet" diff --git a/manifests/params.pp b/manifests/params.pp index 426c0241..748f3cda 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,6 +4,8 @@ $version = 'installed' $manage_modulepath = false $manage_ruby_dependency = 'ignore' + $root_user = 'root' + $root_group = 'root' $provider = $facts['os']['name'] ? { 'Archlinux' => 'pacman', @@ -26,6 +28,7 @@ $r10k_cache_dir = "${facts['puppet_vardir']}/r10k" $r10k_config_file = '/etc/puppetlabs/r10k/r10k.yaml' $r10k_binary = 'r10k' + $pre_postrun_command = "${r10k_binary} deploy environment -p" $puppetconf_path = '/etc/puppetlabs/puppet' $manage_configfile_symlink = false $configfile_symlink = '/etc/r10k.yaml' @@ -61,13 +64,13 @@ if fact('is_pe') == true or fact('is_pe') == 'true' { # < PE 4 $is_pe_server = true - } elsif is_function_available('pe_compiling_server_version') { - # >= PE 4 - $is_pe_server = true + $pe_module_path = '/opt/puppetlabs/puppet/modules' + $modulepath = "${r10k_basedir}/\$environment/modules:${pe_module_path}" } else { # FOSS $is_pe_server = false + $modulepath = "${r10k_basedir}/\$environment/modules" } # Webhook Go parameters diff --git a/manifests/webhook.pp b/manifests/webhook.pp index 91317fb1..ac3b66d7 100644 --- a/manifests/webhook.pp +++ b/manifests/webhook.pp @@ -31,7 +31,7 @@ port => $r10k::params::webhook_port, tls => $tls, }, - R10k::Webhook::Config::R10k $r10k_settings = { + R10k::Webhook::Config::R10k $r10k = { command_path => $r10k::params::webhook_r10k_command_path, config_path => $r10k::params::webhook_r10k_config_path, default_branch => $r10k::params::webhook_r10k_default_branch, @@ -44,7 +44,7 @@ R10k::Webhook::Config $config = { server => $server, chatops => $chatops, - r10k => $r10k_settings, + r10k => $r10k, }, ) { contain r10k::webhook::package diff --git a/spec/classes/webhook_spec.rb b/spec/classes/webhook_spec.rb index 588d4d31..5ddfc61a 100644 --- a/spec/classes/webhook_spec.rb +++ b/spec/classes/webhook_spec.rb @@ -28,8 +28,11 @@ user: 'puppet', password: 'puppet', port: 4000, + tls: { + enabled: false, + } }, - r10k_settings: { + r10k: { command_path: '/opt/puppetlabs/puppet/bin/r10k', config_path: '/etc/puppetlabs/r10k/r10k.yaml', default_branch: 'production', @@ -40,10 +43,36 @@ } } end + + content = '''--- +server: + protected: true + user: puppet + password: puppet + port: 4000 + tls: + enabled: false +chatops: + enabled: false +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 +''' if os == 'archlinux-rolling-x86_64' || os == 'gentoo-2-x86_64' it { is_expected.not_to compile } else it { is_expected.to compile } + 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').with_ensure('running') } + it { is_expected.to contain_file('webhook.yml').with_content(content) } end end end