diff --git a/.rubocop.yml b/.rubocop.yml index bab25db..3b777ac 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,133 +1,135 @@ --- require: - rubocop-rspec - rubocop-i18n AllCops: DisplayCopNames: true TargetRubyVersion: '2.1' Include: - "./**/*.rb" Exclude: - bin/* - ".vendor/**/*" - "**/Gemfile" - "**/Rakefile" - pkg/**/* - spec/fixtures/**/* - vendor/**/* - "**/Puppetfile" - "**/Vagrantfile" - "**/Guardfile" Metrics/LineLength: Description: People have wide screens, use them. Max: 200 GetText: Enabled: false GetText/DecorateString: Description: We don't want to decorate test output. Exclude: - spec/**/* Enabled: false RSpec/BeforeAfterAll: Description: Beware of using after(:all) as it may cause state to leak between tests. A necessary evil in acceptance testing. Exclude: - spec/acceptance/**/*.rb +RSpec/ScatteredSetup: + Enabled: false RSpec/HookArgument: Description: Prefer explicit :each argument, matching existing module's style EnforcedStyle: each Style/BlockDelimiters: Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to be consistent then. EnforcedStyle: braces_for_chaining Style/ClassAndModuleChildren: Description: Compact style reduces the required amount of indentation. EnforcedStyle: compact Style/EmptyElse: Description: Enforce against empty else clauses, but allow `nil` for clarity. EnforcedStyle: empty Style/FormatString: Description: Following the main puppet project's style, prefer the % format format. EnforcedStyle: percent Style/FormatStringToken: Description: Following the main puppet project's style, prefer the simpler template tokens over annotated ones. EnforcedStyle: template Style/Lambda: Description: Prefer the keyword for easier discoverability. EnforcedStyle: literal Style/RegexpLiteral: Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 EnforcedStyle: percent_r Style/TernaryParentheses: Description: Checks for use of parentheses around ternary conditions. Enforce parentheses on complex expressions for better readability, but seriously consider breaking it up. EnforcedStyle: require_parentheses_when_complex Style/TrailingCommaInArguments: Description: Prefer always trailing comma on multiline argument lists. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma Style/TrailingCommaInLiteral: Description: Prefer always trailing comma on multiline literals. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma Style/SymbolArray: Description: Using percent style obscures symbolic intent of array's contents. EnforcedStyle: brackets RSpec/MessageSpies: EnforcedStyle: receive Style/Documentation: Exclude: - lib/puppet/parser/functions/**/* - spec/**/* Style/WordArray: EnforcedStyle: brackets Style/CollectionMethods: Enabled: true Style/MethodCalledOnDoEndBlock: Enabled: true Style/StringMethods: Enabled: true GetText/DecorateFunctionMessage: Enabled: false GetText/DecorateStringFormattingUsingInterpolation: Enabled: false GetText/DecorateStringFormattingUsingPercent: Enabled: false Layout/EndOfLine: Enabled: false Layout/IndentHeredoc: Enabled: false Metrics/AbcSize: Enabled: false Metrics/BlockLength: Enabled: false Metrics/ClassLength: Enabled: false Metrics/CyclomaticComplexity: Enabled: false Metrics/MethodLength: Enabled: false Metrics/ModuleLength: Enabled: false Metrics/ParameterLists: Enabled: false Metrics/PerceivedComplexity: Enabled: false RSpec/DescribeClass: Enabled: false RSpec/ExampleLength: Enabled: false RSpec/MessageExpectation: Enabled: false RSpec/MultipleExpectations: Enabled: false RSpec/NestedGroups: Enabled: false Style/AsciiComments: Enabled: false Style/IfUnlessModifier: Enabled: false Style/SymbolProc: Enabled: false diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 420972b..ef9f27c 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,177 +1,174 @@ require 'spec_helper_acceptance' describe 'icingaweb2 class:' do - describe 'icingaweb2 with defaults' do let(:pp) do <<-MANIFEST case $::osfamily { 'redhat': { if $facts['os']['name'] == 'centos' and Integer($facts['os']['release']['major']) < 8 { package { 'centos-release-scl': } $php_globals = { php_version => 'rh-php71', rhscl_mode => 'rhscl', } } else { $php_globals = {} } - + $php_extensions = { mbstring => { ini_prefix => '20-' }, json => { ini_prefix => '20-' }, ldap => { ini_prefix => '20-' }, gd => { ini_prefix => '20-' }, xml => { ini_prefix => '20-' }, intl => { ini_prefix => '20-' }, mysqlnd => { ini_prefix => '20-' }, pgsql => { ini_prefix => '20-' }, } $web_conf_user = 'apache' } # RedHat - + 'debian': { $php_globals = {} $php_extensions = { mbstring => {}, json => {}, ldap => {}, gd => {}, xml => {}, intl => {}, mysql => {}, pgsql => {}, } $web_conf_user = 'www-data' } # Debian - + default: { fail("'Your operatingsystem ${::operatingsystem} is not supported.'") } } # # PHP # class { '::php::globals': * => $php_globals, } - + class { '::php': ensure => installed, manage_repos => false, apache_config => false, fpm => true, extensions => $php_extensions, dev => false, composer => false, pear => false, phpunit => false, require => Class['::php::globals'], } # # Apache # class { '::apache': default_mods => false, default_vhost => false, mpm_module => 'worker', } apache::listen { '80': } include ::apache::mod::alias include ::apache::mod::status include ::apache::mod::dir include ::apache::mod::env include ::apache::mod::rewrite include ::apache::mod::proxy include ::apache::mod::proxy_fcgi - + apache::custom_config { 'icingaweb2': ensure => present, source => 'puppet:///modules/icingaweb2/examples/apache2/for-mod_proxy_fcgi.conf', verify_config => false, priority => false, } # # Icinga Web 2 # include ::mysql::server - + mysql::db { 'icingaweb2': user => 'icingaweb2', password => 'icingaweb2', host => 'localhost', grant => ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'DROP', 'CREATE VIEW', 'CREATE', 'INDEX', 'EXECUTE', 'ALTER', 'REFERENCES'], before => Class['icingaweb2'], } Package['icingaweb2'] -> Class['apache'] class { 'icingaweb2': manage_repo => true, conf_user => $web_conf_user, db_type => 'mysql', db_host => 'localhost', db_port => 3306, db_username => 'icingaweb2', db_password => 'icingaweb2', import_schema => true, } MANIFEST end it_behaves_like 'a idempotent resource' describe package('icingaweb2') do it { is_expected.to be_installed } end describe file('/etc/icingaweb2/config.ini') do it { is_expected.to be_file } it { is_expected.to contain '[global]' } it { is_expected.to contain '[logging]' } end describe command('curl -I http://localhost/icingaweb2/') do - its(:stdout) { should match(%r{302 Found}) } + its(:stdout) { is_expected.to match(%r{302 Found}) } end describe file('/etc/icingaweb2/resources.ini') do it { is_expected.to be_file } it { is_expected.to contain '[mysql-icingaweb2]' } it { is_expected.to contain 'type = "db"' } it { is_expected.to contain 'db = "mysql"' } it { is_expected.to contain 'host = "localhost"' } it { is_expected.to contain 'port = "3306"' } it { is_expected.to contain 'dbname = "icingaweb2"' } it { is_expected.to contain 'username = "icingaweb2"' } it { is_expected.to contain 'password = "icingaweb2"' } end - + describe file('/etc/icingaweb2/authentication.ini') do it { is_expected.to be_file } it { is_expected.to contain '[mysql-auth]' } it { is_expected.to contain 'backend = "db"' } it { is_expected.to contain 'resource = "mysql-icingaweb2"' } end - + describe file('/etc/icingaweb2/roles.ini') do it { is_expected.to be_file } it { is_expected.to contain '[default admin user]' } it { is_expected.to contain 'users = "icingaadmin"' } it { is_expected.to contain 'permissions = "*"' } end - + describe command('mysql -e "select name from icingaweb2.icingaweb_user"') do - its(:stdout) { should match(%r{icingaadmin}) } + its(:stdout) { is_expected.to match(%r{icingaadmin}) } end - end - end diff --git a/spec/classes/businessprocess_spec.rb b/spec/classes/businessprocess_spec.rb index d216b5d..bf16bb1 100644 --- a/spec/classes/businessprocess_spec.rb +++ b/spec/classes/businessprocess_spec.rb @@ -1,24 +1,27 @@ require 'spec_helper' -describe('icingaweb2::module::businessprocess', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::businessprocess', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with git_revision 'v2.1.0'" do - let(:params) { { :git_revision => 'v2.1.0', } } + let(:params) { { git_revision: 'v2.1.0' } } - it { is_expected.to contain_icingaweb2__module('businessprocess') - .with_install_method('git') - .with_git_revision('v2.1.0') + it { + is_expected.to contain_icingaweb2__module('businessprocess') + .with_install_method('git') + .with_git_revision('v2.1.0') } end end end end diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index 4bb6c3d..747d05b 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -1,104 +1,109 @@ require 'spec_helper' -describe('icingaweb2::config', :type => :class) do +describe('icingaweb2::config', type: :class) do on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context 'with default parameters' do let :pre_condition do "class { 'icingaweb2': }" end it { is_expected.to contain_icingaweb2__inisection('config-logging') } - it { is_expected.to contain_icingaweb2__inisection('config-global') - .with_settings({ 'show_stacktraces' => false, 'module_path' => '/usr/share/icingaweb2/modules', 'config_backend' => 'ini' }) + it { + is_expected.to contain_icingaweb2__inisection('config-global') + .with_settings('show_stacktraces' => false, 'module_path' => '/usr/share/icingaweb2/modules', 'config_backend' => 'ini') } it { is_expected.to contain_icingaweb2__inisection('config-themes') } it { is_expected.not_to contain_icingaweb2__inisection('config-cookie') } - it { is_expected.to contain_file('/var/log/icingaweb2') - .with_ensure('directory') - .with_mode('0750') + it { + is_expected.to contain_file('/var/log/icingaweb2') + .with_ensure('directory') + .with_mode('0750') } - it { is_expected.to contain_file('/var/log/icingaweb2/icingaweb2.log') - .with_ensure('file') - .with_mode('0640') + it { + is_expected.to contain_file('/var/log/icingaweb2/icingaweb2.log') + .with_ensure('file') + .with_mode('0640') } end context 'with import_schema => true and db_type => mysql' do let :pre_condition do "class { 'icingaweb2': import_schema => true, db_type => 'mysql'}" end - it { is_expected.to contain_icingaweb2__config__resource('mysql-icingaweb2')} - it { is_expected.to contain_icingaweb2__config__authmethod('mysql-auth')} - it { is_expected.to contain_icingaweb2__config__role('default admin user')} + it { is_expected.to contain_icingaweb2__config__resource('mysql-icingaweb2') } + it { is_expected.to contain_icingaweb2__config__authmethod('mysql-auth') } + it { is_expected.to contain_icingaweb2__config__role('default admin user') } it { is_expected.to contain_exec('import schema') } it { is_expected.to contain_exec('create default user') } end context 'with import_schema => true and db_type => pgsql' do let :pre_condition do "class { 'icingaweb2': import_schema => true, db_type => 'pgsql'}" end - it { is_expected.to contain_icingaweb2__config__resource('pgsql-icingaweb2')} - it { is_expected.to contain_icingaweb2__config__authmethod('pgsql-auth')} - it { is_expected.to contain_icingaweb2__config__role('default admin user')} + it { is_expected.to contain_icingaweb2__config__resource('pgsql-icingaweb2') } + it { is_expected.to contain_icingaweb2__config__authmethod('pgsql-auth') } + it { is_expected.to contain_icingaweb2__config__role('default admin user') } it { is_expected.to contain_exec('import schema') } it { is_expected.to contain_exec('create default user') } end context 'with import_schema => true and invalid db_type' do let :pre_condition do "class { 'icingaweb2': import_schema => true, db_type => 'foobar'}" end - it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['mysql', 'pgsql'\]/) } + it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['mysql', 'pgsql'\]}) } end context 'with import_schema => false' do let :pre_condition do "class { 'icingaweb2': import_schema => false }" end - it { is_expected.not_to contain_exec('import schema')} - it { is_expected.not_to contain_exec('create default user')} - it { is_expected.not_to contain_icingaweb2__config__role('default admin user')} + it { is_expected.not_to contain_exec('import schema') } + it { is_expected.not_to contain_exec('create default user') } + it { is_expected.not_to contain_icingaweb2__config__role('default admin user') } end context 'with config_backend => db' do let :pre_condition do "class { 'icingaweb2': config_backend => 'db' }" end - it { is_expected.to contain_icingaweb2__inisection('config-global') - .with_settings({ 'show_stacktraces' => false, 'module_path' => '/usr/share/icingaweb2/modules', 'config_backend' => 'db', 'config_resource' => 'mysql-icingaweb2' }) + it { + is_expected.to contain_icingaweb2__inisection('config-global') + .with_settings('show_stacktraces' => false, 'module_path' => '/usr/share/icingaweb2/modules', 'config_backend' => 'db', 'config_resource' => 'mysql-icingaweb2') } - it { is_expected.to contain_icingaweb2__config__resource('mysql-icingaweb2')} + it { is_expected.to contain_icingaweb2__config__resource('mysql-icingaweb2') } end context 'with cookie_path => /' do let :pre_condition do "class { 'icingaweb2': cookie_path => '/' }" end - it { is_expected.to contain_icingaweb2__inisection('config-cookie') - .with_settings({ 'path' => '/' }) + it { + is_expected.to contain_icingaweb2__inisection('config-cookie') + .with_settings('path' => '/') } end context 'with invalid config_backend' do let :pre_condition do "class { 'icingaweb2': config_backend => 'foobar' }" end - it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['db', 'ini'\]/) } + it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['db', 'ini'\]}) } end end end end diff --git a/spec/classes/cube_spec.rb b/spec/classes/cube_spec.rb index 32c8c7f..4538a9b 100644 --- a/spec/classes/cube_spec.rb +++ b/spec/classes/cube_spec.rb @@ -1,24 +1,27 @@ require 'spec_helper' -describe('icingaweb2::module::cube', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::cube', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with git_revision 'v1.0.0'" do - let(:params) { { :git_revision => 'v1.0.0', } } + let(:params) { { git_revision: 'v1.0.0' } } - it { is_expected.to contain_icingaweb2__module('cube') - .with_install_method('git') - .with_git_revision('v1.0.0') + it { + is_expected.to contain_icingaweb2__module('cube') + .with_install_method('git') + .with_git_revision('v1.0.0') } end end end end diff --git a/spec/classes/director_servicespec.rb b/spec/classes/director_servicespec.rb index fc2d197..c7198fa 100644 --- a/spec/classes/director_servicespec.rb +++ b/spec/classes/director_servicespec.rb @@ -1,29 +1,31 @@ require 'spec_helper' -describe('icingaweb2::module::director::service', :type => :class) do - let(:pre_condition) { [ +describe('icingaweb2::module::director::service', type: :class) do + let(:pre_condition) do + [ "class { 'icingaweb2': }", "class { 'icingaweb2::module::director': }", - ] } + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with defaults" do - it { is_expected.to contain_user('icingadirector') - .with({ 'ensure' => 'present', 'gid' => 'icingaweb2', 'shell' => '/bin/false' }).that_comes_before('Systemd::Unit_file[icinga-director.service]') } + it { + is_expected.to contain_user('icingadirector') + .with('ensure' => 'present', 'gid' => 'icingaweb2', 'shell' => '/bin/false').that_comes_before('Systemd::Unit_file[icinga-director.service]') + } it { is_expected.to contain_systemd__unit_file('icinga-director.service').that_notifies('Service[icinga-director]') } - it { is_expected.to contain_service('icinga-director') - .with({ - 'ensure' => 'running', - 'enable' => true }) } - + it { + is_expected.to contain_service('icinga-director') + .with('ensure' => 'running', + 'enable' => true) + } end end - end end - diff --git a/spec/classes/director_spec.rb b/spec/classes/director_spec.rb index 75073b0..34909c8 100644 --- a/spec/classes/director_spec.rb +++ b/spec/classes/director_spec.rb @@ -1,103 +1,112 @@ require 'spec_helper' -describe('icingaweb2::module::director', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::director', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with kickstart 'true'" do - let(:params) { { :git_revision => 'foobar', - :db_host => 'localhost', - :db_name => 'director', - :db_username => 'director', - :db_password => 'director', - :import_schema => true, - :kickstart => true, - :endpoint => 'foobar', - :api_username => 'root', - :api_password => 'secret' } } + let(:params) do + { git_revision: 'foobar', + db_host: 'localhost', + db_name: 'director', + db_username: 'director', + db_password: 'director', + import_schema: true, + kickstart: true, + endpoint: 'foobar', + api_username: 'root', + api_password: 'secret' } + end - it { is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-director') - .with_type('db') - .with_db_type('mysql') - .with_host('localhost') - .with_port('3306') - .with_db_name('director') - .with_db_username('director') - .with_db_password('director') - .with_db_charset('utf8') + it { + is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-director') + .with_type('db') + .with_db_type('mysql') + .with_host('localhost') + .with_port('3306') + .with_db_name('director') + .with_db_username('director') + .with_db_password('director') + .with_db_charset('utf8') } - it { is_expected.to contain_icingaweb2__module('director') - .with_install_method('git') - .with_git_revision('foobar') - .with_module_dir('/usr/share/icingaweb2/modules/director') - .with_settings( { - 'module-director-db'=>{ - 'section_name'=>'db', - 'target'=>'/etc/icingaweb2/modules/director/config.ini', - 'settings'=>{ - 'resource'=>'icingaweb2-module-director'} - }, - 'module-director-config'=>{ - 'section_name'=>'config', - 'target'=>'/etc/icingaweb2/modules/director/kickstart.ini', - 'settings'=>{ - 'endpoint'=>'foobar', - 'host'=>'localhost', - 'port'=>'5665', - 'username'=>'root', - 'password'=>'secret'} - } - } - )} + it { + is_expected.to contain_icingaweb2__module('director') + .with_install_method('git') + .with_git_revision('foobar') + .with_module_dir('/usr/share/icingaweb2/modules/director') + .with_settings('module-director-db' => { + 'section_name' => 'db', + 'target' => '/etc/icingaweb2/modules/director/config.ini', + 'settings' => { + 'resource' => 'icingaweb2-module-director', + }, + }, + 'module-director-config' => { + 'section_name' => 'config', + 'target' => '/etc/icingaweb2/modules/director/kickstart.ini', + 'settings' => { + 'endpoint' => 'foobar', + 'host' => 'localhost', + 'port' => '5665', + 'username' => 'root', + 'password' => 'secret', + }, + }) + } it { is_expected.to contain_exec('director-migration') } it { is_expected.to contain_exec('director-kickstart') } end context "#{os} with import_schema 'false'" do - let(:params) { { :git_revision => 'foobar', - :db_host => 'localhost', - :db_name => 'director', - :db_username => 'director', - :db_password => 'director', - :import_schema => false } } + let(:params) do + { git_revision: 'foobar', + db_host: 'localhost', + db_name: 'director', + db_username: 'director', + db_password: 'director', + import_schema: false } + end - it { is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-director') - .with_type('db') - .with_db_type('mysql') - .with_host('localhost') - .with_port('3306') - .with_db_name('director') - .with_db_username('director') - .with_db_password('director') - .with_db_charset('utf8') + it { + is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-director') + .with_type('db') + .with_db_type('mysql') + .with_host('localhost') + .with_port('3306') + .with_db_name('director') + .with_db_username('director') + .with_db_password('director') + .with_db_charset('utf8') } - it { is_expected.to contain_icingaweb2__module('director') - .with_install_method('git') - .with_git_revision('foobar') - .with_module_dir('/usr/share/icingaweb2/modules/director') - .with_settings( { - 'module-director-db'=>{ - 'section_name'=>'db', - 'target'=>'/etc/icingaweb2/modules/director/config.ini', - 'settings'=>{ - 'resource'=>'icingaweb2-module-director'} } - } - )} + it { + is_expected.to contain_icingaweb2__module('director') + .with_install_method('git') + .with_git_revision('foobar') + .with_module_dir('/usr/share/icingaweb2/modules/director') + .with_settings('module-director-db' => { + 'section_name' => 'db', + 'target' => '/etc/icingaweb2/modules/director/config.ini', + 'settings' => { + 'resource' => 'icingaweb2-module-director', + }, + }) + } it { is_expected.not_to contain_exec('director-migration') } it { is_expected.not_to contain_exec('director-kickstart') } end end end end - diff --git a/spec/classes/doc_spec.rb b/spec/classes/doc_spec.rb index ac01d99..ab1fd5d 100644 --- a/spec/classes/doc_spec.rb +++ b/spec/classes/doc_spec.rb @@ -1,64 +1,64 @@ require 'spec_helper' -describe('icingaweb2::module::doc', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::doc', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end case facts[:osfamily] - when 'Debian' - before(:all) do - @install_method = 'package' - @package_name = 'icingaweb2-module-doc' - end - else - before(:all) do - @install_method = 'none' - @package_name = nil - end + when 'Debian' + let(:install_method) { 'package' } + let(:package_name) { 'icingaweb2-module-doc' } + else + let(:install_method) { 'none' } + let(:package_name) { nil } end - context "with ensure present" do - let(:params) { { :ensure => 'present', } } + context 'with ensure present' do + let(:params) { { ensure: 'present' } } - it { is_expected.to contain_icingaweb2__module('doc') - .with_install_method(@install_method) - .with_package_name(@package_name) - .with_module_dir('/usr/share/icingaweb2/modules/doc') - .with_ensure('present') - } + it { + is_expected.to contain_icingaweb2__module('doc') + .with_install_method(install_method) + .with_package_name(package_name) + .with_module_dir('/usr/share/icingaweb2/modules/doc') + .with_ensure('present') + } if facts[:osfamily] == 'Debian' - it { is_expected.to contain_package('icingaweb2-module-doc').with({ 'ensure' => 'present' }) } + it { is_expected.to contain_package('icingaweb2-module-doc').with('ensure' => 'present') } end end - context "with ensure absent" do - let(:params) { { :ensure => 'absent', } } + context 'with ensure absent' do + let(:params) { { ensure: 'absent' } } - it { is_expected.to contain_icingaweb2__module('doc') - .with_install_method(@install_method) - .with_package_name(@package_name) - .with_module_dir('/usr/share/icingaweb2/modules/doc') - .with_ensure('absent') - } + it { + is_expected.to contain_icingaweb2__module('doc') + .with_install_method(install_method) + .with_package_name(package_name) + .with_module_dir('/usr/share/icingaweb2/modules/doc') + .with_ensure('absent') + } if facts[:osfamily] == 'Debian' - it { is_expected.to contain_package('icingaweb2-module-doc').with({ 'ensure' => 'absent' }) } + it { is_expected.to contain_package('icingaweb2-module-doc').with('ensure' => 'absent') } end end - context "with ensure foobar" do - let(:params) { { :ensure => 'foobar' } } + context 'with ensure foobar' do + let(:params) { { ensure: 'foobar' } } - it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['absent', 'present'\]/) } + it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['absent', 'present'\]}) } end end end end diff --git a/spec/classes/elasticsearch_spec.rb b/spec/classes/elasticsearch_spec.rb index 90b5cb3..9c5ec10 100644 --- a/spec/classes/elasticsearch_spec.rb +++ b/spec/classes/elasticsearch_spec.rb @@ -1,100 +1,113 @@ require 'spec_helper' -describe('icingaweb2::module::elasticsearch', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::elasticsearch', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with git_revision 'v0.9.0'" do - let(:params) { { :git_revision => 'v0.9.0', } } + let(:params) { { git_revision: 'v0.9.0' } } - it { is_expected.to contain_icingaweb2__module('elasticsearch') - .with_install_method('git') - .with_git_revision('v0.9.0') + it { + is_expected.to contain_icingaweb2__module('elasticsearch') + .with_install_method('git') + .with_git_revision('v0.9.0') } end context "#{os} with an instance" do - let(:params) { { - :git_revision => 'v0.9.0', - :instances => { - 'elastic' => { - 'uri' => 'http://localhost:9200', - 'user' => 'user', - 'password' => 'password', - 'ca' => '/tmp/ca', - 'client_certificate' => '/tmp/client_certificate', - 'client_private_key' => '/tmp/client_private_key', - } - } - } } + let(:params) do + { + git_revision: 'v0.9.0', + instances: { + 'elastic' => { + 'uri' => 'http://localhost:9200', + 'user' => 'user', + 'password' => 'password', + 'ca' => '/tmp/ca', + 'client_certificate' => '/tmp/client_certificate', + 'client_private_key' => '/tmp/client_private_key', + }, + }, + } + end - it { is_expected.to contain_icingaweb2__module('elasticsearch') - .with_install_method('git') - .with_git_revision('v0.9.0') + it { + is_expected.to contain_icingaweb2__module('elasticsearch') + .with_install_method('git') + .with_git_revision('v0.9.0') } - it { is_expected.to contain_icingaweb2__module__elasticsearch__instance('elastic') - .with_uri('http://localhost:9200') - .with_user('user') - .with_password('password') - .with_ca('/tmp/ca') - .with_client_certificate('/tmp/client_certificate') - .with_client_private_key('/tmp/client_private_key') + it { + is_expected.to contain_icingaweb2__module__elasticsearch__instance('elastic') + .with_uri('http://localhost:9200') + .with_user('user') + .with_password('password') + .with_ca('/tmp/ca') + .with_client_certificate('/tmp/client_certificate') + .with_client_private_key('/tmp/client_private_key') } - it { is_expected.to contain_icingaweb2__inisection('elasticsearch-instance-elastic') - .with_section_name('elastic') - .with_target('/etc/icingaweb2/modules/elasticsearch/instances.ini') - .with_settings( { 'uri' => 'http://localhost:9200', - 'user' => 'user', - 'password' => 'password', - 'ca' => '/tmp/ca', - 'client_certificate' => '/tmp/client_certificate', - 'client_private_key' => '/tmp/client_private_key'} ) + it { + is_expected.to contain_icingaweb2__inisection('elasticsearch-instance-elastic') + .with_section_name('elastic') + .with_target('/etc/icingaweb2/modules/elasticsearch/instances.ini') + .with_settings('uri' => 'http://localhost:9200', + 'user' => 'user', + 'password' => 'password', + 'ca' => '/tmp/ca', + 'client_certificate' => '/tmp/client_certificate', + 'client_private_key' => '/tmp/client_private_key') } end context "#{os} with an event type" do - let(:params) { { - :git_revision => 'v0.9.0', - :eventtypes => { - 'filebeat' => { - 'instance' => 'my-instance', - 'index' => 'my-index', - 'filter' => 'my-filter', - 'fields' => 'my-fields', - } - } - } } + let(:params) do + { + git_revision: 'v0.9.0', + eventtypes: { + 'filebeat' => { + 'instance' => 'my-instance', + 'index' => 'my-index', + 'filter' => 'my-filter', + 'fields' => 'my-fields', + }, + }, + } + end - it { is_expected.to contain_icingaweb2__module('elasticsearch') - .with_install_method('git') - .with_git_revision('v0.9.0') + it { + is_expected.to contain_icingaweb2__module('elasticsearch') + .with_install_method('git') + .with_git_revision('v0.9.0') } - it { is_expected.to contain_icingaweb2__module__elasticsearch__eventtype('filebeat') - .with_instance('my-instance') - .with_index('my-index') - .with_filter('my-filter') - .with_fields('my-fields') + it { + is_expected.to contain_icingaweb2__module__elasticsearch__eventtype('filebeat') + .with_instance('my-instance') + .with_index('my-index') + .with_filter('my-filter') + .with_fields('my-fields') } - it { is_expected.to contain_icingaweb2__inisection('elasticsearch-eventtype-filebeat') - .with_section_name('filebeat') - .with_target('/etc/icingaweb2/modules/elasticsearch/eventtypes.ini') - .with_settings( { 'instance' => 'my-instance', - 'index' => 'my-index', - 'filter' => 'my-filter', - 'fields' => 'my-fields' } ) + it { + is_expected.to contain_icingaweb2__inisection('elasticsearch-eventtype-filebeat') + .with_section_name('filebeat') + .with_target('/etc/icingaweb2/modules/elasticsearch/eventtypes.ini') + .with_settings('instance' => 'my-instance', + 'index' => 'my-index', + 'filter' => 'my-filter', + 'fields' => 'my-fields') } end end end -end \ No newline at end of file +end diff --git a/spec/classes/fileshipper_spec.rb b/spec/classes/fileshipper_spec.rb index 4f72260..55d1677 100644 --- a/spec/classes/fileshipper_spec.rb +++ b/spec/classes/fileshipper_spec.rb @@ -1,78 +1,91 @@ require 'spec_helper' -describe('icingaweb2::module::fileshipper', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::fileshipper', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with git_revision 'v1.0.0'" do - let(:params) { { :git_revision => 'v1.0.0', } } + let(:params) { { git_revision: 'v1.0.0' } } - it { is_expected.to contain_icingaweb2__module('fileshipper') - .with_install_method('git') - .with_git_revision('v1.0.0') + it { + is_expected.to contain_icingaweb2__module('fileshipper') + .with_install_method('git') + .with_git_revision('v1.0.0') } end context "#{os} with a base directory" do - let(:params) { { - :git_revision => 'v1.0.0', - :base_directories => { - 'temp' => '/tmp' - } - } } + let(:params) do + { + git_revision: 'v1.0.0', + base_directories: { + 'temp' => '/tmp', + }, + } + end - it { is_expected.to contain_icingaweb2__module('fileshipper') - .with_install_method('git') - .with_git_revision('v1.0.0') + it { + is_expected.to contain_icingaweb2__module('fileshipper') + .with_install_method('git') + .with_git_revision('v1.0.0') } - it { is_expected.to contain_icingaweb2__module__fileshipper__basedir('temp') - .with_basedir('/tmp') + it { + is_expected.to contain_icingaweb2__module__fileshipper__basedir('temp') + .with_basedir('/tmp') } - it { is_expected.to contain_icingaweb2__inisection('fileshipper-basedir-temp') - .with_section_name('temp') - .with_target('/etc/icingaweb2/modules/fileshipper/imports.ini') - .with_settings( {'basedir' => '/tmp'} ) + it { + is_expected.to contain_icingaweb2__inisection('fileshipper-basedir-temp') + .with_section_name('temp') + .with_target('/etc/icingaweb2/modules/fileshipper/imports.ini') + .with_settings('basedir' => '/tmp') } end context "#{os} with a directory" do - let(:params) { { - :git_revision => 'v1.0.0', - :directories => { - 'test' => { - 'source' => '/tmp/source', - 'target' => '/tmp/target', - 'extensions' => '.foobar' - } - } - } } + let(:params) do + { + git_revision: 'v1.0.0', + directories: { + 'test' => { + 'source' => '/tmp/source', + 'target' => '/tmp/target', + 'extensions' => '.foobar', + }, + }, + } + end - it { is_expected.to contain_icingaweb2__module('fileshipper') - .with_install_method('git') - .with_git_revision('v1.0.0') + it { + is_expected.to contain_icingaweb2__module('fileshipper') + .with_install_method('git') + .with_git_revision('v1.0.0') } - it { is_expected.to contain_icingaweb2__module__fileshipper__directory('test') - .with_source('/tmp/source') - .with_target('/tmp/target') - .with_extensions('.foobar') + it { + is_expected.to contain_icingaweb2__module__fileshipper__directory('test') + .with_source('/tmp/source') + .with_target('/tmp/target') + .with_extensions('.foobar') } - it { is_expected.to contain_icingaweb2__inisection('fileshipper-directory-test') - .with_section_name('test') - .with_target('/etc/icingaweb2/modules/fileshipper/directories.ini') - .with_settings( {'source' => '/tmp/source', 'target' => '/tmp/target', 'extensions' => '.foobar'} ) + it { + is_expected.to contain_icingaweb2__inisection('fileshipper-directory-test') + .with_section_name('test') + .with_target('/etc/icingaweb2/modules/fileshipper/directories.ini') + .with_settings('source' => '/tmp/source', 'target' => '/tmp/target', 'extensions' => '.foobar') } end end end -end \ No newline at end of file +end diff --git a/spec/classes/generictts_spec.rb b/spec/classes/generictts_spec.rb index 569f584..4dd0c9c 100644 --- a/spec/classes/generictts_spec.rb +++ b/spec/classes/generictts_spec.rb @@ -1,52 +1,60 @@ require 'spec_helper' -describe('icingaweb2::module::generictts', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::generictts', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with git_revision 'v2.0.0'" do - let(:params) { { :git_revision => 'v2.0.0', } } + let(:params) { { git_revision: 'v2.0.0' } } - it { is_expected.to contain_icingaweb2__module('generictts') - .with_install_method('git') - .with_git_revision('v2.0.0') + it { + is_expected.to contain_icingaweb2__module('generictts') + .with_install_method('git') + .with_git_revision('v2.0.0') } end context "#{os} with a ticketsystem" do - let(:params) { { - :git_revision => 'v2.0.0', - :ticketsystems => { - 'foo' => { - 'pattern' => 'foobar', - 'url' => 'barfoo' - } - } - } } - - it { is_expected.to contain_icingaweb2__module__generictts__ticketsystem('foo') - .with_pattern('foobar') - .with_url('barfoo') + let(:params) do + { + git_revision: 'v2.0.0', + ticketsystems: { + 'foo' => { + 'pattern' => 'foobar', + 'url' => 'barfoo', + }, + }, + } + end + + it { + is_expected.to contain_icingaweb2__module__generictts__ticketsystem('foo') + .with_pattern('foobar') + .with_url('barfoo') } - it { is_expected.to contain_icingaweb2__inisection('generictts-ticketsystem-foo') - .with_section_name('foo') - .with_target('/etc/icingaweb2/modules/generictts/config.ini') - .with_settings( {'pattern' => 'foobar', 'url' => 'barfoo'} ) + it { + is_expected.to contain_icingaweb2__inisection('generictts-ticketsystem-foo') + .with_section_name('foo') + .with_target('/etc/icingaweb2/modules/generictts/config.ini') + .with_settings('pattern' => 'foobar', 'url' => 'barfoo') } - it { is_expected.to contain_icingaweb2__module('generictts') - .with_install_method('git') - .with_git_revision('v2.0.0') + it { + is_expected.to contain_icingaweb2__module('generictts') + .with_install_method('git') + .with_git_revision('v2.0.0') } end end end end diff --git a/spec/classes/graphite_spec.rb b/spec/classes/graphite_spec.rb index 51e82d8..114e9e0 100644 --- a/spec/classes/graphite_spec.rb +++ b/spec/classes/graphite_spec.rb @@ -1,59 +1,68 @@ require 'spec_helper' -describe('icingaweb2::module::graphite', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::graphite', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with git_revision 'v0.9.0'" do - let(:params) { { :git_revision => 'v0.9.0', :url => 'http://localhost' } } + let(:params) { { git_revision: 'v0.9.0', url: 'http://localhost' } } - it { is_expected.to contain_icingaweb2__module('graphite') - .with_install_method('git') - .with_git_revision('v0.9.0') + it { + is_expected.to contain_icingaweb2__module('graphite') + .with_install_method('git') + .with_git_revision('v0.9.0') } - it { is_expected.to contain_icingaweb2__inisection('module-graphite-graphite') - .with_section_name('graphite') - .with_target('/etc/icingaweb2/modules/graphite/config.ini') - .with_settings( {'url' => 'http://localhost'} ) + it { + is_expected.to contain_icingaweb2__inisection('module-graphite-graphite') + .with_section_name('graphite') + .with_target('/etc/icingaweb2/modules/graphite/config.ini') + .with_settings('url' => 'http://localhost') } end context "#{os} with all parameters set" do - let(:params) { { - :git_revision => 'v0.9.0', - :url => 'http://localhost', - :user => 'foo', - :password => 'bar', - :graphite_writer_host_name_template => 'foobar', - :graphite_writer_service_name_template => 'barfoo' - } } - - it { is_expected.to contain_icingaweb2__module('graphite') - .with_install_method('git') - .with_git_revision('v0.9.0') + let(:params) do + { + git_revision: 'v0.9.0', + url: 'http://localhost', + user: 'foo', + password: 'bar', + graphite_writer_host_name_template: 'foobar', + graphite_writer_service_name_template: 'barfoo', + } + end + + it { + is_expected.to contain_icingaweb2__module('graphite') + .with_install_method('git') + .with_git_revision('v0.9.0') } - it { is_expected.to contain_icingaweb2__inisection('module-graphite-graphite') - .with_section_name('graphite') - .with_target('/etc/icingaweb2/modules/graphite/config.ini') - .with_settings( {'url' => 'http://localhost', 'user' => 'foo', 'password' => 'bar'} ) + it { + is_expected.to contain_icingaweb2__inisection('module-graphite-graphite') + .with_section_name('graphite') + .with_target('/etc/icingaweb2/modules/graphite/config.ini') + .with_settings('url' => 'http://localhost', 'user' => 'foo', 'password' => 'bar') } - it { is_expected.to contain_icingaweb2__inisection('module-graphite-icinga') - .with_section_name('icinga') - .with_target('/etc/icingaweb2/modules/graphite/config.ini') - .with_settings( {'graphite_writer_host_name_template' => 'foobar', - 'graphite_writer_service_name_template' => 'barfoo'} ) + it { + is_expected.to contain_icingaweb2__inisection('module-graphite-icinga') + .with_section_name('icinga') + .with_target('/etc/icingaweb2/modules/graphite/config.ini') + .with_settings('graphite_writer_host_name_template' => 'foobar', + 'graphite_writer_service_name_template' => 'barfoo') } end end end -end \ No newline at end of file +end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index cf84f93..8e90782 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,41 +1,38 @@ require 'spec_helper' -describe 'icingaweb2', :type => :class do +describe 'icingaweb2', type: :class do on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end - before(:all) do - @conf_dir = '/etc/icingaweb2' - end + let(:conf_dir) { '/etc/icingaweb2' } context 'with all default parameters' do it { is_expected.to compile } it { is_expected.to contain_class('icingaweb2::config') } it { is_expected.to contain_class('icingaweb2::install') } it { is_expected.to contain_class('icingaweb2::repo') } - it { is_expected.to contain_package('icingaweb2').with({ 'ensure' => 'installed' }) } + it { is_expected.to contain_package('icingaweb2').with('ensure' => 'installed') } case facts[:osfamily] - when 'Debian' - it { is_expected.not_to contain_apt__source('icinga-stable-release') } - when 'RedHat' - it { is_expected.not_to contain_yumrepo('icinga-stable-release') } - when 'Suse' - it { is_expected.not_to contain_zypprepo('icinga-stable-release') } + when 'Debian' + it { is_expected.not_to contain_apt__source('icinga-stable-release') } + when 'RedHat' + it { is_expected.not_to contain_yumrepo('icinga-stable-release') } + when 'Suse' + it { is_expected.not_to contain_zypprepo('icinga-stable-release') } end context "#{os} with manage_package => false" do - let(:params) { {:manage_package => false} } + let(:params) { { manage_package: false } } - it { is_expected.not_to contain_package('icinga2').with({ 'ensure' => 'installed' }) } + it { is_expected.not_to contain_package('icinga2').with('ensure' => 'installed') } end end - end end end diff --git a/spec/classes/monitoring_spec.rb b/spec/classes/monitoring_spec.rb index 7c6282a..c9f8391 100644 --- a/spec/classes/monitoring_spec.rb +++ b/spec/classes/monitoring_spec.rb @@ -1,173 +1,178 @@ require 'spec_helper' -describe('icingaweb2::module::monitoring', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::monitoring', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end case facts[:osfamily] - when 'Debian' - before(:all) do - @install_method = 'package' - @package_name = 'icingaweb2-module-monitoring' - end - else - before(:all) do - @install_method = 'none' - @package_name = nil - end + when 'Debian' + let(:install_method) { 'package' } + let(:package_name) { 'icingaweb2-module-monitoring' } + else + let(:install_method) { 'none' } + let(:package_name) { nil } end context "#{os} with ido_type 'mysql' and commandtransport 'api'" do - let(:params) { { :ido_type => 'mysql', - :ido_host => 'localhost', - :ido_db_name => 'icinga2', - :ido_db_username => 'icinga2', - :ido_db_password => 'icinga2', - :commandtransports => { - 'foo' => { - 'username' => 'root', - 'password' => 'foobar', - } - } } } - - - it { is_expected.to contain_icingaweb2__module('monitoring') - .with_install_method(@install_method) - .with_package_name(@package_name) - .with_module_dir('/usr/share/icingaweb2/modules/monitoring') - .with_settings({ - 'module-monitoring-backends'=>{ - 'section_name' => 'backends', - 'target'=>'/etc/icingaweb2/modules/monitoring/backends.ini', - 'settings'=>{ - 'type'=>'ido', - 'resource'=>'icingaweb2-module-monitoring' - } + let(:params) do + { ido_type: 'mysql', + ido_host: 'localhost', + ido_db_name: 'icinga2', + ido_db_username: 'icinga2', + ido_db_password: 'icinga2', + commandtransports: { + 'foo' => { + 'username' => 'root', + 'password' => 'foobar', + }, + } } + end + + it { + is_expected.to contain_icingaweb2__module('monitoring') + .with_install_method(install_method) + .with_package_name(package_name) + .with_module_dir('/usr/share/icingaweb2/modules/monitoring') + .with_settings('module-monitoring-backends' => { + 'section_name' => 'backends', + 'target' => '/etc/icingaweb2/modules/monitoring/backends.ini', + 'settings' => { + 'type' => 'ido', + 'resource' => 'icingaweb2-module-monitoring', }, - 'module-monitoring-security'=>{ - 'section_name' => 'security', - 'target'=>'/etc/icingaweb2/modules/monitoring/config.ini', - 'settings'=>{ - 'protected_customvars'=>'*pw*,*pass*,community' - } - } - }) } - - it { is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-monitoring') - .with_type('db') - .with_db_type('mysql') - .with_host('localhost') - .with_port('3306') - .with_db_name('icinga2') - .with_db_username('icinga2') - .with_db_password('icinga2') + }, + 'module-monitoring-security' => { + 'section_name' => 'security', + 'target' => '/etc/icingaweb2/modules/monitoring/config.ini', + 'settings' => { + 'protected_customvars' => '*pw*,*pass*,community', + }, + }) } + + it { + is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-monitoring') + .with_type('db') + .with_db_type('mysql') + .with_host('localhost') + .with_port('3306') + .with_db_name('icinga2') + .with_db_username('icinga2') + .with_db_password('icinga2') } - it { is_expected.to contain_icingaweb2__module__monitoring__commandtransport('foo') - .with_username('root') - .with_password('foobar') + it { + is_expected.to contain_icingaweb2__module__monitoring__commandtransport('foo') + .with_username('root') + .with_password('foobar') } end context "#{os} with ido_type 'pgsql' and commandtransport 'local'" do - let(:params) { { :ido_type => 'pgsql', - :ido_host => 'localhost', - :ido_port => 5432, - :ido_db_name => 'icinga2', - :ido_db_username => 'icinga2', - :ido_db_password => 'icinga2', - :commandtransports => { - 'foo' => { - 'transport' => 'local', - } - } } } - - it { is_expected.to contain_icingaweb2__module('monitoring') - .with_install_method(@install_method) - .with_package_name(@package_name) - .with_module_dir('/usr/share/icingaweb2/modules/monitoring') - .with_settings({ - 'module-monitoring-backends'=>{ - 'section_name' => 'backends', - 'target'=>'/etc/icingaweb2/modules/monitoring/backends.ini', - 'settings'=>{ - 'type'=>'ido', - 'resource'=>'icingaweb2-module-monitoring' - } + let(:params) do + { ido_type: 'pgsql', + ido_host: 'localhost', + ido_port: 5432, + ido_db_name: 'icinga2', + ido_db_username: 'icinga2', + ido_db_password: 'icinga2', + commandtransports: { + 'foo' => { + 'transport' => 'local', + }, + } } + end + + it do + is_expected.to contain_icingaweb2__module('monitoring') + .with_install_method(install_method) + .with_package_name(package_name) + .with_module_dir('/usr/share/icingaweb2/modules/monitoring') + .with_settings('module-monitoring-backends' => { + 'section_name' => 'backends', + 'target' => '/etc/icingaweb2/modules/monitoring/backends.ini', + 'settings' => { + 'type' => 'ido', + 'resource' => 'icingaweb2-module-monitoring', }, - 'module-monitoring-security'=>{ - 'section_name' => 'security', - 'target'=>'/etc/icingaweb2/modules/monitoring/config.ini', - 'settings'=>{ - 'protected_customvars'=>'*pw*,*pass*,community' - } - } - }) } - - it { is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-monitoring') - .with_type('db') - .with_db_type('pgsql') - .with_host('localhost') - .with_port(5432) - .with_db_name('icinga2') - .with_db_username('icinga2') - .with_db_password('icinga2') + }, + 'module-monitoring-security' => { + 'section_name' => 'security', + 'target' => '/etc/icingaweb2/modules/monitoring/config.ini', + 'settings' => { + 'protected_customvars' => '*pw*,*pass*,community', + }, + }) + end + + it { + is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-monitoring') + .with_type('db') + .with_db_type('pgsql') + .with_host('localhost') + .with_port(5432) + .with_db_name('icinga2') + .with_db_username('icinga2') + .with_db_password('icinga2') } if facts[:osfamily] == 'Debian' - it { is_expected.to contain_package('icingaweb2-module-monitoring').with({ 'ensure' => 'present' }) } + it { is_expected.to contain_package('icingaweb2-module-monitoring').with('ensure' => 'present') } end - it { is_expected.to contain_icingaweb2__module__monitoring__commandtransport('foo') - .with_transport('local') + it { + is_expected.to contain_icingaweb2__module__monitoring__commandtransport('foo') + .with_transport('local') } end context "#{os} with invalid ido_type" do - let(:params) { { :ido_type => 'foobar' } } + let(:params) { { ido_type: 'foobar' } } - it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['mysql', 'pgsql'\]/) } + it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['mysql', 'pgsql'\]}) } end context "#{os} with array protected_customvars" do - let(:params) { { :ido_type => 'mysql', - :ido_host => 'localhost', - :ido_db_name => 'icinga2', - :ido_db_username => 'icinga2', - :ido_db_password => 'icinga2', - :commandtransports => { - 'foo' => { - 'transport' => 'local', - } - }, - :protected_customvars => ['foo', 'bar', '*baz*'] } } - - it { is_expected.to contain_icingaweb2__module('monitoring') - .with_settings({ - 'module-monitoring-backends'=>{ - 'section_name' => 'backends', - 'target'=>'/etc/icingaweb2/modules/monitoring/backends.ini', - 'settings'=>{ - 'type'=>'ido', - 'resource'=>'icingaweb2-module-monitoring' - } + let(:params) do + { ido_type: 'mysql', + ido_host: 'localhost', + ido_db_name: 'icinga2', + ido_db_username: 'icinga2', + ido_db_password: 'icinga2', + commandtransports: { + 'foo' => { + 'transport' => 'local', + }, + }, + protected_customvars: ['foo', 'bar', '*baz*'] } + end + + it { + is_expected.to contain_icingaweb2__module('monitoring') + .with_settings('module-monitoring-backends' => { + 'section_name' => 'backends', + 'target' => '/etc/icingaweb2/modules/monitoring/backends.ini', + 'settings' => { + 'type' => 'ido', + 'resource' => 'icingaweb2-module-monitoring', + }, + }, + 'module-monitoring-security' => { + 'section_name' => 'security', + 'target' => '/etc/icingaweb2/modules/monitoring/config.ini', + 'settings' => { + 'protected_customvars' => 'foo,bar,*baz*', }, - 'module-monitoring-security'=>{ - 'section_name' => 'security', - 'target'=>'/etc/icingaweb2/modules/monitoring/config.ini', - 'settings'=>{ - 'protected_customvars'=>'foo,bar,*baz*' - } - } - }) } + }) } end end end end diff --git a/spec/classes/puppetdb_spec.rb b/spec/classes/puppetdb_spec.rb index 6025f53..df14132 100644 --- a/spec/classes/puppetdb_spec.rb +++ b/spec/classes/puppetdb_spec.rb @@ -1,198 +1,221 @@ require 'spec_helper' -describe('icingaweb2::module::puppetdb', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::puppetdb', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end - context "with ensure present, git_revision, ssl and certificates to their defaults" do - let(:params) { { :ensure => 'present', } } + context 'with ensure present, git_revision, ssl and certificates to their defaults' do + let(:params) { { ensure: 'present' } } - it { is_expected.to contain_icingaweb2__module('puppetdb') - .with_ensure('present') - .with_install_method('git') - .with_git_repository('https://github.com/Icinga/icingaweb2-module-puppetdb.git') - .with_git_revision('master') - .with_module_dir('/usr/share/icingaweb2/modules/puppetdb') - } + it { + is_expected.to contain_icingaweb2__module('puppetdb') + .with_ensure('present') + .with_install_method('git') + .with_git_repository('https://github.com/Icinga/icingaweb2-module-puppetdb.git') + .with_git_revision('master') + .with_module_dir('/usr/share/icingaweb2/modules/puppetdb') + } - it { is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') - .with_ensure('directory') - } + it { + is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') + .with_ensure('directory') + } it { is_expected.to have_icingaweb2__module__puppetdb__certificate_resource_count(0) } end - context "with ensure absent" do - let(:params) { { :ensure => 'absent', } } + context 'with ensure absent' do + let(:params) { { ensure: 'absent' } } - it { is_expected.to contain_icingaweb2__module('puppetdb') - .with_ensure('absent') - } + it { + is_expected.to contain_icingaweb2__module('puppetdb') + .with_ensure('absent') + } end - context "with ensure foo" do - let(:params) { { :ensure => 'foo' } } + context 'with ensure foo' do + let(:params) { { ensure: 'foo' } } - it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['absent', 'present'\]/) } + it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['absent', 'present'\]}) } end - context "with ensure absent" do - let(:params) { { :ensure => 'absent', } } + context 'with ensure absent' do + let(:params) { { ensure: 'absent' } } - it { is_expected.to contain_icingaweb2__module('puppetdb') - .with_ensure('absent') - } + it { + is_expected.to contain_icingaweb2__module('puppetdb') + .with_ensure('absent') + } - it { is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') - .with_ensure('directory') - } + it { + is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') + .with_ensure('directory') + } it { is_expected.not_to contain_file('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb') } - end - context "with git_revision set to 123" do - let(:params) { { :git_revision => '123', } } + context 'with git_revision set to 123' do + let(:params) { { git_revision: '123' } } - it { is_expected.to contain_icingaweb2__module('puppetdb') - .with_ensure('present') - .with_git_revision('123') - } + it { + is_expected.to contain_icingaweb2__module('puppetdb') + .with_ensure('present') + .with_git_revision('123') + } end - context "with ssl set to none" do - let(:params) { { :ssl => 'none', } } + context 'with ssl set to none' do + let(:params) { { ssl: 'none' } } it { is_expected.to contain_icingaweb2__module('puppetdb') } - it { is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') - .with_ensure('directory') - } + it { + is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') + .with_ensure('directory') + } it { is_expected.not_to contain_file('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb') } end - context "with ssl set to none and two certificates" do - let(:params) { { :ssl => 'none', - :certificates => { 'pupdb1' => - { 'ssl_key' => 'mysslkey1', 'ssl_cacert' => 'mycacert1'}, - 'pupdb2' => - { 'ssl_key' => 'mysslkey2', 'ssl_cacert' => 'mycacert2'}, - } - } } + context 'with ssl set to none and two certificates' do + let(:params) do + { ssl: 'none', + certificates: { 'pupdb1' => + { 'ssl_key' => 'mysslkey1', 'ssl_cacert' => 'mycacert1' }, + 'pupdb2' => + { 'ssl_key' => 'mysslkey2', 'ssl_cacert' => 'mycacert2' } } } + end it { is_expected.to contain_icingaweb2__module('puppetdb') } - it { is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') - .with_ensure('directory') - } + it { + is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') + .with_ensure('directory') + } it { is_expected.to have_icingaweb2__module__puppetdb__certificate_resource_count(2) } - it { is_expected.to contain_icingaweb2__module__puppetdb__certificate('pupdb1') - .with_ssl_key('mysslkey1') - .with_ssl_cacert('mycacert1') - } - it { is_expected.to contain_icingaweb2__module__puppetdb__certificate('pupdb2') - .with_ssl_key('mysslkey2') - .with_ssl_cacert('mycacert2') - } + it { + is_expected.to contain_icingaweb2__module__puppetdb__certificate('pupdb1') + .with_ssl_key('mysslkey1') + .with_ssl_cacert('mycacert1') + } + it { + is_expected.to contain_icingaweb2__module__puppetdb__certificate('pupdb2') + .with_ssl_key('mysslkey2') + .with_ssl_cacert('mycacert2') + } end - context "with ssl set to puppet and host to puppetdb.example.com" do - let(:params) { { :ssl => 'puppet', :host => 'puppetdb.example.com' } } - let(:facts) { facts.merge({ :fqdn => 'puppetdb' }) } + context 'with ssl set to puppet and host to puppetdb.example.com' do + let(:params) { { ssl: 'puppet', host: 'puppetdb.example.com' } } + let(:facts) { facts.merge(fqdn: 'puppetdb') } it { is_expected.to contain_icingaweb2__module('puppetdb') } - it { is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') - .with_ensure('directory') - } - it { is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com') - .with_ensure('directory') - } - it { is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys') - .with_ensure('directory') - } - it { is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/certs') - .with_ensure('directory') - } - - it { is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/certs/ca.pem') - .with_ensure('present') - .with_mode('0640') - .with_source("#{Puppet.settings['ssldir']}/certs/ca.pem") - } + it { + is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') + .with_ensure('directory') + } + it { + is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com') + .with_ensure('directory') + } + it { + is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys') + .with_ensure('directory') + } + it { + is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/certs') + .with_ensure('directory') + } + + it { + is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/certs/ca.pem') + .with_ensure('present') + .with_mode('0640') + .with_source("#{Puppet.settings['ssldir']}/certs/ca.pem") + } it { is_expected.to have_icingaweb2__module__puppetdb__certificate_resource_count(0) } - it { is_expected.to contain_concat('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') - .with_ensure('present') - .with_warn('false') - .with_mode('0640') - .with_ensure_newline(true) - } - - it { is_expected.to contain_concat__fragment('private_key') - .with_target('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') - .with_source("#{Puppet.settings['ssldir']}/private_keys/puppetdb.pem") - .with_order('1') - } - - it { is_expected.to contain_concat__fragment('public_key') - .with_target('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') - .with_source("#{Puppet.settings['ssldir']}/certs/puppetdb.pem") - .with_order('2') - } + it { + is_expected.to contain_concat('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') + .with_ensure('present') + .with_warn('false') + .with_mode('0640') + .with_ensure_newline(true) + } + + it { + is_expected.to contain_concat__fragment('private_key') + .with_target('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') + .with_source("#{Puppet.settings['ssldir']}/private_keys/puppetdb.pem") + .with_order('1') + } + + it { + is_expected.to contain_concat__fragment('public_key') + .with_target('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') + .with_source("#{Puppet.settings['ssldir']}/certs/puppetdb.pem") + .with_order('2') + } end - context "with ssl set to puppet and one extra certificate" do - let(:params) { { :ssl => 'puppet', - :host => 'puppetdb.example.com', - :certificates => { 'pupdb1' => - { 'ssl_key' => 'mysslkey1', 'ssl_cacert' => 'mycacert1'}, - }, - } } + context 'with ssl set to puppet and one extra certificate' do + let(:params) do + { ssl: 'puppet', + host: 'puppetdb.example.com', + certificates: { 'pupdb1' => + { 'ssl_key' => 'mysslkey1', 'ssl_cacert' => 'mycacert1' } } } + end - let(:facts) { facts.merge({ :fqdn => 'puppetdb' }) } + let(:facts) { facts.merge(fqdn: 'puppetdb') } it { is_expected.to contain_icingaweb2__module('puppetdb') } - it { is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') - .with_ensure('directory') - } + it { + is_expected.to contain_file('/etc/icingaweb2/modules/puppetdb/ssl') + .with_ensure('directory') + } it { is_expected.to have_icingaweb2__module__puppetdb__certificate_resource_count(1) } - it { is_expected.to contain_icingaweb2__module__puppetdb__certificate('pupdb1') - .with_ssl_key('mysslkey1') - .with_ssl_cacert('mycacert1') - } - - it { is_expected.to contain_concat('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') - .with_ensure('present') - .with_warn('false') - .with_mode('0640') - .with_ensure_newline(true) - } - - it { is_expected.to contain_concat__fragment('private_key') - .with_target('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') - .with_order('1') - } - - it { is_expected.to contain_concat__fragment('public_key') - .with_target('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') - .with_order('2') - } + it { + is_expected.to contain_icingaweb2__module__puppetdb__certificate('pupdb1') + .with_ssl_key('mysslkey1') + .with_ssl_cacert('mycacert1') + } + + it { + is_expected.to contain_concat('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') + .with_ensure('present') + .with_warn('false') + .with_mode('0640') + .with_ensure_newline(true) + } + + it { + is_expected.to contain_concat__fragment('private_key') + .with_target('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') + .with_order('1') + } + + it { + is_expected.to contain_concat__fragment('public_key') + .with_target('/etc/icingaweb2/modules/puppetdb/ssl/puppetdb.example.com/private_keys/puppetdb_combined.pem') + .with_order('2') + } end - context "with ssl set to foo" do - let(:params) { { :ssl => 'foo' } } + context 'with ssl set to foo' do + let(:params) { { ssl: 'foo' } } - it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['none', 'puppet'\]/) } + it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['none', 'puppet'\]}) } end end end end - diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb index 893ac32..aa0852c 100644 --- a/spec/classes/repo_spec.rb +++ b/spec/classes/repo_spec.rb @@ -1,44 +1,36 @@ require 'spec_helper' -describe('icingaweb2::repo', :type => :class) do +describe('icingaweb2::repo', type: :class) do on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context 'with manage_repo => true' do let :pre_condition do "class { 'icingaweb2': manage_repo => true}" end case facts[:osfamily] - when 'Debian' - it { is_expected.to contain_apt__source('icinga-stable-release') } - when 'RedHat' - it { is_expected.to contain_yumrepo('icinga-stable-release') } - when 'Suse' - it { is_expected.to contain_zypprepo('icinga-stable-release') } + when 'Debian' + it { is_expected.to contain_apt__source('icinga-stable-release') } + when 'RedHat' + it { is_expected.to contain_yumrepo('icinga-stable-release') } + when 'Suse' + it { is_expected.to contain_zypprepo('icinga-stable-release') } end end context 'with manage_repo => false' do let :pre_condition do "class { 'icingaweb2': manage_repo => false}" end - case facts[:osfamily] - when 'Debian' - it { is_expected.not_to contain_apt__source('icinga-stable-release') } - it { is_expected.not_to contain_zypprepo('icinga-stable-release') } - when 'RedHat' - it { is_expected.not_to contain_yumrepo('icinga-stable-release') } - it { is_expected.not_to contain_zypprepo('icinga-stable-release') } - when 'Suse' - it { is_expected.not_to contain_yumrepo('icinga-stable-release') } - it { is_expected.not_to contain_apt__source('icinga-stable-release') } - end + it { is_expected.not_to contain_apt__source('icinga-stable-release') } + it { is_expected.not_to contain_yumrepo('icinga-stable-release') } + it { is_expected.not_to contain_zypprepo('icinga-stable-release') } end end end end diff --git a/spec/classes/translation_spec.rb b/spec/classes/translation_spec.rb index 3cd26a3..f9b8256 100644 --- a/spec/classes/translation_spec.rb +++ b/spec/classes/translation_spec.rb @@ -1,68 +1,67 @@ require 'spec_helper' -describe('icingaweb2::module::translation', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::translation', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end - context "with ensure present" do - let(:params) { { :ensure => 'present', } } + context 'with ensure present' do + let(:params) { { ensure: 'present' } } - it { is_expected.to contain_icingaweb2__module('translation') - .with_ensure('present') - .with_install_method('none') - .with_module_dir('/usr/share/icingaweb2/modules/translation') - .with_settings({ 'module-translation'=>{ - 'section_name' => 'translation', - 'target'=>'/etc/icingaweb2/modules/translation/config.ini', - 'settings'=>{ - 'msgmerge' => '/usr/bin/msgmerge', - 'xgettext' => '/usr/bin/xgettext', - 'msgfmt' => '/usr/bin/msgfmt', - } - } - }) } + it { + is_expected.to contain_icingaweb2__module('translation') + .with_ensure('present') + .with_install_method('none') + .with_module_dir('/usr/share/icingaweb2/modules/translation') + .with_settings('module-translation' => { + 'section_name' => 'translation', + 'target' => '/etc/icingaweb2/modules/translation/config.ini', + 'settings' => { + 'msgmerge' => '/usr/bin/msgmerge', + 'xgettext' => '/usr/bin/xgettext', + 'msgfmt' => '/usr/bin/msgfmt', + }, + }) } case facts[:osfamily] - when 'Debian' - it { is_expected.to contain_package('gettext').with({ 'ensure' => 'present' }) } - when 'RedHat' - it { is_expected.to contain_package('gettext').with({ 'ensure' => 'present' }) } - when 'Suse' - it { is_expected.to contain_package('gettext-tools').with({ 'ensure' => 'present' }) } + when 'Debian', 'RedHat' + it { is_expected.to contain_package('gettext').with('ensure' => 'present') } + when 'Suse' + it { is_expected.to contain_package('gettext-tools').with('ensure' => 'present') } end end - context "with ensure absent" do - let(:params) { { :ensure => 'absent', } } + context 'with ensure absent' do + let(:params) { { ensure: 'absent' } } - it { is_expected.to contain_icingaweb2__module('translation') - .with_ensure('absent') - .with_install_method('none') - .with_module_dir('/usr/share/icingaweb2/modules/translation') - } + it { + is_expected.to contain_icingaweb2__module('translation') + .with_ensure('absent') + .with_install_method('none') + .with_module_dir('/usr/share/icingaweb2/modules/translation') + } case facts[:osfamily] - when 'Debian' - it { is_expected.to contain_package('gettext').with({ 'ensure' => 'absent' }) } - when 'RedHat' - it { is_expected.to contain_package('gettext').with({ 'ensure' => 'absent' }) } - when 'Suse' - it { is_expected.to contain_package('gettext-tools').with({ 'ensure' => 'absent' }) } + when 'Debian', 'RedHat' + it { is_expected.to contain_package('gettext').with('ensure' => 'absent') } + when 'Suse' + it { is_expected.to contain_package('gettext-tools').with('ensure' => 'absent') } end end - context "with ensure foobar" do - let(:params) { { :ensure => 'foobar' } } + context 'with ensure foobar' do + let(:params) { { ensure: 'foobar' } } - it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['absent', 'present'\]/) } + it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['absent', 'present'\]}) } end end end end diff --git a/spec/classes/vsphere_spec.rb b/spec/classes/vsphere_spec.rb index a1fb06d..e8cd7e3 100644 --- a/spec/classes/vsphere_spec.rb +++ b/spec/classes/vsphere_spec.rb @@ -1,24 +1,27 @@ require 'spec_helper' -describe('icingaweb2::module::vsphere', :type => :class) do - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } +describe('icingaweb2::module::vsphere', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with git_revision 'v1.1.0'" do - let(:params) { { :git_revision => 'v1.1.0', } } + let(:params) { { git_revision: 'v1.1.0' } } - it { is_expected.to contain_icingaweb2__module('vsphere') - .with_install_method('git') - .with_git_revision('v1.1.0') + it { + is_expected.to contain_icingaweb2__module('vsphere') + .with_install_method('git') + .with_git_revision('v1.1.0') } end end end -end \ No newline at end of file +end diff --git a/spec/defines/authmethod_spec.rb b/spec/defines/authmethod_spec.rb index 0a58ab6..be116b9 100644 --- a/spec/defines/authmethod_spec.rb +++ b/spec/defines/authmethod_spec.rb @@ -1,59 +1,68 @@ require 'spec_helper' -describe('icingaweb2::config::authmethod', :type => :define) do +describe('icingaweb2::config::authmethod', type: :define) do let(:title) { 'myauthmethod' } - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with backend 'external'" do - let(:params) { { :backend => 'external', :order => '10' } } - - it { is_expected.to contain_icingaweb2__inisection('authmethod-myauthmethod') - .with_target('/etc/icingaweb2/authentication.ini') - .with_settings({'backend'=>'external'}) - .with_order('10')} + let(:params) { { backend: 'external', order: '10' } } + it { + is_expected.to contain_icingaweb2__inisection('authmethod-myauthmethod') + .with_target('/etc/icingaweb2/authentication.ini') + .with_settings('backend' => 'external') + .with_order('10') + } end context "#{os} with backend 'ldap'" do - let(:params) { { :backend => 'ldap', :resource => 'myresource', :ldap_user_class => 'users', :ldap_user_name_attribute => 'uid', :ldap_filter => 'foobar', :domain => 'icinga.com', :order => '10' } } + let(:params) { { backend: 'ldap', resource: 'myresource', ldap_user_class: 'users', ldap_user_name_attribute: 'uid', ldap_filter: 'foobar', domain: 'icinga.com', order: '10' } } - it { is_expected.to contain_icingaweb2__inisection('authmethod-myauthmethod') - .with_target('/etc/icingaweb2/authentication.ini') - .with_settings({'backend'=>'ldap', 'resource'=>'myresource', 'user_class'=>'users', 'user_name_attribute'=>'uid', 'filter'=>'foobar', 'domain'=>'icinga.com' }, ) - .with_order('10')} + it { + is_expected.to contain_icingaweb2__inisection('authmethod-myauthmethod') + .with_target('/etc/icingaweb2/authentication.ini') + .with_settings('backend' => 'ldap', 'resource' => 'myresource', 'user_class' => 'users', 'user_name_attribute' => 'uid', 'filter' => 'foobar', 'domain' => 'icinga.com') + .with_order('10') + } end context "#{os} with backend 'msldap'" do - let(:params) { { :backend => 'msldap', :resource => 'myresource', :order => '10' } } + let(:params) { { backend: 'msldap', resource: 'myresource', order: '10' } } - it { is_expected.to contain_icingaweb2__inisection('authmethod-myauthmethod') - .with_target('/etc/icingaweb2/authentication.ini') - .with_settings({'backend'=>'msldap', 'resource'=>'myresource'}) - .with_order('10')} + it { + is_expected.to contain_icingaweb2__inisection('authmethod-myauthmethod') + .with_target('/etc/icingaweb2/authentication.ini') + .with_settings('backend' => 'msldap', 'resource' => 'myresource') + .with_order('10') + } end context "#{os} with backend 'db'" do - let(:params) { { :backend => 'db', :resource => 'myresource', :order => '10' } } + let(:params) { { backend: 'db', resource: 'myresource', order: '10' } } - it { is_expected.to contain_icingaweb2__inisection('authmethod-myauthmethod') - .with_target('/etc/icingaweb2/authentication.ini') - .with_settings({'backend'=>'db', 'resource'=>'myresource'}) - .with_order('10')} + it { + is_expected.to contain_icingaweb2__inisection('authmethod-myauthmethod') + .with_target('/etc/icingaweb2/authentication.ini') + .with_settings('backend' => 'db', 'resource' => 'myresource') + .with_order('10') + } end context "#{os} with invalid backend" do - let(:params) { { :backend => 'foobar' } } + let(:params) { { backend: 'foobar' } } - it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['db', 'external', 'ldap', 'msldap'\]/) } + it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['db', 'external', 'ldap', 'msldap'\]}) } end end end end diff --git a/spec/defines/groupbackend_spec.rb b/spec/defines/groupbackend_spec.rb index 16cc81c..83dddc4 100644 --- a/spec/defines/groupbackend_spec.rb +++ b/spec/defines/groupbackend_spec.rb @@ -1,47 +1,80 @@ require 'spec_helper' -describe('icingaweb2::config::groupbackend', :type => :define) do +describe('icingaweb2::config::groupbackend', type: :define) do let(:title) { 'mygroupbackend' } - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with backend 'db'" do - let(:params) { { :backend => 'db', :resource => 'my-ldap' } } - - it { is_expected.to contain_icingaweb2__inisection('groupbackend-mygroupbackend') - .with_target('/etc/icingaweb2/groups.ini') - .with_settings({'backend'=>'db', 'resource' => 'my-ldap'})} + let(:params) { { backend: 'db', resource: 'my-ldap' } } + it { + is_expected.to contain_icingaweb2__inisection('groupbackend-mygroupbackend') + .with_target('/etc/icingaweb2/groups.ini') + .with_settings('backend' => 'db', 'resource' => 'my-ldap') + } end context "#{os} with backend 'ldap'" do - let(:params) { { :backend => 'ldap', :resource => 'my-ldap', :ldap_group_class => 'groupofnames', :ldap_group_name_attribute => 'cn', :ldap_group_member_attribute => 'member', :ldap_base_dn => 'foobar', :domain => 'icinga.com' } } + let(:params) do + { + backend: 'ldap', + resource: 'my-ldap', + ldap_group_class: 'groupofnames', + ldap_group_name_attribute: 'cn', + ldap_group_member_attribute: 'member', + ldap_base_dn: 'foobar', + domain: 'icinga.com', + } + end - it { is_expected.to contain_icingaweb2__inisection('groupbackend-mygroupbackend') - .with_target('/etc/icingaweb2/groups.ini') - .with_settings({'backend'=>'ldap', 'resource'=>'my-ldap', 'group_class'=>'groupofnames', 'group_name_attribute'=>'cn', 'group_member_attribute'=>'member', 'base_dn'=>'foobar', 'domain' => 'icinga.com'})} + it { + is_expected.to contain_icingaweb2__inisection('groupbackend-mygroupbackend') + .with_target('/etc/icingaweb2/groups.ini') + .with_settings( + 'backend' => 'ldap', + 'resource' => 'my-ldap', + 'group_class' => 'groupofnames', + 'group_name_attribute' => 'cn', + 'group_member_attribute' => 'member', + 'base_dn' => 'foobar', + 'domain' => 'icinga.com', + ) + } end context "#{os} with backend 'msldap'" do - let(:params) { { :backend => 'msldap', :resource => 'my-msldap', :ldap_user_backend => 'ad1', :ldap_nested_group_search => true, :ldap_group_filter => 'baz', :ldap_base_dn => 'foobar', :domain => 'icinga.com' } } + let(:params) { { backend: 'msldap', resource: 'my-msldap', ldap_user_backend: 'ad1', ldap_nested_group_search: true, ldap_group_filter: 'baz', ldap_base_dn: 'foobar', domain: 'icinga.com' } } - it { is_expected.to contain_icingaweb2__inisection('groupbackend-mygroupbackend') - .with_target('/etc/icingaweb2/groups.ini') - .with_settings({'backend'=>'msldap', 'resource'=>'my-msldap', 'user_backend'=>'ad1', 'nested_group_search'=>'1', 'group_filter'=>'baz', 'base_dn'=>'foobar', 'domain' => 'icinga.com' })} + it { + is_expected.to contain_icingaweb2__inisection('groupbackend-mygroupbackend') + .with_target('/etc/icingaweb2/groups.ini') + .with_settings( + 'backend' => 'msldap', + 'resource' => 'my-msldap', + 'user_backend' => 'ad1', + 'nested_group_search' => '1', + 'group_filter' => 'baz', + 'base_dn' => 'foobar', + 'domain' => 'icinga.com', + ) + } end context "#{os} with invalid backend" do - let(:params) { { :backend => 'foobar' } } + let(:params) { { backend: 'foobar' } } - it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['db', 'ldap', 'msldap'\]/) } + it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['db', 'ldap', 'msldap'\]}) } end end end end diff --git a/spec/defines/inisection_spec.rb b/spec/defines/inisection_spec.rb index eb9616b..eca7d46 100644 --- a/spec/defines/inisection_spec.rb +++ b/spec/defines/inisection_spec.rb @@ -1,27 +1,31 @@ require 'spec_helper' -describe('icingaweb2::inisection', :type => :define) do +describe('icingaweb2::inisection', type: :define) do let(:title) { 'foo' } - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with valid params" do - let(:params) { {:target => '/foo/bar', :section_name => 'test', :settings => {'setting1' => 'value1', 'setting2' => 'value2'} } } + let(:params) { { target: '/foo/bar', section_name: 'test', settings: { 'setting1' => 'value1', 'setting2' => 'value2' } } } it { is_expected.to contain_concat('/foo/bar') } - it { is_expected.to contain_concat__fragment('foo-test-01') - .with_target('/foo/bar') - .with_order('01') - .with_content(/\[test\]\nsetting1 = \"value1\"\nsetting2 = \"value2\"\n\n/) } + it { + is_expected.to contain_concat__fragment('foo-test-01') + .with_target('/foo/bar') + .with_order('01') + .with_content(%r{\[test\]\nsetting1 = \"value1\"\nsetting2 = \"value2\"\n\n}) + } end end end end diff --git a/spec/defines/module_spec.rb b/spec/defines/module_spec.rb index 6451009..ea63f3e 100644 --- a/spec/defines/module_spec.rb +++ b/spec/defines/module_spec.rb @@ -1,81 +1,99 @@ require 'spec_helper' -describe('icingaweb2::module', :type => :define) do +describe('icingaweb2::module', type: :define) do let(:title) { 'mymodule' } - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with install_method 'none'" do - let(:params) { { :module => 'foo', - :module_dir => '/usr/local/icingaweb2-modules/foo', - :install_method => 'none', - :settings => {'section1' => { 'target' => '/foo/bar', 'settings' => {'setting1' => 'value1', 'setting2' => 'value2' } } } } } + let(:params) do + { module: 'foo', + module_dir: '/usr/local/icingaweb2-modules/foo', + install_method: 'none', + settings: { 'section1' => { 'target' => '/foo/bar', 'settings' => { 'setting1' => 'value1', 'setting2' => 'value2' } } } } + end it { is_expected.to contain_file('/etc/icingaweb2/enabledModules') } it { is_expected.to contain_file('/etc/icingaweb2/enabledModules/foo') } it { is_expected.to contain_file('/etc/icingaweb2/modules') } it { is_expected.to contain_file('/etc/icingaweb2/modules/foo') } - it { is_expected.to contain_icingaweb2__inisection('section1') - .with_target('/foo/bar') - .with_settings({'setting1' => 'value1', 'setting2' => 'value2'})} + it { + is_expected.to contain_icingaweb2__inisection('section1') + .with_target('/foo/bar') + .with_settings('setting1' => 'value1', 'setting2' => 'value2') + } end context "#{os} with install_method 'git'" do - let(:params) { { :module => 'foo', - :module_dir => '/usr/local/icingaweb2-modules/foo', - :git_repository => 'https://github.com/icinga/foo.git', - :git_revision => 'master', - :settings => {'section1' => { 'target' => '/foo/bar', 'settings' => {'setting1' => 'value1', 'setting2' => 'value2' } } } } } + let(:params) do + { module: 'foo', + module_dir: '/usr/local/icingaweb2-modules/foo', + git_repository: 'https://github.com/icinga/foo.git', + git_revision: 'master', + settings: { 'section1' => { 'target' => '/foo/bar', 'settings' => { 'setting1' => 'value1', 'setting2' => 'value2' } } } } + end it { is_expected.to contain_file('/etc/icingaweb2/enabledModules') } it { is_expected.to contain_file('/etc/icingaweb2/enabledModules/foo') } it { is_expected.to contain_file('/etc/icingaweb2/modules') } it { is_expected.to contain_file('/etc/icingaweb2/modules/foo') } - it { is_expected.to contain_vcsrepo('/usr/local/icingaweb2-modules/foo') - .with_provider('git') - .with_source('https://github.com/icinga/foo.git') - .with_revision('master')} + it { + is_expected.to contain_vcsrepo('/usr/local/icingaweb2-modules/foo') + .with_provider('git') + .with_source('https://github.com/icinga/foo.git') + .with_revision('master') + } - it { is_expected.to contain_icingaweb2__inisection('section1') - .with_target('/foo/bar') - .with_settings({'setting1' => 'value1', 'setting2' => 'value2'})} + it { + is_expected.to contain_icingaweb2__inisection('section1') + .with_target('/foo/bar') + .with_settings('setting1' => 'value1', 'setting2' => 'value2') + } end context "#{os} with install_method 'package'" do - let(:params) { { :module => 'foo', - :module_dir => '/usr/local/icingaweb2-modules/foo', - :install_method => 'package', - :package_name => 'foo', - :settings => {'section1' => { 'target' => '/foo/bar', 'settings' => {'setting1' => 'value1', 'setting2' => 'value2' } } } } } + let(:params) do + { module: 'foo', + module_dir: '/usr/local/icingaweb2-modules/foo', + install_method: 'package', + package_name: 'foo', + settings: { 'section1' => { 'target' => '/foo/bar', 'settings' => { 'setting1' => 'value1', 'setting2' => 'value2' } } } } + end it { is_expected.to contain_file('/etc/icingaweb2/enabledModules') } it { is_expected.to contain_file('/etc/icingaweb2/enabledModules/foo') } it { is_expected.to contain_file('/etc/icingaweb2/modules') } it { is_expected.to contain_file('/etc/icingaweb2/modules/foo') } - it { is_expected.to contain_package('foo').with({ 'ensure' => 'present' }) } + it { is_expected.to contain_package('foo').with('ensure' => 'present') } - it { is_expected.to contain_icingaweb2__inisection('section1') - .with_target('/foo/bar') - .with_settings({'setting1' => 'value1', 'setting2' => 'value2'})} + it { + is_expected.to contain_icingaweb2__inisection('section1') + .with_target('/foo/bar') + .with_settings('setting1' => 'value1', 'setting2' => 'value2') + } end context "#{os} with invalid installation_method" do - let(:params) { { :module => 'foor', - :module_dir => '/usr/local/icingaweb2-modules/foo', - :install_method => 'foobar' } } + let(:params) do + { module: 'foor', + module_dir: '/usr/local/icingaweb2-modules/foo', + install_method: 'foobar' } + end - it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['git', 'none', 'package'\]/) } + it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['git', 'none', 'package'\]}) } end end end end diff --git a/spec/defines/resource_spec.rb b/spec/defines/resource_spec.rb index 86a2c3e..557875f 100644 --- a/spec/defines/resource_spec.rb +++ b/spec/defines/resource_spec.rb @@ -1,70 +1,107 @@ require 'spec_helper' -describe('icingaweb2::config::resource', :type => :define) do +describe('icingaweb2::config::resource', type: :define) do let(:title) { 'myresource' } - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with type db" do - let(:params) { { - :type => 'db', - :host => 'localhost', - :port => 3306, - :db_type => 'mysql', - :db_name => 'foo', - :db_username => 'bar', - :db_password => 'secret' } } - - it { is_expected.to contain_icingaweb2__inisection('resource-myresource') - .with_target('/etc/icingaweb2/resources.ini') - .with_settings({'type'=>'db', 'db'=>'mysql', 'host'=>'localhost', 'port'=>'3306', 'dbname'=>'foo', 'username'=>'bar', 'password'=>'secret'}) } + let(:params) do + { + type: 'db', + host: 'localhost', + port: 3306, + db_type: 'mysql', + db_name: 'foo', + db_username: 'bar', + db_password: 'secret', + } + end + it { + is_expected.to contain_icingaweb2__inisection('resource-myresource') + .with_target('/etc/icingaweb2/resources.ini') + .with_settings('type' => 'db', 'db' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'dbname' => 'foo', 'username' => 'bar', 'password' => 'secret') + } end context "#{os} with type ldap" do - let(:params) { { - :type => 'ldap', - :host => 'localhost', - :port => 389, - :ldap_root_dn => 'cn=foo,dc=bar', - :ldap_bind_dn => 'cn=root,dc=bar', - :ldap_bind_pw => 'secret' } } + let(:params) do + { + type: 'ldap', + host: 'localhost', + port: 389, + ldap_root_dn: 'cn=foo,dc=bar', + ldap_bind_dn: 'cn=root,dc=bar', + ldap_bind_pw: 'secret', + } + end - it { is_expected.to contain_icingaweb2__inisection('resource-myresource') - .with_target('/etc/icingaweb2/resources.ini') - .with_settings({'type'=>'ldap', 'hostname'=>'localhost', 'port'=>'389', 'root_dn'=>'cn=foo,dc=bar', 'bind_dn'=>'cn=root,dc=bar', 'bind_pw'=>'secret', 'encryption'=>'none', 'timeout' => '5'})} + it { + is_expected.to contain_icingaweb2__inisection('resource-myresource') + .with_target('/etc/icingaweb2/resources.ini') + .with_settings( + 'type' => 'ldap', + 'hostname' => 'localhost', + 'port' => '389', + 'root_dn' => 'cn=foo,dc=bar', + 'bind_dn' => 'cn=root,dc=bar', + 'bind_pw' => 'secret', + 'encryption' => 'none', + 'timeout' => '5', + ) + } end context "#{os} with type ldap and changed ldap timeout" do - let(:params) { { - :type => 'ldap', - :host => 'localhost', - :port => 389, - :ldap_root_dn => 'cn=foo,dc=bar', - :ldap_bind_dn => 'cn=root,dc=bar', - :ldap_bind_pw => 'secret', - :ldap_timeout => 60 } } + let(:params) do + { + type: 'ldap', + host: 'localhost', + port: 389, + ldap_root_dn: 'cn=foo,dc=bar', + ldap_bind_dn: 'cn=root,dc=bar', + ldap_bind_pw: 'secret', + ldap_timeout: 60, + } + end - it { is_expected.to contain_icingaweb2__inisection('resource-myresource') - .with_target('/etc/icingaweb2/resources.ini') - .with_settings({'type'=>'ldap', 'hostname'=>'localhost', 'port'=>'389', 'root_dn'=>'cn=foo,dc=bar', 'bind_dn'=>'cn=root,dc=bar', 'bind_pw'=>'secret', 'encryption'=>'none', 'timeout' => '60'})} + it { + is_expected.to contain_icingaweb2__inisection('resource-myresource') + .with_target('/etc/icingaweb2/resources.ini') + .with_settings( + 'type' => 'ldap', + 'hostname' => 'localhost', + 'port' => '389', + 'root_dn' => 'cn=foo,dc=bar', + 'bind_dn' => 'cn=root,dc=bar', + 'bind_pw' => 'secret', + 'encryption' => 'none', + 'timeout' => '60', + ) + } end context "#{os} with invalid type" do - let(:params) { { - :type => 'foobar', - :host => 'localhost', - :port => 3306 } } + let(:params) do + { + type: 'foobar', + host: 'localhost', + port: 3306, + } + end - it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['db', 'ldap'\]/) } + it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['db', 'ldap'\]}) } end end end end diff --git a/spec/defines/role_spec.rb b/spec/defines/role_spec.rb index 5152720..6b66ba6 100644 --- a/spec/defines/role_spec.rb +++ b/spec/defines/role_spec.rb @@ -1,34 +1,38 @@ require 'spec_helper' -describe('icingaweb2::config::role', :type => :define) do +describe('icingaweb2::config::role', type: :define) do let(:title) { 'myrole' } - let(:pre_condition) { [ - "class { 'icingaweb2': }" - ] } + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with users => 'bob, pete' and permissions => '*'" do - let(:params) { { :users => 'bob, pete', :permissions => '*' } } - - it { is_expected.to contain_icingaweb2__inisection('role-myrole') - .with_target('/etc/icingaweb2/roles.ini') - .with_settings({'users'=>'bob, pete', 'permissions' => '*'}) } + let(:params) { { users: 'bob, pete', permissions: '*' } } + it { + is_expected.to contain_icingaweb2__inisection('role-myrole') + .with_target('/etc/icingaweb2/roles.ini') + .with_settings('users' => 'bob, pete', 'permissions' => '*') + } end context "#{os} with users => 'bob, pete', permissions => 'module/monitoring', filters => {'monitoring/filter/objects' => 'host_name=linux-*'}" do - let(:params) { { :users => 'bob, pete', :permissions => 'module/monitoring', :filters => {'monitoring/filter/objects' => 'host_name=linux-*'} } } - - it { is_expected.to contain_icingaweb2__inisection('role-myrole') - .with_target('/etc/icingaweb2/roles.ini') - .with_settings({'users'=>'bob, pete', 'permissions'=>'module/monitoring', 'monitoring/filter/objects'=>'host_name=linux-*'}) } + let(:params) { { users: 'bob, pete', permissions: 'module/monitoring', filters: { 'monitoring/filter/objects' => 'host_name=linux-*' } } } + it { + is_expected.to contain_icingaweb2__inisection('role-myrole') + .with_target('/etc/icingaweb2/roles.ini') + .with_settings('users' => 'bob, pete', 'permissions' => 'module/monitoring', 'monitoring/filter/objects' => 'host_name=linux-*') + } end end end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index a957ce6..48e63b9 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,51 +1,50 @@ require 'beaker-rspec' require 'beaker/puppet_install_helper' # Install Puppet on all hosts -install_puppet_agent_on(hosts, :puppet_collection => 'puppet5') +install_puppet_agent_on(hosts, puppet_collection: 'puppet5') RSpec.configure do |c| module_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) c.formatter = :documentation c.before :suite do # Install module to all hosts hosts.each do |host| - install_dev_puppet_module_on(host, :source => module_root, :module_name => 'icingaweb2', - :target_module_path => '/etc/puppetlabs/code/modules') + install_dev_puppet_module_on(host, source: module_root, module_name: 'icingaweb2', + target_module_path: '/etc/puppetlabs/code/modules') # Install dependencies on(host, puppet('module', 'install', 'puppetlabs-stdlib')) on(host, puppet('module', 'install', 'puppetlabs-concat')) on(host, puppet('module', 'install', 'puppetlabs-vcsrepo')) # Install additional modules on(host, puppet('module', 'install', 'puppetlabs-mysql')) on(host, puppet('module', 'install', 'puppetlabs-postgresql')) on(host, puppet('module', 'install', 'puppetlabs-apache')) on(host, puppet('module', 'install', 'puppet-php')) if fact('osfamily') == 'Debian' on(host, puppet('module', 'install', 'puppetlabs-apt')) end if fact('osfamily') == 'Suse' on(host, puppet('module', 'install', 'puppet-zypprepo')) end # Add more setup code as needed end end end shared_examples 'a idempotent resource' do it 'applies with no errors' do apply_manifest(pp, catch_failures: true) end it 'applies a second time without changes', :skip_pup_5016 do apply_manifest(pp, catch_changes: true) end end -