-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Refactor providers to support whyrun mode - Package custom ChefSpec matchers - Add Test Kitchen integration test - Update ChefSpec tests - Expand environment variables (like `$PATH`) (Fixes #6) - Add Rakefile for running tests - Use the latest and greatest testing strategies
- Loading branch information
Showing
41 changed files
with
411 additions
and
282 deletions.
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 |
---|---|---|
@@ -1,17 +1,23 @@ | ||
*.swp | ||
.rvmrc | ||
|
||
.idea | ||
.yardoc | ||
*.gem | ||
*.html | ||
*.rbc | ||
*.swp | ||
coverage | ||
doc | ||
tmp | ||
*~ | ||
*# | ||
.#* | ||
\#*# | ||
.*.sw[a-z] | ||
*.un~ | ||
*.tmp | ||
*.bk | ||
*.bkup | ||
.kitchen.local.yml | ||
Berksfile.lock | ||
Gemfile.lock | ||
gemfiles/*.lock | ||
.bundle | ||
bin | ||
vendor | ||
|
||
.bundle/ | ||
.cache/ | ||
.kitchen/ | ||
.vagrant/ | ||
.vagrant.d/ | ||
.yardoc/ | ||
bin/ | ||
doc/ | ||
tmp/ | ||
vendor/ |
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,27 @@ | ||
driver: | ||
name: vagrant | ||
|
||
provisioner: | ||
name: chef_solo | ||
data_path: test/shared | ||
|
||
platforms: | ||
- name: ubuntu-12.04 | ||
- name: centos-6.4 | ||
|
||
suites: | ||
# | ||
# Alias suites | ||
# | ||
- name: magic_shell_alias_add | ||
run_list: magic_shell_alias::add | ||
- name: magic_shell_alias_remove | ||
run_list: magic_shell_alias::remove | ||
|
||
# | ||
# Environment suites | ||
# | ||
- name: magic_shell_environment_add | ||
run_list: magic_shell_environment::add | ||
- name: magic_shell_environment_remove | ||
run_list: magic_shell_environment::remove |
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 @@ | ||
Encoding: | ||
Enabled: false | ||
LineLength: | ||
Enabled: false |
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 |
---|---|---|
@@ -1,9 +1,6 @@ | ||
language: ruby | ||
rvm: | ||
- 1.9.2 | ||
- 1.9.3 | ||
env: | ||
- CHEF_VERSION='~> 10.0' | ||
- CHEF_VERSION='~> 11.0' | ||
- 2.0.0 | ||
- 2.1.0 | ||
script: | ||
- bundle exec strainer test | ||
- bundle exec rake travis:ci |
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 @@ | ||
source 'https://api.berkshelf.com' | ||
|
||
group :integration do | ||
cookbook 'magic_shell_alias', path: 'test/fixtures/cookbooks/magic_shell_alias' | ||
cookbook 'magic_shell_environment', path: 'test/fixtures/cookbooks/magic_shell_environment' | ||
end | ||
|
||
metadata |
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
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'chef', ENV['CHEF_VERSION'] || '>= 10.0' | ||
gem 'rake' | ||
|
||
group :test do | ||
gem 'chefspec', '~> 1.0.0' | ||
gem 'foodcritic', '~> 2.1.0' | ||
gem 'strainer', '~> 2.0.0' | ||
gem 'berkshelf', '~> 3.0.0.beta' | ||
gem 'chefspec', '~> 3.0' | ||
gem 'foodcritic', '~> 3.0' | ||
gem 'rubocop', '~> 0.16' | ||
|
||
gem 'test-kitchen', '~> 1.1' | ||
gem 'kitchen-vagrant', '~> 0.14' | ||
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 |
---|---|---|
|
@@ -4,14 +4,6 @@ magic_shell Cookbook | |
|
||
Provides utility for adding some syntactic sugar to your shell. | ||
|
||
Requirements | ||
------------ | ||
None | ||
|
||
Attributes | ||
---------- | ||
None | ||
|
||
Usage | ||
----- | ||
Update the `metadata.rb` for your cookbook to depend on magic_shell | ||
|
@@ -63,8 +55,24 @@ Contributing | |
3. Code, document, write specs, test | ||
4. Submit a PR | ||
|
||
License and Authors | ||
------------------- | ||
Author: [Nathen Harvey](https://github.com/nathenharvey) ([@nathenharvey](https://twitter.com/nathenharvey)) | ||
|
||
Copyright 2012, CustomInk, LLC | ||
License & Authors | ||
----------------- | ||
- Author: Nathen Harvey <[email protected]> | ||
- Author: Seth Vargo <[email protected]> | ||
|
||
```text | ||
Copyright 2012-2014 CustomInk, LLC. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
``` |
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,38 @@ | ||
require 'bundler/setup' | ||
|
||
namespace :style do | ||
require 'rubocop/rake_task' | ||
desc 'Run Ruby style checks' | ||
Rubocop::RakeTask.new(:ruby) | ||
|
||
require 'foodcritic' | ||
desc 'Run Chef style checks' | ||
FoodCritic::Rake::LintTask.new(:chef) | ||
end | ||
|
||
desc 'Run all style checks' | ||
task style: ['style:chef', 'style:ruby'] | ||
|
||
require 'rspec/core/rake_task' | ||
desc 'Run ChefSpec unit tests' | ||
RSpec::Core::RakeTask.new(:unit) do |t| | ||
t.rspec_opts = '--color --format progress' | ||
end | ||
|
||
require 'kitchen' | ||
desc 'Run Test Kitchen integration tests' | ||
task :integration do | ||
Kitchen.logger = Kitchen.default_file_logger | ||
Kitchen::Config.new.instances.each do |instance| | ||
instance.test(:always) | ||
end | ||
end | ||
|
||
# We cannot run Test Kitchen on Travis CI yet... | ||
namespace :travis do | ||
desc 'Run tests on Travis' | ||
task ci: ['style', 'unit'] | ||
end | ||
|
||
# The default rake task should just run it all | ||
task default: ['style', 'unit', 'integration'] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
if defined?(ChefSpec) | ||
def add_magic_shell_alias(name) | ||
ChefSpec::Matchers::ResourceMatcher.new(:magic_shell_alias, :add, name) | ||
end | ||
|
||
def remove_magic_shell_alias(name) | ||
ChefSpec::Matchers::ResourceMatcher.new(:magic_shell_alias, :remove, name) | ||
end | ||
|
||
def add_magic_shell_environment(name) | ||
ChefSpec::Matchers::ResourceMatcher.new(:magic_shell_environment, :add, name) | ||
end | ||
|
||
def remove_magic_shell_environment(name) | ||
ChefSpec::Matchers::ResourceMatcher.new(:magic_shell_environment, :remove, name) | ||
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
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 |
---|---|---|
@@ -1,27 +1,68 @@ | ||
# | ||
# Cookbook Name:: magic_shell | ||
# Provider:: alias | ||
# | ||
# Author:: Nathen Harvey <[email protected]> | ||
# Author:: Seth Vargo <[email protected]> | ||
# | ||
# Copyright 2012-2014, CustomInk, LLC. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# | ||
# Delegate update actions to inline resources | ||
# | ||
use_inline_resources | ||
|
||
# | ||
# This provider supports why-run mode. | ||
# | ||
def whyrun_supported? | ||
true | ||
end | ||
|
||
# | ||
# Create a file entry for the given alias. | ||
# | ||
action :add do | ||
command_name = new_resource.alias_name.gsub(/ /,"_") | ||
if !new_resource.command.nil? | ||
Chef::Log.info("Adding #{command_name}.sh to /etc/profile.d/") | ||
file_contents = "# This alias was generated by Chef for #{node["fqdn"]}\n" | ||
file_contents += "alias #{command_name}='#{new_resource.command}'" | ||
resource = file "/etc/profile.d/#{command_name}.sh" do | ||
owner "root" | ||
group "root" | ||
mode "0755" | ||
content file_contents | ||
action :nothing | ||
end | ||
resource.run_action(:create) | ||
new_resource.updated_by_last_action(true) if resource.updated_by_last_action? | ||
end | ||
file = Chef::Resource::File.new(destination, run_context) | ||
file.owner('root') | ||
file.group('root') | ||
file.mode('0755') | ||
file.content(<<-EOH.gsub(/^ {8}/, '')) | ||
# | ||
# This file was generated by Chef for #{node['fqdn']} | ||
# Do NOT modify this file by hand! | ||
# | ||
alias #{new_resource.alias_name}="#{new_resource.command}" | ||
EOH | ||
file.run_action(:create) | ||
end | ||
|
||
# | ||
# Delete the file entry for the given alias. | ||
# | ||
action :remove do | ||
command_name = new_resource.alias_name.gsub(/ /,"_") | ||
resource = file "/etc/profile.d/#{command_name}.sh" do | ||
action :nothing | ||
end | ||
file = Chef::Resource::File.new(destination, run_context) | ||
file.run_action(:delete) | ||
end | ||
|
||
def destination | ||
"/etc/profile.d/#{filename}.sh" | ||
end | ||
|
||
resource.run_action(:delete) | ||
new_resource.updated_by_last_action(true) if resource.updated_by_last_action? | ||
def filename | ||
new_resource.alias_name.to_s.gsub(/\s/, '_') | ||
end |
Oops, something went wrong.