summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2015-02-10 10:24:05 -0800
committerdanielsdeleo <dan@getchef.com>2015-02-11 10:52:49 -0800
commit06757d1307538f7b4d8ef4c57beedc7eff8b8bbe (patch)
tree12743d1fdc81e10d70b6e268233161fa7fc3a41d
parent20bc6b6e6faa8c3730eb59f3a999ec41ebb8a560 (diff)
downloadchef-06757d1307538f7b4d8ef4c57beedc7eff8b8bbe.tar.gz
Switch save URL based on policy mode flag
-rw-r--r--lib/chef/cookbook_manifest.rb15
-rw-r--r--spec/unit/cookbook_manifest_spec.rb42
2 files changed, 48 insertions, 9 deletions
diff --git a/lib/chef/cookbook_manifest.rb b/lib/chef/cookbook_manifest.rb
index 417afbd82c..92f20664bd 100644
--- a/lib/chef/cookbook_manifest.rb
+++ b/lib/chef/cookbook_manifest.rb
@@ -39,8 +39,9 @@ class Chef
def_delegator :@cookbook_version, :version
def_delegator :@cookbook_version, :frozen_version?
- def initialize(cookbook_version)
+ def initialize(cookbook_version, policy_mode: false)
@cookbook_version = cookbook_version
+ @policy_mode = !!policy_mode
reset!
end
@@ -99,6 +100,10 @@ class Chef
@manifest_records_by_path
end
+ def policy_mode?
+ @policy_mode
+ end
+
def to_hash
result = manifest.dup
result['frozen?'] = frozen_version?
@@ -116,14 +121,14 @@ class Chef
# REST api. If there is an existing document on the server and it
# is marked frozen, a PUT will result in a 409 Conflict.
def save_url
- "cookbooks/#{name}/#{version}"
+ "#{cookbook_url_path}/#{name}/#{version}"
end
# Adds the `force=true` parameter to the upload URL. This allows
# the user to overwrite a frozen cookbook (a PUT against the
# normal #save_url raises a 409 Conflict in this case).
def force_save_url
- "cookbooks/#{name}/#{version}?force=true"
+ "#{cookbook_url_path}/#{name}/#{version}?force=true"
end
# TODO: This is kind of terrible. investigate removing it
@@ -144,6 +149,10 @@ class Chef
private
+ def cookbook_url_path
+ policy_mode? ? "cookbook_artifacts" : "cookbooks"
+ end
+
# See #manifest for a description of the manifest return value.
# See #preferred_manifest_record for a description an individual manifest record.
def generate_manifest
diff --git a/spec/unit/cookbook_manifest_spec.rb b/spec/unit/cookbook_manifest_spec.rb
index 8f9c9810d4..938f72c743 100644
--- a/spec/unit/cookbook_manifest_spec.rb
+++ b/spec/unit/cookbook_manifest_spec.rb
@@ -38,7 +38,19 @@ describe Chef::CookbookManifest do
end
end
- subject(:cookbook_manifest) { Chef::CookbookManifest.new(cookbook_version) }
+ let(:policy_mode) { false }
+
+ subject(:cookbook_manifest) { Chef::CookbookManifest.new(cookbook_version, policy_mode: policy_mode) }
+
+ context "when policy mode is not specified" do
+
+ subject(:cookbook_manifest) { Chef::CookbookManifest.new(cookbook_version) }
+
+ it "defaults to policies disabled" do
+ expect(cookbook_manifest.policy_mode?).to be(false)
+ end
+
+ end
describe "collecting cookbook data from the cookbook version object" do
@@ -157,6 +169,7 @@ describe Chef::CookbookManifest do
"root_files" => map_to_file_specs(root_filenames),
}
end
+
before do
cookbook_version.attribute_filenames = attribute_filenames
cookbook_version.definition_filenames = definition_filenames
@@ -183,14 +196,31 @@ describe Chef::CookbookManifest do
describe "providing upstream URLs for save" do
- it "gives the save URL" do
- expect(cookbook_manifest.save_url).to eq("cookbooks/tatft/1.2.3")
- end
+ context "and policy mode is disabled" do
+
+ it "gives the save URL" do
+ expect(cookbook_manifest.save_url).to eq("cookbooks/tatft/1.2.3")
+ end
+
+ it "gives the force save URL" do
+ expect(cookbook_manifest.force_save_url).to eq("cookbooks/tatft/1.2.3?force=true")
+ end
- it "gives the force save URL" do
- expect(cookbook_manifest.force_save_url).to eq("cookbooks/tatft/1.2.3?force=true")
end
+ context "and policy mode is enabled" do
+
+ let(:policy_mode) { true }
+
+ it "gives the save URL" do
+ expect(cookbook_manifest.save_url).to eq("cookbook_artifacts/tatft/1.2.3")
+ end
+
+ it "gives the force save URL" do
+ expect(cookbook_manifest.force_save_url).to eq("cookbook_artifacts/tatft/1.2.3?force=true")
+ end
+
+ end
end
end