-
Notifications
You must be signed in to change notification settings - Fork 338
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
sethvargo
merged 3 commits into
chefspec:master
from
cullenmcdermott:add_apt_repository_matcher
Jul 30, 2016
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apt_repository 'default_action' | ||
|
||
apt_update 'explicit_action' do | ||
action :periodic | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
apt_update 'update_repo' do | ||
action :update | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this in #752