Skip to content
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

Berksfile resolve #59

Merged
merged 2 commits into from Jun 26, 2012
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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