forked from johnbintz/guard-puppet
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b33bdc4
Showing
11 changed files
with
199 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.gem | ||
.bundle | ||
Gemfile.lock | ||
pkg/* |
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 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in guard-puppet.gemspec | ||
gemspec | ||
|
||
require 'rbconfig' | ||
if RbConfig::CONFIG['host_os'] =~ /linux/ | ||
gem 'libnotify' | ||
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 @@ | ||
# A sample Guardfile | ||
# More info at https://github.com/guard/guard#readme | ||
|
||
guard 'rspec', :version => 2 do | ||
watch(%r{^spec/.+_spec\.rb$}) | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
watch('spec/spec_helper.rb') { "spec" } | ||
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 @@ | ||
require 'bundler/gem_tasks' |
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,26 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "guard/puppet/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "guard-puppet" | ||
s.version = Guard::PuppetVersion::VERSION | ||
s.authors = ["John Bintz"] | ||
s.email = ["john@coswellproductions.com"] | ||
s.homepage = "" | ||
s.summary = %q{TODO: Write a gem summary} | ||
s.description = %q{TODO: Write a gem description} | ||
|
||
s.rubyforge_project = "guard-puppet" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
|
||
s.add_dependency 'guard' | ||
s.add_dependency 'puppet' | ||
|
||
s.add_development_dependency 'rspec', '~> 2.6.0' | ||
s.add_development_dependency 'mocha' | ||
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,30 @@ | ||
require 'guard/guard' | ||
|
||
module ::Guard | ||
class Puppet < ::Guard::Guard | ||
class << self | ||
attr_accessor :is_wrapping_exit | ||
end | ||
|
||
def initialize(watchers = [], options = {}) | ||
super | ||
@options = options | ||
end | ||
|
||
def run_all | ||
UI.info msg = "Applying Puppet configuration..." | ||
Notifier.notify msg, :title => "Puppet Config", :image => :pending | ||
if Runner.new(@options).run != 0 | ||
Notifier.notify "Puppet config failure!", :title => "Puppet Config", :image => :failed | ||
else | ||
Notifier.notify "Puppet config reapplied successfully!", :title => "Puppet Config" | ||
end | ||
end | ||
|
||
def run_on_change(files = []) | ||
run_all | ||
end | ||
end | ||
end | ||
|
||
require 'guard/puppet/runner' |
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,32 @@ | ||
require 'guard/puppet' | ||
require 'puppet/util/command_line' | ||
require 'puppet/application/apply' | ||
|
||
module Guard | ||
class Puppet | ||
class Runner | ||
attr_reader :options | ||
|
||
def initialize(options) | ||
@options = options | ||
end | ||
|
||
def run | ||
::Puppet::Util::CommandLine.new('puppet', command_line_params) | ||
rescue SystemExit => e | ||
e.status | ||
end | ||
|
||
def command_line_params | ||
command = [ "apply" ] | ||
command << "-v" if @options[:verbose] | ||
if @options[:config_dir] | ||
@options[:config_dir] = Dir.pwd if @options[:config_dir] == true | ||
command << %{--confdir="#{@options[:config_dir]}"} if @options[:config_dir] | ||
end | ||
command << @options[:manifest] if @options[:manifest] | ||
command | ||
end | ||
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,5 @@ | ||
module Guard | ||
module PuppetVersion | ||
VERSION = '0.0.1' | ||
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,47 @@ | ||
require 'spec_helper' | ||
require 'guard/puppet/runner' | ||
|
||
describe Guard::Puppet::Runner do | ||
let(:options) { {} } | ||
let(:runner) { described_class.new(options) } | ||
|
||
describe '#command_line_params' do | ||
subject { runner.command_line_params } | ||
|
||
context 'default' do | ||
it { should == [ 'apply' ] } | ||
end | ||
|
||
context 'verbose' do | ||
let(:options) { { :verbose => true } } | ||
|
||
it { should == [ 'apply', '-v' ] } | ||
end | ||
|
||
context 'config dir with path' do | ||
let(:options) { { :config_dir => '/123' } } | ||
|
||
it { should == [ 'apply', '--confdir="/123"' ] } | ||
end | ||
|
||
context 'config dir with true' do | ||
let(:options) { { :config_dir => true } } | ||
|
||
it { should == [ 'apply', %{--confdir="#{Dir.pwd}"} ] } | ||
end | ||
|
||
context 'manifest' do | ||
let(:options) { { :manifest => '123' } } | ||
|
||
it { should == [ 'apply', '123' ] } | ||
end | ||
end | ||
|
||
describe '#run' do | ||
it 'should return the result of an exit call' do | ||
::Puppet::Util::CommandLine.expects(:new).raises(SystemExit.new(10)) | ||
|
||
runner.run.should == 10 | ||
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,32 @@ | ||
require 'spec_helper' | ||
require 'guard/puppet' | ||
|
||
describe Guard::Puppet do | ||
let(:guard) { described_class.new } | ||
|
||
describe '#run_all' do | ||
before do | ||
Guard::UI.expects(:info) | ||
Guard::Notifier.expects(:notify).with("Applying Puppet configuration...", { :image => :pending, :title => "Puppet Config" }) | ||
Guard::Puppet::Runner.any_instance.expects(:run).returns(return_value) | ||
end | ||
|
||
context 'fails' do | ||
let(:return_value) { 1 } | ||
|
||
it 'should show the failure message' do | ||
Guard::Notifier.expects(:notify).with("Puppet config failure!", :image => :failed, :title => "Puppet Config") | ||
guard.run_all | ||
end | ||
end | ||
|
||
context 'succeeds' do | ||
let(:return_value) { 0 } | ||
|
||
it 'should show the success message' do | ||
Guard::Notifier.expects(:notify).with("Puppet config reapplied successfully!", :title => "Puppet Config") | ||
guard.run_all | ||
end | ||
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,4 @@ | ||
RSpec.configure do |c| | ||
c.mock_with :mocha | ||
end | ||
|