1
0
mirror of https://github.com/krislamo/puppet-fluentd synced 2024-09-19 20:20:35 +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 'beaker-puppet_install_helper'
gem 'metadata-json-lint'
gem 'rspec-puppet-facts', '~> 1.7'
beakerrspec = '> 0'
platforms [:ruby_19, :ruby_21] do

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,27 +1,32 @@
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]')
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'
})
}
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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
end

View File

@ -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

View File

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