1
0
mirror of https://github.com/krislamo/puppet-fluentd synced 2024-12-16 05:10:36 +00:00

Merge pull request #19 from wywy/use_rspec_puppet_facts

Use rspec puppet facts
This commit is contained in:
Max Wilhelm 2017-08-17 14:08:11 +02:00 committed by GitHub
commit d6231c3b13
14 changed files with 350 additions and 389 deletions

View File

@ -7,6 +7,7 @@ gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0' gem 'facter', '>= 1.7.0'
gem 'beaker-puppet_install_helper' gem 'beaker-puppet_install_helper'
gem 'metadata-json-lint' gem 'metadata-json-lint'
gem 'rspec-puppet-facts', '~> 1.7'
beakerrspec = '> 0' beakerrspec = '> 0'
platforms [:ruby_19, :ruby_21] do platforms [:ruby_19, :ruby_21] do

View File

@ -1,46 +1,31 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::config', :type => :class do describe 'fluentd::config', :type => :class do
shared_examples 'when called with no parameters' do on_supported_os.each do |os, facts|
it { context "on #{os}" do
should contain_file('/etc/td-agent/td-agent.conf').with({ let :facts do
'ensure' => 'file', facts
'owner' => 'root', end
'group' => 'root',
'source' => 'puppet:///modules/fluentd/td-agent.conf',
'notify' => 'Class[Fluentd::Service]'
})
should contain_file('/etc/td-agent/conf.d').with({ describe 'when called with no parameters' do
'ensure' => 'directory',
'owner' => 'td-agent',
'group' => 'td-agent',
'mode' => '0750'
})
}
end
context 'when osfamily is Debian' do it {
let(:facts) { should contain_file('/etc/td-agent/td-agent.conf').with({
{ 'ensure' => 'file',
:osfamily => 'Debian', 'owner' => 'root',
:lsbdistid => 'Ubuntu', 'group' => 'root',
:operatingsystem => 'Ubuntu', 'source' => 'puppet:///modules/fluentd/td-agent.conf',
:lsbdistcodename => 'precise', 'notify' => 'Class[Fluentd::Service]'
:architecture => 'amd64', })
}
}
include_examples 'when called with no parameters' should contain_file('/etc/td-agent/conf.d').with({
end 'ensure' => 'directory',
'owner' => 'td-agent',
context 'when osfamily is RedHat' do 'group' => 'td-agent',
let(:facts) { 'mode' => '0750'
{ })
:osfamily => 'RedHat', }
} end
} end
include_examples 'when called with no parameters'
end end
end end

View File

@ -1,38 +1,21 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::install', :type => :class do 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 describe 'when called with no parameters' do
it { it {
should contain_package('fluentd').with({ should contain_package('fluentd').with({
'ensure' => 'installed', 'ensure' => 'installed',
'name' => 'td-agent', 'name' => 'td-agent',
'install_options' => [] 'install_options' => []
}) })
} }
end
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 end

View File

@ -1,34 +1,81 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::repo::apt', :type => :class do describe 'fluentd::repo::apt', :type => :class do
let(:facts) { on_supported_os.each do |os, facts|
{ context "on #{os}" do
:osfamily => 'Debian', let :facts do
:lsbdistid => 'Ubuntu', facts
:operatingsystem => 'Ubuntu', end
:lsbdistcodename => 'precise',
:architecture => 'amd64',
}
}
describe 'when called with no parameters on Ubuntu' do case facts[:osfamily]
it { when 'Debian'
should contain_class('apt') it {
should contain_apt__source('treasure-data').with({ should contain_class('apt')
'ensure' => 'present', should contain_apt__source('treasure-data').with({
'location' => 'http://packages.treasuredata.com/2/ubuntu/precise', 'ensure' => 'present',
'release' => 'precise', 'repos' => 'contrib',
'repos' => 'contrib', 'architecture' => 'amd64',
'architecture' => 'amd64', 'key' => {
'key' => { 'id' => 'BEE682289B2217F45AF4CC3F901F9177AB97ACBE',
'id' => 'BEE682289B2217F45AF4CC3F901F9177AB97ACBE', 'source' => 'http://packages.treasuredata.com/GPG-KEY-td-agent'
'source' => 'http://packages.treasuredata.com/GPG-KEY-td-agent' },
}, 'include' => {
'include' => { 'src' => false,
'src' => false, 'deb' => true
'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
end end

View File

@ -1,30 +1,21 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::repo', :type => :class do 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 describe 'when called with no parameters' do
let(:facts) { case facts[:osfamily]
{ when 'Debian'
:osfamily => 'Debian', it { is_expected.to contain_class('fluentd::repo::apt') }
:lsbdistid => 'Ubuntu', when 'RedHat'
:operatingsystem => 'Ubuntu', it { is_expected.to contain_class('fluentd::repo::yum') }
:lsbdistcodename => 'precise', end
:architecture => 'amd64', end
} end
}
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')
}
end end
end end

View File

@ -1,27 +1,32 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::repo::yum', :type => :class do describe 'fluentd::repo::yum', :type => :class do
let(:facts) { on_supported_os.each do |os, facts|
{ context "on #{os}" do
:osfamily => 'RedHat', let :facts do
} facts
} end
describe 'when called with no parameters on RedHat' do describe 'when called with no parameters' do
it { case facts[:osfamily]
should contain_yumrepo('treasure-data').with({ when 'RedHat'
'ensure' => 'present', it {
'baseurl' => 'https://packages.treasuredata.com/2/redhat/$releasever/$basearch', should contain_yumrepo('treasure-data').with({
'descr' => 'TreasureData', 'ensure' => 'present',
'enabled' => '1', 'baseurl' => 'https://packages.treasuredata.com/2/redhat/$releasever/$basearch',
'gpgcheck' => '1' 'descr' => 'TreasureData',
}).that_notifies('Exec[add GPG key]') 'enabled' => '1',
'gpgcheck' => '1'
}).that_notifies('Exec[add GPG key]')
should contain_exec('add GPG key').with({ should contain_exec('add GPG key').with({
'command' => 'rpm --import https://packages.treasuredata.com/GPG-KEY-td-agent', 'command' => 'rpm --import https://packages.treasuredata.com/GPG-KEY-td-agent',
'path' => '/bin:/usr/bin/', 'path' => '/bin:/usr/bin/',
'refreshonly' => 'true' 'refreshonly' => 'true'
}) })
} }
end
end
end
end end
end end

View File

@ -1,39 +1,23 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::config', :type => :class do describe 'fluentd::config', :type => :class do
shared_examples 'when called with no parameters' do on_supported_os.each do |os, facts|
it { context "on #{os}" do
should contain_service('fluentd').with({ let :facts do
'name' => 'td-agent', facts
'ensure' => 'running', end
'enable' => 'true',
'hasstatus' => 'true',
'hasrestart' => 'true'
})
}
end
context 'when osfamily is Debian' do describe 'when called with no parameters' do
let(:facts) { it {
{ should contain_service('fluentd').with({
:osfamily => 'Debian', 'name' => 'td-agent',
:lsbdistid => 'Ubuntu', 'ensure' => 'running',
:operatingsystem => 'Ubuntu', 'enable' => 'true',
:lsbdistcodename => 'precise', 'hasstatus' => 'true',
:architecture => 'amd64', 'hasrestart' => 'true'
} })
} }
end
include_examples 'when called with no parameters' end
end
context 'when osfamily is RedHat' do
let(:facts) {
{
:osfamily => 'RedHat',
}
}
include_examples 'when called with no parameters'
end end
end end

View File

@ -1,37 +1,20 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd', :type => :class do describe 'fluentd', :type => :class do
shared_examples 'when called with no parameters' do on_supported_os.each do |os, facts|
it { context "on #{os}" do
should contain_class('fluentd::repo') let :facts do
should contain_class('fluentd::install') facts
should contain_class('fluentd::config') end
should contain_class('fluentd::service')
} 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 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 end

View File

@ -1,37 +1,21 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::user', :type => :class do describe 'fluentd::user', :type => :class do
shared_examples 'when called with no parameters' do on_supported_os.each do |os, facts|
it { context "on #{os}" do
should contain_user('fluentd').with({ let :facts do
'name' => 'td-agent', facts
'gid' => 'td-agent', end
'groups' => ['adm']
})
}
end
context 'when osfamily is Debian' do describe 'when called with no parameters' do
let(:facts) { it {
{ should contain_user('fluentd').with({
:osfamily => 'Debian', 'name' => 'td-agent',
:lsbdistid => 'Ubuntu', 'gid' => 'td-agent',
:operatingsystem => 'Ubuntu', 'groups' => ['adm']
:lsbdistcodename => 'precise', })
:architecture => 'amd64', }
} end
} end
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
end end

View File

@ -1,35 +1,34 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::filter' do describe 'fluentd::filter' do
let(:facts) { on_supported_os.each do |os, facts|
{ context "on #{os}" do
:osfamily => 'Debian', let :facts do
:lsbdistid => 'Ubuntu', facts
:operatingsystem => 'Ubuntu', end
:lsbdistcodename => 'precise',
:architecture => 'amd64',
}
}
let(:pre_condition) { 'include fluentd' }
context 'basic filter' do let(:pre_condition) { 'include fluentd' }
let(:title) { 'test' }
let(:params) do describe 'basic filter' do
{ let(:title) { 'test' }
priority: '20', let(:params) do
pattern: '*.test', {
config: { priority: '20',
pattern: '*.test',
config: {
'type' => 'record_transformer', 'type' => 'record_transformer',
'record' => { 'record' => {
'hostname' => '${hostname}' 'hostname' => '${hostname}'
} }
}
} }
} end
end
it do it do
is_expected.to contain_file('/etc/td-agent/conf.d/20-filter-test.conf'). 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'))) with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/filter_record_transformer.conf')))
end
end
end end
end end
end end

View File

@ -1,72 +1,71 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::match' do describe 'fluentd::match' do
let(:facts) { on_supported_os.each do |os, facts|
{ context "on #{os}" do
:osfamily => 'Debian', let :facts do
:lsbdistid => 'Ubuntu', facts
:operatingsystem => 'Ubuntu', end
:lsbdistcodename => 'precise',
:architecture => 'amd64',
}
}
let(:pre_condition) { 'include fluentd' }
context 'basic match' do let(:pre_condition) { 'include fluentd' }
let(:title) { 'test' }
let(:params) do describe 'basic match' do
{ let(:title) { 'test' }
priority: '30', let(:params) do
pattern: '*.test', {
config: { priority: '30',
'flush_interval' => '30s', pattern: '*.test',
'type' => 'secure_forward', config: {
'secure' => 'yes', 'flush_interval' => '30s',
'shared_key' => 'my_shared_key', 'type' => 'secure_forward',
'self_hostname' => 'instance.test.com', 'secure' => 'yes',
'ca_cert_path' => '/path/to/ca.cert', 'shared_key' => 'my_shared_key',
'server' => [ 'self_hostname' => 'instance.test.com',
{ 'ca_cert_path' => '/path/to/ca.cert',
'host' => 'test.server.com', 'server' => [
} {
] 'host' => 'test.server.com',
}
]
}
} }
} end
end
it do it do
is_expected.to contain_file('/etc/td-agent/conf.d/30-match-test.conf'). 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'))) with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/match_secure_forward.conf')))
end end
end end
context 'multiple store' do describe 'multiple store' do
let(:title) { 'test' } let(:title) { 'test' }
let(:params) do let(:params) do
{ {
priority: '30', priority: '30',
pattern: '*.test', pattern: '*.test',
config: { config: {
'type' => 'copy', 'type' => 'copy',
'store' => [ 'store' => [
{ {
'type' => 'elasticsearch', 'type' => 'elasticsearch',
'logstashformat' => true, 'logstashformat' => true,
'hosts' => '172.20.10.17:9200', 'hosts' => '172.20.10.17:9200',
'flush_interval' => '30s', 'flush_interval' => '30s',
}, },
{ {
'type' => 'file', 'type' => 'file',
'path' => '/tmp/td-agent-debug.log', 'path' => '/tmp/td-agent-debug.log',
} }
] ]
}
} }
} end
end
it do it do
is_expected.to contain_file('/etc/td-agent/conf.d/30-match-test.conf'). 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'))) with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/match_copy.conf')))
end
end
end end
end end
end end

View File

@ -1,52 +1,51 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::plugin' do describe 'fluentd::plugin' do
let(:facts) { on_supported_os.each do |os, facts|
{ context "on #{os}" do
:osfamily => 'Debian', let :facts do
:lsbdistid => 'Ubuntu', facts
:operatingsystem => 'Ubuntu', end
:lsbdistcodename => 'precise',
:architecture => 'amd64',
}
}
let(:pre_condition) { 'include fluentd' }
context 'gem plugin' do let(:pre_condition) { 'include fluentd' }
let(:title) { 'fluent-plugin-elasticsearch' }
let(:params) do
{
type: 'gem'
}
end
it do describe 'gem plugin' do
should contain_package('fluent-plugin-elasticsearch').with({ let(:title) { 'fluent-plugin-elasticsearch' }
'ensure' => 'present', let(:params) do
'provider' => 'fluentd_gem', {
'notify' => 'Class[Fluentd::Service]' 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
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

View File

@ -1,34 +1,33 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::source' do describe 'fluentd::source' do
let(:facts) { on_supported_os.each do |os, facts|
{ context "on #{os}" do
:osfamily => 'Debian', let :facts do
:lsbdistid => 'Ubuntu', facts
:operatingsystem => 'Ubuntu', end
:lsbdistcodename => 'precise',
:architecture => 'amd64',
}
}
let(:pre_condition) { 'include fluentd' }
context 'basic source' do let(:pre_condition) { 'include fluentd' }
let(:title) { 'test' }
let(:params) do describe 'basic source' do
{ let(:title) { 'test' }
priority: '10', let(:params) do
config: { {
'type' => 'tail', priority: '10',
'format' => 'json', config: {
'path' => '/var/log/test-application/*.json', 'type' => 'tail',
'tag' => 'application.test' 'format' => 'json',
'path' => '/var/log/test-application/*.json',
'tag' => 'application.test'
}
} }
} end
end
it do it do
is_expected.to contain_file('/etc/td-agent/conf.d/10-source-test.conf'). 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'))) with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/source_tail.conf')))
end
end
end end
end end
end end

View File

@ -1 +1,3 @@
require 'puppetlabs_spec_helper/module_spec_helper' require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts