Added test-kitchen and rspec tests

This commit is contained in:
Eric Renfro 2016-12-13 11:01:57 -05:00
parent 79b7ef5294
commit bf36088000
11 changed files with 234 additions and 0 deletions

19
.gitignore vendored Normal file
View file

@ -0,0 +1,19 @@
.DS_Store
.vagrant
Berksfile.lock
Gemfile.lock
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
# Bundler
bin/*
.bundle/*
# Test-Kitchen
.kitchen/
.kitchen.local.yml

28
.kitchen.yml Normal file
View file

@ -0,0 +1,28 @@
---
driver:
name: vagrant
provisioner:
name: chef_zero
environments_path: test/environments
chef_client_path: /usr/bin/chef-client
client_rb:
environment: integration_test_env
platforms:
- name: deb8
driver:
box: lh-debian
box_url: http://repos.home.ld/vagrant/box/lh-debian.json
vm_hostname: integration.deb.test
vagrantfile_erb: test/Vagrantfile.erb
require_chef_omnibus: false
suites:
- name: deb8
run_list:
- recipe[apt-zabbix::default]
attributes:
includes:
- deb8

2
.rspec Normal file
View file

@ -0,0 +1,2 @@
--color
--require spec_helper

20
Gemfile Normal file
View file

@ -0,0 +1,20 @@
source 'https://rubygems.org'
gem 'berkshelf'
# Uncomment these lines if you want to live on the Edge:
#
# group :development do
# gem "berkshelf", github: "berkshelf/berkshelf"
# gem "vagrant", github: "mitchellh/vagrant", tag: "v1.6.3"
# end
#
# group :plugins do
# gem "vagrant-berkshelf", github: "berkshelf/vagrant-berkshelf"
# gem "vagrant-omnibus", github: "schisamo/vagrant-omnibus"
# end
gem "test-kitchen"
gem "kitchen-vagrant"
gem "hitimes"
gem "ffi"

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.color = true
config.log_level = :error
end
ChefSpec::Coverage.start!

View file

@ -0,0 +1,45 @@
require 'spec_helper'
describe 'apt-zabbix::default' do
#context 'Creates Zabbix APT repository' 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
virtual_box_version = '5.0'
let(:runner) { ChefSpec::ServerRunner.new(platform: 'debian', version: '8.6') }
let(:chef_run) { runner.converge('apt-zabbix::default') }
#let(:chef_run) do
# ChefSpec::SoloRunner.new do |node|
# node.set['virtualbox']['version'] = virtual_box_version
# end.converge(described_recipe)
#end
#before do
# allow(::File).to receive(:executable?).and_return(true)
#end
it 'installs the apt repository' do
expect(chef_run).to add_apt_repository('zabbix').with(
:uri => 'http://repo.zabbix.com/zabbix/3.0/debian',
:key => 'zabbix-official-repo.key',
:distribution => 'jessie',
:components => ['main']
)
#expect(chef_run).to render_file('/etc/apt/sources.list.d/zabbix.list').with_content('deb "http://repo.zabbix.com/zabbix/3.0/debian" jessie main')
end
end

66
test/Vagrantfile.erb Normal file
View file

@ -0,0 +1,66 @@
Vagrant.configure("2") do |c|
c.vm.box = "<%= config[:box] %>"
c.vm.box_url = "<%= config[:box_url] %>"
if Vagrant.has_plugin?("vagrant-cachier")
c.cache.auto_detect = true
c.cache.scope = :box
end
#if Vagrant.has_plugin?("vagrant-omnibus")
# c.omnibus.cache_packages = true
# c.omnibus.chef_version = <%= config[:chef_version] %>
#end
if Vagrant.has_plugin?("vagrant-libvirt")
c.vm.provider :libvirt do |libvirt|
libvirt.storage_pool_name = "Virt-SSD"
libvirt.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
end
end
c.vbguest.auto_update = false
<% if config[:vm_hostname] %>
c.vm.hostname = "<%= config[:vm_hostname] %>"
<% end %>
<% if config[:guest] %>
c.vm.guest = <%= config[:guest] %>
<% end %>
<% if config[:username] %>
c.ssh.username = "<%= config[:username] %>"
<% end %>
<% if config[:ssh_key] %>
c.ssh.private_key_path = "<%= config[:ssh_key] %>"
<% end %>
<% Array(config[:network]).each do |opts| %>
c.vm.network(:<%= opts[0] %>, <%= opts[1..-1].join(", ") %>)
<% end %>
c.vm.synced_folder ".", "/vagrant", disabled: true
<% config[:synced_folders].each do |source, destination, options| %>
c.vm.synced_folder "<%= source %>", "<%= destination %>", <%= options %>
<% end %>
c.vm.provider :<%= config[:provider] %> do |p|
<% config[:customize].each do |key, value| %>
<% case config[:provider]
when "virtualbox" %>
p.customize ["modifyvm", :id, "--<%= key %>", "<%= value %>"]
<% when "rackspace", "softlayer" %>
p.<%= key %> = "<%= value%>"
<% when /^vmware_/ %>
<% if key == :memory %>
<% unless config[:customize].include?(:memsize) %>
p.vmx["memsize"] = "<%= value %>"
<% end %>
<% else %>
p.vmx["<%= key %>"] = "<%= value %>"
<% end %>
<% end %>
<% 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,23 @@
require 'spec_helper'
describe 'apt-zabbix::default' do
### REPOSITORIES
#
describe 'Repositories should be installed:' do
describe file('/etc/apt/sources.list.d') do
it { should be_directory }
it { should be_mode 755 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
describe file('/etc/apt/sources.list.d/zabbix.list') do
it { should exist }
it { should be_mode 644 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its(:content) { shoult match('deb ... jessie contrib non-free main') }
end
end
end

View file

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