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

Add apt repository matcher #709

Merged
merged 3 commits into from
Jul 30, 2016
Merged
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
8 changes: 8 additions & 0 deletions examples/apt_repository/recipes/add.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apt_repository 'default_action' do
uri 'some_uri'
end

apt_repository 'explicit_action' do
uri 'some_url'
action :add
end
4 changes: 4 additions & 0 deletions examples/apt_repository/recipes/remove.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apt_repository 'explicit_remove_action' do
uri 'some_uri'
action :remove
end
14 changes: 14 additions & 0 deletions examples/apt_repository/spec/add_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'chefspec'

describe 'apt_repository::add' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }

it 'adds a apt_repository with default action' do
expect(chef_run).to add_apt_repository('default_action')
expect(chef_run).to_not add_apt_repository('not_default_action')
end

it 'installs a apt_repository with an explicit action' do
expect(chef_run).to add_apt_repository('explicit_action')
end
end
9 changes: 9 additions & 0 deletions examples/apt_repository/spec/remove_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'chefspec'

describe 'apt_repository::remove' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }

it 'removes a apt_repository with default action' do
expect(chef_run).to remove_apt_repository('explicit_remove_action')
end
end
5 changes: 5 additions & 0 deletions examples/apt_update/recipes/periodic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apt_repository 'default_action'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this in #752


apt_update 'explicit_action' do
action :periodic
end
3 changes: 3 additions & 0 deletions examples/apt_update/recipes/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apt_update 'update_repo' do
action :update
end
14 changes: 14 additions & 0 deletions examples/apt_update/spec/periodic_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'chefspec'

describe 'apt_update::periodic' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }

it 'updates apt with default action' do
expect(chef_run).to periodic_apt_update('default_action')
expect(chef_run).to_not periodic_apt_update('not_default_action')
end

it 'installs a apt_repository with an explicit action' do
expect(chef_run).to periodic_apt_update('explicit_action')
end
end
9 changes: 9 additions & 0 deletions examples/apt_update/spec/update_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'chefspec'

describe 'apt_update::update' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }

it 'updates apt repo' do
expect(chef_run).to update_apt_update('update_repo')
end
end
56 changes: 56 additions & 0 deletions lib/chefspec/api/apt_repository.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module ChefSpec::API
# @since 3.0.0
module AptRepositoryMatchers
ChefSpec.define_matcher :apt_repository

#
# Assert that an +apt_repository+ resource exists in the Chef run with the
# action +:add+. Given a Chef Recipe that adds "rsyslog" as an
# +apt_repository+:
#
# apt_repository 'rsyslog' do
# uri 'ppa:adiscon/v8-stable'
# action :add
# end
#
# The Examples section demonstrates the different ways to test an
# +apt_repository+ resource with ChefSpec.
#
# @example Assert that an +apt_repository+ was added
# expect(chef_run).to add_apt_repository('rsyslog')
# @param [String, Regex] resource_name
# the name of the resource to match
#
# @return [ChefSpec::Matchers::ResourceMatcher]

def add_apt_repository(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:apt_repository, :add,
resource_name)
end

#
# Assert that an +apt_repository+ resource exists in the Chef run with the
# action +:remove+. Given a Chef Recipe that removes "rsyslog" as an
# +apt_repository+:
#
# apt_repository 'rsyslog' do
# uri 'ppa:adiscon/v8-stable'
# action :remove
# end
#
# The Examples section demonstrates the different ways to test an
# +apt_repository+ resource with ChefSpec.
#
# @example Assert that an +apt_repository+ was removed
# expect(chef_run).to remove_apt_repository('rsyslog')
# @param [String, Regex] resource_name
# the name of the resource to match
#
# @return [ChefSpec::Matchers::ResourceMatcher]

def remove_apt_repository(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:apt_repository, :remove,
resource_name)
end
end
end
53 changes: 53 additions & 0 deletions lib/chefspec/api/apt_update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module ChefSpec::API
# @since 3.0.0
module AptUpdateMatchers
ChefSpec.define_matcher :apt_update

#
# Assert that an +apt_update+ resource exists in the Chef run with the
# action +:update+. Given a Chef Recipe that adds "rsyslog" as a repository
# to update.
# apt_repository 'rsyslog' do
# action :update
# end
#
# The Examples section demonstrates the different ways to test an
# +apt_update+ resource with ChefSpec.
#
# @example Assert that an +apt_update+ was run
# expect(chef_run).to update_apt_update('rsyslog')
# @param [String, Regex] resource_name
# the name of the resource to match
#
# @return [ChefSpec::Matchers::ResourceMatcher]

def update_apt_update(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:apt_update, :update,
resource_name)
end

#
# Assert that an +apt_update+ resource exists in the Chef run
# with the action +:periodic+. Given a Chef Recipe that updates "rsyslog"
# as an +apt_update+: periodically
#
# apt_update 'rsyslog' do
# action :periodic
# end
#
# The Examples section demonstrates the different ways to test an
# +apt_update+ resource with ChefSpec.
#
# @example Assert that an +apt_update+ was updated periodically
# expect(chef_run).to periodic_apt_update('rsyslog')
# @param [String, Regex] resource_name
# the name of the resource to match
#
# @return [ChefSpec::Matchers::ResourceMatcher]

def periodic_apt_update(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:apt_update, :periodic,
resource_name)
end
end
end