Added test-kitchen and chefspec

This commit is contained in:
Eric Renfro 2016-12-08 17:36:10 -05:00
parent f8de3964d2
commit 611e54f835
8 changed files with 122 additions and 0 deletions

25
.kitchen.yml Normal file
View File

@ -0,0 +1,25 @@
---
driver:
name: docker
provisioner:
name: chef_zero
environments_path: test/environments
client_rb:
environment: integration_test_env
platforms:
- name: centos-7.2-chef-12
driver_config:
image: centos:7.2.1511
platform: rhel
require_chef_omnibus: 12.16.42
use_sudo: false
hostname: integration.test.test
suites:
- name: default
data_bags_path: "test/integration/data_bags"
run_list:
- recipe[yum-rsyslog]

7
Gemfile Normal file
View File

@ -0,0 +1,7 @@
source 'https://rubygems.org'
gem 'berkshelf'
gem 'test-kitchen'
gem 'chefspec'
gem 'foodcritic'
gem 'kitchen-docker'

1
chefignore Normal file
View File

@ -0,0 +1 @@
.kitchen

10
spec/spec_helper.rb Normal file
View File

@ -0,0 +1,10 @@
require 'chefspec'
require 'chefspec/berkshelf'
RSpec.configure do |config|
config.platform = 'centos'
config.version = '7.2.1511'
end
ChefSpec::Coverage.start!

View File

@ -0,0 +1,44 @@
require 'spec_helper'
describe 'yum-rsyslog::default' do
context 'Creates rsyslog YUM repository and enables it.' do
let(:chef_run) do
ChefSpec::SoloRunner.new do |node|
# Create a new environment (you could also use a different :let block or :before block)
env = Chef::Environment.new
env.name 'unit_test'
# Stub the node to return this environment
allow(node).to receive(:chef_environment).and_return(env.name)
# Stub any calls to Environment.load to return this environment
allow(Chef::Environment).to receive(:load).and_return(env)
# Stubbing out fqdn node attribute
node.automatic['fqdn'] = 'unit.testing.stub'
end.converge(described_recipe)
end
#before(:each) do
#stub_command("rpm -qa zabbix-release-2.4-1.el6.noarch ").and_return(false)
#allow(Chef::EncryptedDataBagItem).to receive(:load).with('odhp_credentials', 'credentials').and_return(
#{
# 'zabbix' => {
# 'users' => {
# 'unit_test_env' => {
# 'postgres' => {
# 'username' => 'postgres_username',
# 'password' => 'postgres_password'
# }
# }
# }
# }
#})
#end
it 'installs the rsyslog repository' do
expect(chef_run).to create_yum_repository('rsyslog')
end
end
end

View File

@ -0,0 +1,16 @@
{
"name": "integration_test_env",
"description": "placeholder for integration testing",
"cookbook_versions": {
},
"json_class": "Chef::Environment",
"chef_type": "environment",
"default_attributes": {
},
"override_attributes": {
}
}

View File

@ -0,0 +1,15 @@
require 'spec_helper'
describe 'yum-rsyslog::default' do
describe yumrepo('rsyslog') do
it { should be_enabled }
end
describe file('/etc/yum.repos.d/rsyslog.repo') do
it { should be_file }
it { should be_mode 644 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
end

View File

@ -0,0 +1,4 @@
require 'serverspec'
set :backend, :exec