Skip to content

Commit

Permalink
Merge pull request #59 from RiotGames/berksfile_resolve
Browse files Browse the repository at this point in the history
Berksfile resolve
  • Loading branch information
reset committed Jun 26, 2012
2 parents 62f9699 + a2f1364 commit ba2bbfc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/berkshelf/berksfile.rb
Expand Up @@ -151,14 +151,25 @@ def install(options = {})
# Server so that it cannot be overwritten
def upload(chef_server_url, options = {})
uploader = Uploader.new(chef_server_url, options)
resolver = Resolver.new(Berkshelf.downloader, sources(exclude: options[:without]))
solution = resolve(options)

resolver.resolve.each do |cb|
solution.each do |cb|
Berkshelf.ui.info "Uploading #{cb.cookbook_name} (#{cb.version}) to: '#{chef_server_url}'"
uploader.upload!(cb, options)
end
end

# Finds a solution for the Berksfile and returns an array of CachedCookbooks.
#
# @option options [Symbol, Array] :without
# Group(s) to exclude which will cause any sources marked as a member of the
# group to not be resolved
#
# @return [Array<Berkshelf::CachedCookbooks]
def resolve(options = {})
Resolver.new(Berkshelf.downloader, sources(exclude: options[:without])).resolve
end

# Write a collection of hard links to the given path representing the given
# CachedCookbooks. Useful for getting Cookbooks in a single location for
# consumption by Vagrant, or another tool that expect this structure.
Expand Down
11 changes: 11 additions & 0 deletions spec/unit/berkshelf/berksfile_spec.rb
Expand Up @@ -121,6 +121,17 @@ module Berkshelf
end
end

describe "#resolve" do
let(:resolver) { double('resolver') }
before(:each) { Berkshelf::Resolver.stub(:new) { resolver } }

it "resolves the Berksfile" do
resolver.should_receive(:resolve).and_return([double('cached_cookbook_one'), double('cached_cookbook_two')])
solution = subject.resolve
solution.should have(2).items
end
end

describe "#install" do
let(:resolver) { double('resolver') }
before(:each) { Berkshelf::Resolver.stub(:new) { resolver } }
Expand Down

0 comments on commit ba2bbfc

Please sign in to comment.