From 41a617c15607d91cd4d6374afb26b541377c1525 Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Mon, 14 Aug 2017 17:54:56 +0200 Subject: [PATCH 01/13] add and init rspec-puppet-facts --- Gemfile | 1 + spec/spec_helper.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 01122cb..3da20ad 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ gem 'puppet-lint', '>= 1.0.0' gem 'facter', '>= 1.7.0' gem 'beaker-puppet_install_helper' gem 'metadata-json-lint' +gem 'rspec-puppet-facts', '~> 1.7' beakerrspec = '> 0' platforms [:ruby_19, :ruby_21] do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f566..1ffdf17 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,3 @@ require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' +include RspecPuppetFacts From 754cd4a696c4c79ce5146c4ce9c43bb42819c965 Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Mon, 14 Aug 2017 17:55:27 +0200 Subject: [PATCH 02/13] use rspec-puppet-facts for fluentd_repo_spec --- spec/classes/fluentd_repo_spec.rb | 39 ++++++++++++------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/spec/classes/fluentd_repo_spec.rb b/spec/classes/fluentd_repo_spec.rb index e7b92c2..ae1e142 100644 --- a/spec/classes/fluentd_repo_spec.rb +++ b/spec/classes/fluentd_repo_spec.rb @@ -1,30 +1,21 @@ require 'spec_helper' describe 'fluentd::repo', :type => :class do + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end - context 'when called with no parameters on osfamily Debian' do - let(:facts) { - { - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :lsbdistcodename => 'precise', - :architecture => 'amd64', - } - } - it { - should contain_class('fluentd::repo::apt') - } - end - - context 'when called with no parameters on osfamily RedHat' do - let(:facts) { - { - :osfamily => 'RedHat', - } - } - it { - should contain_class('fluentd::repo::yum') - } + describe 'when called with no parameters' do + case facts[:osfamily] + when 'Debian' + it { is_expected.to contain_class('fluentd::repo::apt') } + when 'RedHat' + it { is_expected.to contain_class('fluentd::repo::yum') } + end + end + end end end + From b51a559684d895a4a87dd405bb8fea8fa32ed26e Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Mon, 14 Aug 2017 17:55:39 +0200 Subject: [PATCH 03/13] use rspec-puppet-facts for fluentd_config_spec --- spec/classes/fluentd_config_spec.rb | 61 +++++++++++------------------ 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/spec/classes/fluentd_config_spec.rb b/spec/classes/fluentd_config_spec.rb index aa4e1e3..cdbb578 100644 --- a/spec/classes/fluentd_config_spec.rb +++ b/spec/classes/fluentd_config_spec.rb @@ -1,46 +1,31 @@ require 'spec_helper' describe 'fluentd::config', :type => :class do - shared_examples 'when called with no parameters' do - it { - should contain_file('/etc/td-agent/td-agent.conf').with({ - 'ensure' => 'file', - 'owner' => 'root', - 'group' => 'root', - 'source' => 'puppet:///modules/fluentd/td-agent.conf', - 'notify' => 'Class[Fluentd::Service]' - }) + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end - should contain_file('/etc/td-agent/conf.d').with({ - 'ensure' => 'directory', - 'owner' => 'td-agent', - 'group' => 'td-agent', - 'mode' => '0750' - }) - } - end + describe 'when called with no parameters' do - context 'when osfamily is Debian' do - let(:facts) { - { - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :lsbdistcodename => 'precise', - :architecture => 'amd64', - } - } + it { + should contain_file('/etc/td-agent/td-agent.conf').with({ + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + 'source' => 'puppet:///modules/fluentd/td-agent.conf', + 'notify' => 'Class[Fluentd::Service]' + }) - include_examples 'when called with no parameters' - end - - context 'when osfamily is RedHat' do - let(:facts) { - { - :osfamily => 'RedHat', - } - } - - include_examples 'when called with no parameters' + should contain_file('/etc/td-agent/conf.d').with({ + 'ensure' => 'directory', + 'owner' => 'td-agent', + 'group' => 'td-agent', + 'mode' => '0750' + }) + } + end + end end end From e8cdc9a9e0610c60d7f458792e5dad41030c3eac Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Mon, 14 Aug 2017 17:56:06 +0200 Subject: [PATCH 04/13] use rspec-puppet-facts for fluentd_install_spec --- spec/classes/fluentd_install_spec.rb | 47 +++++++++------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/spec/classes/fluentd_install_spec.rb b/spec/classes/fluentd_install_spec.rb index da08766..33ba699 100644 --- a/spec/classes/fluentd_install_spec.rb +++ b/spec/classes/fluentd_install_spec.rb @@ -1,38 +1,21 @@ require 'spec_helper' describe 'fluentd::install', :type => :class do + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end - shared_examples 'when called with no parameters' do - it { - should contain_package('fluentd').with({ - 'ensure' => 'installed', - 'name' => 'td-agent', - 'install_options' => [] - }) - } + describe 'when called with no parameters' do + it { + should contain_package('fluentd').with({ + 'ensure' => 'installed', + 'name' => 'td-agent', + 'install_options' => [] + }) + } + end + end end - - context 'when osfamily is Debian' do - let(:facts) { - { - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :lsbdistcodename => 'precise', - :architecture => 'amd64', - } - } - include_examples 'when called with no parameters' - end - - context 'when osfamily is RedHat' do - let(:facts) { - { - :osfamily => 'RedHat', - } - } - - include_examples 'when called with no parameters' - end - end From d7f6d91a11d73d2200df38f5be59782f8dff5988 Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Mon, 14 Aug 2017 17:56:20 +0200 Subject: [PATCH 05/13] use rspec-puppet-facts for fluentd_repo_apt_spec --- spec/classes/fluentd_repo_apt_spec.rb | 101 +++++++++++++++++++------- 1 file changed, 74 insertions(+), 27 deletions(-) diff --git a/spec/classes/fluentd_repo_apt_spec.rb b/spec/classes/fluentd_repo_apt_spec.rb index ce6bc15..94224c4 100644 --- a/spec/classes/fluentd_repo_apt_spec.rb +++ b/spec/classes/fluentd_repo_apt_spec.rb @@ -1,34 +1,81 @@ require 'spec_helper' describe 'fluentd::repo::apt', :type => :class do - let(:facts) { - { - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :lsbdistcodename => 'precise', - :architecture => 'amd64', - } - } + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end - describe 'when called with no parameters on Ubuntu' do - it { - should contain_class('apt') - should contain_apt__source('treasure-data').with({ - 'ensure' => 'present', - 'location' => 'http://packages.treasuredata.com/2/ubuntu/precise', - 'release' => 'precise', - 'repos' => 'contrib', - 'architecture' => 'amd64', - 'key' => { - 'id' => 'BEE682289B2217F45AF4CC3F901F9177AB97ACBE', - 'source' => 'http://packages.treasuredata.com/GPG-KEY-td-agent' - }, - 'include' => { - 'src' => false, - 'deb' => true + case facts[:osfamily] + when 'Debian' + it { + should contain_class('apt') + should contain_apt__source('treasure-data').with({ + 'ensure' => 'present', + 'repos' => 'contrib', + 'architecture' => 'amd64', + 'key' => { + 'id' => 'BEE682289B2217F45AF4CC3F901F9177AB97ACBE', + 'source' => 'http://packages.treasuredata.com/GPG-KEY-td-agent' + }, + 'include' => { + 'src' => false, + 'deb' => true + } + }) } - }) - } + case facts[:operatingsystem] + when 'Ubuntu' + case facts[:lsbdistcodename] + when 'precise' + it { + should contain_apt__source('treasure-data').with({ + 'location' => 'http://packages.treasuredata.com/2/ubuntu/precise', + 'release' => 'precise' + }) + } + when 'trusty' + it { + should contain_apt__source('treasure-data').with({ + 'location' => 'http://packages.treasuredata.com/2/ubuntu/trusty', + 'release' => 'trusty' + }) + } + when 'xenial' + it { + should contain_apt__source('treasure-data').with({ + 'location' => 'http://packages.treasuredata.com/2/ubuntu/xenial', + 'release' => 'xenial' + }) + } + end + when 'Debian' + case facts[:lsbdistcodename] + when 'jessie' + it { + should contain_apt__source('treasure-data').with({ + 'location' => 'http://packages.treasuredata.com/2/debian/jessie', + 'release' => 'jessie' + }) + } + when 'squeeze' + it { + should contain_apt__source('treasure-data').with({ + 'location' => 'http://packages.treasuredata.com/2/debian/squeeze', + 'release' => 'squeeze' + }) + } + when 'wheezy' + it { + should contain_apt__source('treasure-data').with({ + 'location' => 'http://packages.treasuredata.com/2/debian/wheezy', + 'release' => 'wheezy' + }) + } + end + end + end + end end end From b34c7dc4e4f99d37b7f07f4776d69d8fcd8efabc Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Mon, 14 Aug 2017 17:56:33 +0200 Subject: [PATCH 06/13] use rspec-puppet-facts for fluentd_repo_yum_spec --- spec/classes/fluentd_repo_yum_spec.rb | 46 +++++++++++++++------------ 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/spec/classes/fluentd_repo_yum_spec.rb b/spec/classes/fluentd_repo_yum_spec.rb index ede083d..7bcd865 100644 --- a/spec/classes/fluentd_repo_yum_spec.rb +++ b/spec/classes/fluentd_repo_yum_spec.rb @@ -1,27 +1,33 @@ require 'spec_helper' describe 'fluentd::repo::yum', :type => :class do - let(:facts) { - { - :osfamily => 'RedHat', - } - } + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end - describe 'when called with no parameters on RedHat' do - it { - should contain_yumrepo('treasure-data').with({ - 'ensure' => 'present', - 'baseurl' => 'https://packages.treasuredata.com/2/redhat/$releasever/$basearch', - 'descr' => 'TreasureData', - 'enabled' => '1', - 'gpgcheck' => '1' - }).that_notifies('Exec[add GPG key]') - should contain_exec('add GPG key').with({ - 'command' => 'rpm --import https://packages.treasuredata.com/GPG-KEY-td-agent', - 'path' => '/bin:/usr/bin/', - 'refreshonly' => 'true' - }) - } + describe 'when called with no parameters' do + case facts[:osfamily] + when 'RedHat' + it { + should contain_yumrepo('treasure-data').with({ + 'ensure' => 'present', + 'baseurl' => 'https://packages.treasuredata.com/2/redhat/$releasever/$basearch', + 'descr' => 'TreasureData', + 'enabled' => '1', + 'gpgcheck' => '1' + }).that_notifies('Exec[add GPG key]') + + should contain_exec('add GPG key').with({ + 'command' => 'rpm --import https://packages.treasuredata.com/GPG-KEY-td-agent', + 'path' => '/bin:/usr/bin/', + 'refreshonly' => 'true' + }) + } + end + end + end end end From 6e97016aace7838180ac3c4b51ef04e5951d4681 Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Thu, 17 Aug 2017 13:26:03 +0200 Subject: [PATCH 07/13] use rspec-puppet-facts for fluentd_service_spec --- spec/classes/fluentd_repo_yum_spec.rb | 1 - spec/classes/fluentd_service_spec.rb | 50 +++++++++------------------ 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/spec/classes/fluentd_repo_yum_spec.rb b/spec/classes/fluentd_repo_yum_spec.rb index 7bcd865..6c854c7 100644 --- a/spec/classes/fluentd_repo_yum_spec.rb +++ b/spec/classes/fluentd_repo_yum_spec.rb @@ -7,7 +7,6 @@ describe 'fluentd::repo::yum', :type => :class do facts end - describe 'when called with no parameters' do case facts[:osfamily] when 'RedHat' diff --git a/spec/classes/fluentd_service_spec.rb b/spec/classes/fluentd_service_spec.rb index 16c00a3..c0da9fd 100644 --- a/spec/classes/fluentd_service_spec.rb +++ b/spec/classes/fluentd_service_spec.rb @@ -1,39 +1,23 @@ require 'spec_helper' describe 'fluentd::config', :type => :class do - shared_examples 'when called with no parameters' do - it { - should contain_service('fluentd').with({ - 'name' => 'td-agent', - 'ensure' => 'running', - 'enable' => 'true', - 'hasstatus' => 'true', - 'hasrestart' => 'true' - }) - } - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end - context 'when osfamily is Debian' do - let(:facts) { - { - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :lsbdistcodename => 'precise', - :architecture => 'amd64', - } - } - - include_examples 'when called with no parameters' - end - - context 'when osfamily is RedHat' do - let(:facts) { - { - :osfamily => 'RedHat', - } - } - - include_examples 'when called with no parameters' + describe 'when called with no parameters' do + it { + should contain_service('fluentd').with({ + 'name' => 'td-agent', + 'ensure' => 'running', + 'enable' => 'true', + 'hasstatus' => 'true', + 'hasrestart' => 'true' + }) + } + end + end end end From 257880811c115f79b90d1db88a49dc4243a8fe63 Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Thu, 17 Aug 2017 13:26:16 +0200 Subject: [PATCH 08/13] use rspec-puppet-facts for fluentd_spec --- spec/classes/fluentd_spec.rb | 47 ++++++++++++------------------------ 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/spec/classes/fluentd_spec.rb b/spec/classes/fluentd_spec.rb index 989f7f1..bc58226 100644 --- a/spec/classes/fluentd_spec.rb +++ b/spec/classes/fluentd_spec.rb @@ -1,37 +1,20 @@ require 'spec_helper' describe 'fluentd', :type => :class do - shared_examples 'when called with no parameters' do - it { - should contain_class('fluentd::repo') - should contain_class('fluentd::install') - should contain_class('fluentd::config') - should contain_class('fluentd::service') - } + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end + + describe 'when called with no parameters' do + it { + should contain_class('fluentd::repo') + should contain_class('fluentd::install') + should contain_class('fluentd::config') + should contain_class('fluentd::service') + } + end + end end - - context 'when osfamily is Debian' do - let(:facts) { - { - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :lsbdistcodename => 'precise', - :architecture => 'amd64', - } - } - - include_examples 'when called with no parameters' - end - - context 'when osfamily is RedHat' do - let(:facts) { - { - :osfamily => 'RedHat', - } - } - - include_examples 'when called with no parameters' - end - end From c2f95f4bc9338c1964f00036b31a0b62b765be80 Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Thu, 17 Aug 2017 13:26:38 +0200 Subject: [PATCH 09/13] use rspec-puppet-facts for fluentd_user_spec --- spec/classes/fluentd_user_spec.rb | 46 ++++++++++--------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/spec/classes/fluentd_user_spec.rb b/spec/classes/fluentd_user_spec.rb index b468640..434f54f 100644 --- a/spec/classes/fluentd_user_spec.rb +++ b/spec/classes/fluentd_user_spec.rb @@ -1,37 +1,21 @@ require 'spec_helper' describe 'fluentd::user', :type => :class do - shared_examples 'when called with no parameters' do - it { - should contain_user('fluentd').with({ - 'name' => 'td-agent', - 'gid' => 'td-agent', - 'groups' => ['adm'] - }) - } - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end - context 'when osfamily is Debian' do - let(:facts) { - { - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :lsbdistcodename => 'precise', - :architecture => 'amd64', - } - } - - include_examples 'when called with no parameters' - end - - context 'when osfamily is RedHat' do - let(:facts) { - { - :osfamily => 'RedHat', - } - } - - include_examples 'when called with no parameters' + describe 'when called with no parameters' do + it { + should contain_user('fluentd').with({ + 'name' => 'td-agent', + 'gid' => 'td-agent', + 'groups' => ['adm'] + }) + } + end + end end end From 258a37ff11593d841d3b048a126f4c9152107650 Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Thu, 17 Aug 2017 13:33:43 +0200 Subject: [PATCH 10/13] use rspec-puppet-facts for filter_spec --- spec/defines/filter_spec.rb | 43 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/spec/defines/filter_spec.rb b/spec/defines/filter_spec.rb index 6365302..c360cff 100644 --- a/spec/defines/filter_spec.rb +++ b/spec/defines/filter_spec.rb @@ -1,35 +1,34 @@ require 'spec_helper' describe 'fluentd::filter' do - let(:facts) { - { - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :lsbdistcodename => 'precise', - :architecture => 'amd64', - } - } - let(:pre_condition) { 'include fluentd' } + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end - context 'basic filter' do - let(:title) { 'test' } - let(:params) do - { - priority: '20', - pattern: '*.test', - config: { + let(:pre_condition) { 'include fluentd' } + + describe 'basic filter' do + let(:title) { 'test' } + let(:params) do + { + priority: '20', + pattern: '*.test', + config: { 'type' => 'record_transformer', 'record' => { 'hostname' => '${hostname}' } + } } - } - end + end - it do - is_expected.to contain_file('/etc/td-agent/conf.d/20-filter-test.conf'). - with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/filter_record_transformer.conf'))) + it do + is_expected.to contain_file('/etc/td-agent/conf.d/20-filter-test.conf'). + with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/filter_record_transformer.conf'))) + end + end end end end From 5f213da8b3d260558c1a0d965ed0417f55a741c7 Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Thu, 17 Aug 2017 13:33:54 +0200 Subject: [PATCH 11/13] use rspec-puppet-facts for match_spec --- spec/defines/match_spec.rb | 119 ++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/spec/defines/match_spec.rb b/spec/defines/match_spec.rb index c2da497..53e1806 100644 --- a/spec/defines/match_spec.rb +++ b/spec/defines/match_spec.rb @@ -1,72 +1,71 @@ require 'spec_helper' describe 'fluentd::match' do - let(:facts) { - { - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :lsbdistcodename => 'precise', - :architecture => 'amd64', - } - } - let(:pre_condition) { 'include fluentd' } + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end - context 'basic match' do - let(:title) { 'test' } - let(:params) do - { - priority: '30', - pattern: '*.test', - config: { - 'flush_interval' => '30s', - 'type' => 'secure_forward', - 'secure' => 'yes', - 'shared_key' => 'my_shared_key', - 'self_hostname' => 'instance.test.com', - 'ca_cert_path' => '/path/to/ca.cert', - 'server' => [ - { - 'host' => 'test.server.com', - } - ] + let(:pre_condition) { 'include fluentd' } + + describe 'basic match' do + let(:title) { 'test' } + let(:params) do + { + priority: '30', + pattern: '*.test', + config: { + 'flush_interval' => '30s', + 'type' => 'secure_forward', + 'secure' => 'yes', + 'shared_key' => 'my_shared_key', + 'self_hostname' => 'instance.test.com', + 'ca_cert_path' => '/path/to/ca.cert', + 'server' => [ + { + 'host' => 'test.server.com', + } + ] + } } - } - end + end - it do - is_expected.to contain_file('/etc/td-agent/conf.d/30-match-test.conf'). - with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/match_secure_forward.conf'))) - end - end + it do + is_expected.to contain_file('/etc/td-agent/conf.d/30-match-test.conf'). + with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/match_secure_forward.conf'))) + end + end - context 'multiple store' do - let(:title) { 'test' } - let(:params) do - { - priority: '30', - pattern: '*.test', - config: { - 'type' => 'copy', - 'store' => [ - { - 'type' => 'elasticsearch', - 'logstashformat' => true, - 'hosts' => '172.20.10.17:9200', - 'flush_interval' => '30s', - }, - { - 'type' => 'file', - 'path' => '/tmp/td-agent-debug.log', - } - ] + describe 'multiple store' do + let(:title) { 'test' } + let(:params) do + { + priority: '30', + pattern: '*.test', + config: { + 'type' => 'copy', + 'store' => [ + { + 'type' => 'elasticsearch', + 'logstashformat' => true, + 'hosts' => '172.20.10.17:9200', + 'flush_interval' => '30s', + }, + { + 'type' => 'file', + 'path' => '/tmp/td-agent-debug.log', + } + ] + } } - } - end + end - it do - is_expected.to contain_file('/etc/td-agent/conf.d/30-match-test.conf'). - with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/match_copy.conf'))) + it do + is_expected.to contain_file('/etc/td-agent/conf.d/30-match-test.conf'). + with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/match_copy.conf'))) + end + end end end end From 613a28ccaf29fa28aa0b5318c4afa15699fbfe15 Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Thu, 17 Aug 2017 13:34:03 +0200 Subject: [PATCH 12/13] use rspec-puppet-facts for plugin_spec --- spec/defines/plugin_spec.rb | 89 ++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/spec/defines/plugin_spec.rb b/spec/defines/plugin_spec.rb index 3ea3878..7eff277 100644 --- a/spec/defines/plugin_spec.rb +++ b/spec/defines/plugin_spec.rb @@ -1,52 +1,51 @@ require 'spec_helper' describe 'fluentd::plugin' do - let(:facts) { - { - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :lsbdistcodename => 'precise', - :architecture => 'amd64', - } - } - let(:pre_condition) { 'include fluentd' } + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end - context 'gem plugin' do - let(:title) { 'fluent-plugin-elasticsearch' } - let(:params) do - { - type: 'gem' - } - end + let(:pre_condition) { 'include fluentd' } - it do - should contain_package('fluent-plugin-elasticsearch').with({ - 'ensure' => 'present', - 'provider' => 'fluentd_gem', - 'notify' => 'Class[Fluentd::Service]' - }) + describe 'gem plugin' do + let(:title) { 'fluent-plugin-elasticsearch' } + let(:params) do + { + type: 'gem' + } + end + + it do + should contain_package('fluent-plugin-elasticsearch').with({ + 'ensure' => 'present', + 'provider' => 'fluentd_gem', + 'notify' => 'Class[Fluentd::Service]' + }) + end + end + + describe 'file plugin' do + let(:title) { 'fluent-plugin-test' } + let(:params) do + { + type: 'file', + source: 'puppet:///path/to/source' + } + end + + it do + should contain_file('/etc/td-agent/plugin/fluent-plugin-test').with({ + 'ensure' => 'present', + 'owner' => 'td-agent', + 'group' => 'td-agent', + 'mode' => '0640', + 'source' => 'puppet:///path/to/source', + 'notify' => 'Class[Fluentd::Service]' + }) + end + end end end - - context 'file plugin' do - let(:title) { 'fluent-plugin-test' } - let(:params) do - { - type: 'file', - source: 'puppet:///path/to/source' - } - end - - it do - should contain_file('/etc/td-agent/plugin/fluent-plugin-test').with({ - 'ensure' => 'present', - 'owner' => 'td-agent', - 'group' => 'td-agent', - 'mode' => '0640', - 'source' => 'puppet:///path/to/source', - 'notify' => 'Class[Fluentd::Service]' - }) - end - end -end \ No newline at end of file +end From fc0f3fdf8863ac0023cd779c5de6249d1fbc4451 Mon Sep 17 00:00:00 2001 From: Max Wilhelm Date: Thu, 17 Aug 2017 13:34:13 +0200 Subject: [PATCH 13/13] use rspec-puppet-facts for source_spec --- spec/defines/source_spec.rb | 49 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index c06feda..47d63e5 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -1,34 +1,33 @@ require 'spec_helper' describe 'fluentd::source' do - let(:facts) { - { - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :lsbdistcodename => 'precise', - :architecture => 'amd64', - } - } - let(:pre_condition) { 'include fluentd' } + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end - context 'basic source' do - let(:title) { 'test' } - let(:params) do - { - priority: '10', - config: { - 'type' => 'tail', - 'format' => 'json', - 'path' => '/var/log/test-application/*.json', - 'tag' => 'application.test' + let(:pre_condition) { 'include fluentd' } + + describe 'basic source' do + let(:title) { 'test' } + let(:params) do + { + priority: '10', + config: { + 'type' => 'tail', + 'format' => 'json', + 'path' => '/var/log/test-application/*.json', + 'tag' => 'application.test' + } } - } - end + end - it do - is_expected.to contain_file('/etc/td-agent/conf.d/10-source-test.conf'). - with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/source_tail.conf'))) + it do + is_expected.to contain_file('/etc/td-agent/conf.d/10-source-test.conf'). + with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/source_tail.conf'))) + end + end end end end