From 4cf8ce3d10f5f5fb314529aef34936e8d667c339 Mon Sep 17 00:00:00 2001 From: Jim Rosser Date: Mon, 18 Jul 2016 11:35:53 -0500 Subject: [PATCH] Added Chefspec testing --- Berksfile | 2 +- Gemfile | 1 + spec/recipes/default_spec.rb | 39 ++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 23 +++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 spec/recipes/default_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/Berksfile b/Berksfile index 2db8943..d5941dd 100644 --- a/Berksfile +++ b/Berksfile @@ -1,4 +1,4 @@ -site :opscode +source "https://supermarket.chef.io" cookbook 'yum' cookbook 'yum-epel' diff --git a/Gemfile b/Gemfile index d7e1576..8c1ec37 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,4 @@ gem 'berkshelf' gem 'test-kitchen' gem 'kitchen-vagrant' gem 'foodcritic' +gem 'chefspec' diff --git a/spec/recipes/default_spec.rb b/spec/recipes/default_spec.rb new file mode 100644 index 0000000..247216d --- /dev/null +++ b/spec/recipes/default_spec.rb @@ -0,0 +1,39 @@ +require_relative '../spec_helper' + +describe 'sysdig::default' do + describe 'when platform is ubuntu' do + before do + stub_command('apt-key list | grep -i EC51E8C4').and_return(false) + end + + let(:chef_run) do + chef_runner = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') + chef_runner.converge(described_recipe) + end + + it 'adds apt repository' do + expect(chef_run).to add_apt_repository('sysdig') + end + end + + describe 'when platform is rhel or fedora' do + let(:chef_run) do + chef_runner = ChefSpec::SoloRunner.new(platform: 'centos', version: '7.0') + chef_runner.converge(described_recipe) + end + + it 'includes yum epel' do + expect(chef_run).to include_recipe('yum-epel') + end + + it 'adds the yum repository' do + expect(chef_run).to create_yum_repository('sysdig') + end + end + + let(:chef_run) { ChefSpec::SoloRunner.new().converge(described_recipe) } + + it 'installs sysdig' do + expect(chef_run).to install_package('sysdig') + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..7a59897 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,23 @@ +# Added by ChefSpec +require 'chefspec' +require 'chefspec/berkshelf' + +RSpec.configure do |config| + # Specify the path for Chef Solo to find cookbooks + # config.cookbook_path = '/var/cookbooks' + + # Specify the path for Chef Solo to find roles + # config.role_path = '/var/roles' + + # Specify the Chef log_level (default: :warn) + # config.log_level = :debug + + # Specify the path to a local JSON file with Ohai data + # config.path = 'ohai.json' + + # Specify the operating platform to mock Ohai data from + # config.platform = 'ubuntu' + + # Specify the operating version to mock Ohai data from + # config.version = '14.04' +end