Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Make chef_repo relative paths relative to policy dir
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsdeleo committed Oct 19, 2015
1 parent 6c67d90 commit d8eb1c9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/chef-dk/policyfile/dsl.rb
Expand Up @@ -155,7 +155,7 @@ def set_default_chef_repo_source(path)
if path.nil?
@errors << "You must specify the path to the chef-repo when using a default_source :chef_repo"
else
set_default_source(ChefRepoCookbookSource.new(path))
set_default_source(ChefRepoCookbookSource.new(File.expand_path(path, storage_config.relative_paths_root)))
end
end

Expand Down
4 changes: 3 additions & 1 deletion spec/unit/policyfile_demands_spec.rb
Expand Up @@ -834,8 +834,10 @@
end

it "raises an error describing the conflict" do
repo_path = File.expand_path("path/to/repo")

expected_err = <<-ERROR
Source supermarket(https://supermarket.chef.io) and chef_repo(path/to/repo) contain conflicting cookbooks:
Source supermarket(https://supermarket.chef.io) and chef_repo(#{repo_path}) contain conflicting cookbooks:
- remote-cb
- remote-cb-two
ERROR
Expand Down
21 changes: 21 additions & 0 deletions spec/unit/policyfile_evaluation_spec.rb
Expand Up @@ -262,6 +262,27 @@
expect(policyfile.default_source).to eq(expected)
end

context "when the path to the chef repo is relative" do

let(:policyfile_rb) do
<<-EOH
run_list "foo", "bar"
default_source :chef_repo, "../cookbooks"
EOH
end

# storage_config is created with path to Policyfile.rb in CWD
let(:expected_path) { File.expand_path("../cookbooks") }

it "sets the repo path relative to the directory the policyfile is in" do
expect(policyfile.errors).to eq([])
expect(policyfile.default_source.size).to eq(1)
expect(policyfile.default_source.first).to be_a(ChefDK::Policyfile::ChefRepoCookbookSource)
expect(policyfile.default_source.first.path).to eq(expected_path)
end

end

end

context "with multiple default sources" do
Expand Down

0 comments on commit d8eb1c9

Please sign in to comment.