summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Doherty <cdoherty@chef.io>2015-12-08 16:15:20 -0800
committerChris Doherty <cdoherty@chef.io>2015-12-08 16:15:20 -0800
commit3377aefc317b2c38b9bd63ccfec9747e6d2d2784 (patch)
treef43ffb611cc70dc8d3f7b8679a201ca8f1b6557e
parent5302f698aa7ccf78d04660ea953237fd7444624e (diff)
downloadchef-zero-3377aefc317b2c38b9bd63ccfec9747e6d2d2784.tar.gz
clears create and update specs.
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb18
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb10
2 files changed, 23 insertions, 5 deletions
diff --git a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb b/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb
index 4bea4c1..6117278 100644
--- a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb
+++ b/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb
@@ -14,7 +14,9 @@ module ChefZero
# PUT /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
def put(request)
- cookbook_name, identifier = request.rest_path.last(2)
+ if exists_data?(request)
+ return error(409, "Cookbooks cannot be modified, and a cookbook with this identifier already exists.")
+ end
# pedant dictates that we not return the "json_class" element, so let's not store it.
identified_cookbook_json = to_json(parse_json(request.body).tap { |o| o.delete("json_class") })
@@ -26,9 +28,17 @@ module ChefZero
# DELETE /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
def delete(request)
- delete_data(request)
-
- return already_json_response(200, "{}")
+ begin
+ delete_data(request)
+ already_json_response(200, "{}")
+ rescue StandardError => ex
+ case ex.cause
+ when ChefZero::DataStore::DataNotFoundError
+ error(404, "not_found")
+ else
+ raise
+ end
+ end
end
end
end
diff --git a/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb b/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
index c488f73..4fe25ef 100644
--- a/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
@@ -7,7 +7,15 @@ module ChefZero
def get(request)
data = {}
- list_data(request, request.rest_path).each do |cookbook_artifact|
+ artifacts = begin
+ list_data(request, request.rest_path)
+ rescue Exception => e
+ if e.response_code == 404
+ return already_json_response(200, "{}")
+ end
+ end
+
+ artifacts.each do |cookbook_artifact|
cookbook_url = build_uri(request.base_uri, request.rest_path + [cookbook_artifact])
versions = []