Skip to content
This repository has been archived by the owner on Mar 19, 2022. It is now read-only.

Remove hard dependency on librarian #211

Merged
merged 7 commits into from
Mar 25, 2013
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: 4 additions & 4 deletions knife-solo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Gem::Specification.new do |s|
s.post_install_message = KnifeSolo.post_install_message

s.add_development_dependency 'bundler'
s.add_development_dependency 'rake'
s.add_development_dependency 'mocha'
s.add_development_dependency 'rdoc'
s.add_development_dependency 'fog'
s.add_development_dependency 'librarian', '~> 0.0.26'
s.add_development_dependency 'minitest'
s.add_development_dependency 'mocha'
s.add_development_dependency 'parallel'
s.add_development_dependency 'rake'
s.add_development_dependency 'rdoc'

s.add_dependency 'chef', chef_version
s.add_dependency 'net-ssh', '>= 2.2.2', '< 3.0'
s.add_dependency 'librarian', '~> 0.0.20'
end
27 changes: 21 additions & 6 deletions lib/chef/knife/solo_cook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class SoloCook < Knife

deps do
require 'chef/cookbook/chefignore'
require 'librarian/action'
require 'librarian/chef'
require 'pathname'
KnifeSolo::SshCommand.load_deps
KnifeSolo::NodeConfigCommand.load_deps
Expand Down Expand Up @@ -133,10 +131,27 @@ def time(msg)
end

def librarian_install
return unless File.exist? 'Cheffile'
ui.msg "Installing Librarian cookbooks..."
Librarian::Action::Resolve.new(librarian_env).run
Librarian::Action::Install.new(librarian_env).run
if !File.exist? 'Cheffile'
Chef::Log.debug "Cheffile not found"
elsif !load_librarian
ui.warn "Librarian-Chef could not be loaded"
ui.warn "Please add the librarian gem to your Gemfile or install it manually with `gem install librarian`"
else
ui.msg "Installing Librarian cookbooks..."
Librarian::Action::Resolve.new(librarian_env).run
Librarian::Action::Install.new(librarian_env).run
end
end

def load_librarian
begin
require 'librarian/action'
require 'librarian/chef'
rescue LoadError
false
else
true
end
end

def librarian_env
Expand Down
25 changes: 23 additions & 2 deletions test/solo_cook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,41 @@ def test_does_not_run_librarian_if_no_cheffile

def test_runs_librarian_if_cheffile_found
in_kitchen do
File.open("Cheffile", 'w') {}
FileUtils.touch "Cheffile"
Librarian::Action::Install.any_instance.expects(:run)
command("somehost").run
end
end

def test_does_not_run_librarian_if_denied_by_option
in_kitchen do
File.open("Cheffile", 'w') {}
FileUtils.touch "Cheffile"
Librarian::Action::Install.any_instance.expects(:run).never
command("somehost", "--no-librarian").run
end
end

def test_complains_if_librarian_gem_missing
in_kitchen do
FileUtils.touch "Cheffile"
cmd = command("somehost")
cmd.expects(:load_librarian).returns(false)
cmd.ui.expects(:err).with(regexp_matches(/librarian gem/))
Librarian::Action::Install.any_instance.expects(:run).never
cmd.run
end
end

def test_wont_complain_if_librarian_gem_missing_but_no_cheffile
in_kitchen do
cmd = command("somehost")
cmd.expects(:load_librarian).never
cmd.ui.expects(:err).never
Librarian::Action::Install.any_instance.expects(:run).never
cmd.run
end
end

def test_validates_chef_version
in_kitchen do
cmd = command("somehost")
Expand Down