Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Chefspec testing #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Berksfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
site :opscode
source "https://supermarket.chef.io"

cookbook 'yum'
cookbook 'yum-epel'
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ gem 'berkshelf'
gem 'test-kitchen'
gem 'kitchen-vagrant'
gem 'foodcritic'
gem 'chefspec'
39 changes: 39 additions & 0 deletions spec/recipes/default_spec.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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