Skip to content

Commit

Permalink
Tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Yudin committed Dec 25, 2014
1 parent 3727089 commit b09eb86
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .kitchen.yml
Expand Up @@ -16,6 +16,9 @@ platforms:
attributes:
td_agent:
version: 2
- name: centos-6.6
driver_config:
image: centos:centos6

suites:
- name: default
Expand All @@ -26,3 +29,7 @@ suites:
includes: true
plugins:
- forest

- name: lwrp
run_list:
- recipe[smoke::default]
4 changes: 4 additions & 0 deletions Berksfile
@@ -1,3 +1,7 @@
source "https://api.berkshelf.com"

metadata

group :integration do
cookbook 'smoke', :path => './test/fixtures/smoke'
end
6 changes: 6 additions & 0 deletions test/fixtures/smoke/metadata.rb
@@ -0,0 +1,6 @@
name "smoke"
license "Apache 2.0"
description "This cookbook is used with test-kitchen to test the parent, td-agent cookbok"
version "1.0.0"

depends 'td-agent'
55 changes: 55 additions & 0 deletions test/fixtures/smoke/recipes/default.rb
@@ -0,0 +1,55 @@
#
# Cookbok Name:: smoke
# Recipe:: default
#
# Author:: Pavel Yudin <pyudin@parallels.com>
#
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

node.set['td_agent']['includes'] = true
include_recipe 'td-agent::default'

td_agent_source 'test_in_tail' do
type 'tail'
tag 'syslog'
params(format: 'syslog',
path: '/var/log/messages')
end

td_agent_source 'test_in_tail_nginx' do
type 'tail'
tag 'webserver.nginx'
params(format: '/^(?<remote>[^ ]*) - (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*) "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" "(?<forwarded_for>[^\"]*)"$/',
time_format: '%d/%b/%Y:%H:%M:%S',
types: { code: 'integer', size: 'integer' },
path: '/var/log/nginx/access.log')
end

td_agent_match 'test_gelf_match' do
type 'copy'
tag 'webserver.*'
params( store: [{ type: 'gelf',
host: '127.0.0.1',
port: 12201,
flush_interval: '5s'},
{ type: 'stdout' }])
end

td_agent_plugin 'gelf' do
url 'https://raw.githubusercontent.com/emsearcy/fluent-plugin-gelf/master/lib/fluent/plugin/out_gelf.rb'
end

td_agent_gem 'gelf'
3 changes: 3 additions & 0 deletions test/integration/lwrp/serverspec/Gemfile
@@ -0,0 +1,3 @@
source "https://rubygems.org/"

gem "serverspec", "~> 1.16.0"
58 changes: 58 additions & 0 deletions test/integration/lwrp/serverspec/lwrp_spec.rb
@@ -0,0 +1,58 @@
require 'serverspec'

include Serverspec::Helper::Exec
include Serverspec::Helper::DetectOS

RSpec.configure do |c|
c.before :all do
c.path = '/usr/lib/fluent/ruby/bin:/sbin:/usr/sbin'
end
end

describe package('td-agent') do
it { should be_installed }
end

describe service('td-agent') do
it { should be_running }
end

describe file('/etc/td-agent') do
it { should be_a_directory }
end

describe file('/etc/td-agent/td-agent.conf') do
it { should be_a_file }
it { should be_mode 644 }
end

describe file('/etc/td-agent/conf.d') do
it { should be_a_directory }
it { should be_mode 755 }
end

describe file('/etc/td-agent/conf.d/test_in_tail.conf') do
it { should be_a_file }
it { should be_mode 644 }
it { should contain "<source>\n type tail\n tag syslog\n format syslog\n path /var/log/messages\n</source>"}
end

describe file('/etc/td-agent/conf.d/test_in_tail_nginx.conf') do
it { should be_a_file }
it { should be_mode 644 }
end

describe file('/etc/td-agent/conf.d/test_gelf_match.conf') do
it { should be_a_file }
it { should be_mode 644 }
it { should contain "<match webserver.*>\n type copy\n <store>\ntype gelf\nhost 127.0.0.1\nport 12201\nflush_interval 5s\n</store>\n<store>\ntype stdout\n</store>\n\n</match>" }
end

describe file('/etc/td-agent/plugin/gelf.rb') do
it { should be_a_file }
it { should be_mode 644 }
end

describe command('td-agent --dry-run') do
its(:exit_status) { should eq 0 }
end

0 comments on commit b09eb86

Please sign in to comment.