From 611e54f835db5f252a014d21b556e4b3c433bb5f Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Thu, 8 Dec 2016 17:36:10 -0500 Subject: [PATCH 1/2] Added test-kitchen and chefspec --- .kitchen.yml | 25 +++++++++++ Gemfile | 7 +++ chefignore | 1 + spec/spec_helper.rb | 10 +++++ spec/unit/recipes/default_spec.rb | 44 +++++++++++++++++++ test/environments/integration_test_env.json | 16 +++++++ .../default/serverspec/default_spec.rb | 15 +++++++ .../helpers/serverspec/spec_helper.rb | 4 ++ 8 files changed, 122 insertions(+) create mode 100644 .kitchen.yml create mode 100644 Gemfile create mode 100644 chefignore create mode 100644 spec/spec_helper.rb create mode 100644 spec/unit/recipes/default_spec.rb create mode 100644 test/environments/integration_test_env.json create mode 100644 test/integration/default/serverspec/default_spec.rb create mode 100644 test/integration/helpers/serverspec/spec_helper.rb diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..f972204 --- /dev/null +++ b/.kitchen.yml @@ -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] + diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..d000c9b --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +source 'https://rubygems.org' +gem 'berkshelf' +gem 'test-kitchen' +gem 'chefspec' +gem 'foodcritic' +gem 'kitchen-docker' + diff --git a/chefignore b/chefignore new file mode 100644 index 0000000..7be3c6d --- /dev/null +++ b/chefignore @@ -0,0 +1 @@ +.kitchen diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..6577937 --- /dev/null +++ b/spec/spec_helper.rb @@ -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! + diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb new file mode 100644 index 0000000..5e99258 --- /dev/null +++ b/spec/unit/recipes/default_spec.rb @@ -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 + diff --git a/test/environments/integration_test_env.json b/test/environments/integration_test_env.json new file mode 100644 index 0000000..445c15b --- /dev/null +++ b/test/environments/integration_test_env.json @@ -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": { + + } +} + diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb new file mode 100644 index 0000000..4c974e1 --- /dev/null +++ b/test/integration/default/serverspec/default_spec.rb @@ -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 + diff --git a/test/integration/helpers/serverspec/spec_helper.rb b/test/integration/helpers/serverspec/spec_helper.rb new file mode 100644 index 0000000..677ae95 --- /dev/null +++ b/test/integration/helpers/serverspec/spec_helper.rb @@ -0,0 +1,4 @@ +require 'serverspec' + +set :backend, :exec + From 63d9340c9d001ff93491958de28d6eb314288a7d Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Thu, 8 Dec 2016 17:38:08 -0500 Subject: [PATCH 2/2] Updated version --- metadata.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index bca31cd..2e2c871 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ maintainer_email 'psi-jack@linux-help.org' license 'Apache 2.0' description 'Installs and configures the Official Rsyslog Yum Repository' long_description '' -version '0.1.1' +version '0.1.2' issues_url 'http://gogs.home.ld/Linux-Help/cookbook-yum-rsyslog/issues' source_url 'http://gogs.home.ld/Linux-Help/cookbook-yum-rsyslog'