chef-dk 0.3.0 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -0
  3. data/lib/chef-dk/cli.rb +7 -5
  4. data/lib/chef-dk/command/generate.rb +2 -0
  5. data/lib/chef-dk/command/generator_commands.rb +8 -0
  6. data/lib/chef-dk/command/generator_commands/base.rb +4 -1
  7. data/lib/chef-dk/command/generator_commands/policyfile.rb +83 -0
  8. data/lib/chef-dk/command/install.rb +4 -5
  9. data/lib/chef-dk/command/push.rb +4 -5
  10. data/lib/chef-dk/command/verify.rb +3 -2
  11. data/lib/chef-dk/component_test.rb +7 -2
  12. data/lib/chef-dk/exceptions.rb +3 -34
  13. data/lib/chef-dk/helpers.rb +20 -2
  14. data/lib/chef-dk/policyfile/cookbook_locks.rb +19 -1
  15. data/lib/chef-dk/policyfile/read_cookbook_for_compat_mode_upload.rb +11 -1
  16. data/lib/chef-dk/policyfile/storage_config.rb +23 -0
  17. data/lib/chef-dk/policyfile/uploader.rb +1 -1
  18. data/lib/chef-dk/policyfile_services/install.rb +19 -32
  19. data/lib/chef-dk/policyfile_services/push.rb +17 -27
  20. data/lib/chef-dk/service_exception_inspectors.rb +25 -0
  21. data/lib/chef-dk/service_exception_inspectors/base.rb +40 -0
  22. data/lib/chef-dk/service_exception_inspectors/http.rb +121 -0
  23. data/lib/chef-dk/service_exceptions.rb +77 -0
  24. data/lib/chef-dk/skeletons/code_generator/recipes/policyfile.rb +8 -0
  25. data/lib/chef-dk/skeletons/code_generator/templates/default/Policyfile.rb.erb +16 -0
  26. data/lib/chef-dk/skeletons/code_generator/templates/default/kitchen.yml.erb +1 -1
  27. data/lib/chef-dk/version.rb +1 -1
  28. data/spec/unit/cli_spec.rb +126 -65
  29. data/spec/unit/command/exec_spec.rb +7 -2
  30. data/spec/unit/command/generator_commands/cookbook_spec.rb +27 -1
  31. data/spec/unit/command/generator_commands/policyfile_spec.rb +125 -0
  32. data/spec/unit/command/install_spec.rb +3 -4
  33. data/spec/unit/command/push_spec.rb +6 -7
  34. data/spec/unit/command/shell_init_spec.rb +5 -1
  35. data/spec/unit/cookbook_profiler/git_spec.rb +2 -2
  36. data/spec/unit/policyfile/cookbook_locks_spec.rb +58 -0
  37. data/spec/unit/policyfile/read_cookbook_for_compat_mode_upload_spec.rb +8 -1
  38. data/spec/unit/policyfile/storage_config_spec.rb +75 -1
  39. data/spec/unit/policyfile/uploader_spec.rb +31 -0
  40. data/spec/unit/policyfile_lock_validation_spec.rb +13 -12
  41. data/spec/unit/policyfile_services/install_spec.rb +5 -3
  42. data/spec/unit/policyfile_services/push_spec.rb +7 -5
  43. data/spec/unit/service_exception_inspectors/base_spec.rb +43 -0
  44. data/spec/unit/service_exception_inspectors/http_spec.rb +140 -0
  45. metadata +41 -2
@@ -20,6 +20,8 @@ require 'chef-dk/policyfile_services/push'
20
20
 
21
21
  describe ChefDK::PolicyfileServices::Push do
22
22
 
23
+ include ChefDK::Helpers
24
+
23
25
  let(:working_dir) do
24
26
  path = File.join(tempdir, "policyfile_services_test_working_dir")
25
27
  Dir.mkdir(path)
@@ -58,7 +60,7 @@ describe ChefDK::PolicyfileServices::Push do
58
60
  end
59
61
 
60
62
  it "infers the path to Policyfile.lock.json" do
61
- expect(push_service.lockfile_path).to eq(policyfile_lock_path)
63
+ expect(push_service.policyfile_lock_expanded_path).to eq(policyfile_lock_path)
62
64
  end
63
65
 
64
66
  it "has a storage configuration" do
@@ -74,7 +76,7 @@ describe ChefDK::PolicyfileServices::Push do
74
76
  let(:policyfile_lock_name) { "MyPolicy.lock.json" }
75
77
 
76
78
  it "infers the path to the lockfile from the policyfile location" do
77
- expect(push_service.lockfile_path).to eq(policyfile_lock_path)
79
+ expect(push_service.policyfile_lock_expanded_path).to eq(policyfile_lock_path)
78
80
  end
79
81
 
80
82
  end
@@ -90,7 +92,7 @@ describe ChefDK::PolicyfileServices::Push do
90
92
  context "when a lockfile is present" do
91
93
 
92
94
  before do
93
- File.open(policyfile_lock_path, "w+") { |f| f.print(lockfile_content) }
95
+ with_file(policyfile_lock_path) { |f| f.print(lockfile_content) }
94
96
  end
95
97
 
96
98
  context "and the lockfile has invalid JSON" do
@@ -175,7 +177,7 @@ E
175
177
 
176
178
  it "validates the lockfile, writes any updates, and uploads the cookbooks" do
177
179
  allow(File).to receive(:open).and_call_original
178
- expect(File).to receive(:open).with(policyfile_lock_path, "w+").and_yield(updated_lockfile_io)
180
+ expect(File).to receive(:open).with(policyfile_lock_path, "wb+").and_yield(updated_lockfile_io)
179
181
  expect(uploader).to receive(:upload)
180
182
 
181
183
  push_service.run
@@ -185,7 +187,7 @@ E
185
187
 
186
188
  before do
187
189
  allow(File).to receive(:open).and_call_original
188
- expect(File).to receive(:open).with(policyfile_lock_path, "w+").and_yield(updated_lockfile_io)
190
+ expect(File).to receive(:open).with(policyfile_lock_path, "wb+").and_yield(updated_lockfile_io)
189
191
  expect(uploader).to receive(:upload).and_raise("an error")
190
192
  end
191
193
 
@@ -0,0 +1,43 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'spec_helper'
19
+ require 'chef-dk/service_exception_inspectors/base'
20
+
21
+
22
+ describe ChefDK::ServiceExceptionInspectors::Base do
23
+
24
+ let(:message) { "something went wrong, oops" }
25
+
26
+ let(:exception) { StandardError.new(message) }
27
+
28
+ subject(:inspector) { described_class.new(exception) }
29
+
30
+ it "has an exception" do
31
+ expect(inspector.exception).to eq(exception)
32
+ end
33
+
34
+ it "gives the exception's message" do
35
+ expect(inspector.message).to eq(message)
36
+ end
37
+
38
+ it "has no extended error information" do
39
+ expect(inspector.extended_error_info).to eq("")
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,140 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'spec_helper'
19
+ require 'net/http'
20
+ require 'chef/monkey_patches/net_http'
21
+ require 'chef-dk/service_exception_inspectors/http'
22
+
23
+ describe ChefDK::ServiceExceptionInspectors::HTTP do
24
+
25
+ let(:message) { "something went wrong, oops" }
26
+
27
+ let(:response_body) { "" }
28
+
29
+ let(:request_headers) do
30
+ {
31
+ "content-type" => "application/json",
32
+ "accept" => "application/json"
33
+ }
34
+ end
35
+
36
+ let(:request_body) { "this is the request" }
37
+
38
+ let(:request) do
39
+ r = instance_double(Net::HTTP::Post,
40
+ method: "POST",
41
+ uri: nil,
42
+ path: "/organizations/chef-oss-dev/cookbooks",
43
+ body: request_body)
44
+ stub = allow(r).to(receive(:each_header))
45
+ request_headers.each { |k,v| stub.and_yield(k,v) }
46
+ r
47
+ end
48
+
49
+ let(:response_headers) do
50
+ {
51
+ "server" => "ngx_openresty",
52
+ "date" => "Wed, 29 Oct 2014 22:27:47 GMT"
53
+ }
54
+ end
55
+
56
+ let(:response) do
57
+ r = instance_double(Net::HTTPClientError,
58
+ code: "400",
59
+ message: "Bad Request",
60
+ body: response_body)
61
+ stub = allow(r).to(receive(:each_header))
62
+ response_headers.each { |k,v| stub.and_yield(k,v) }
63
+ r
64
+ end
65
+
66
+ let(:exception) do
67
+ Net::HTTPServerException.new(message, response).tap {|e| e.chef_rest_request = request }
68
+ end
69
+
70
+
71
+ subject(:inspector) { described_class.new(exception) }
72
+
73
+ it "has an exception" do
74
+ expect(inspector.exception).to eq(exception)
75
+ end
76
+
77
+ context "with a string response body" do
78
+
79
+ let(:response_body) { "No sir, I didn't like it" }
80
+
81
+ it "gives a customized exception message including the server response" do
82
+ expect(inspector.message).to eq("HTTP 400 Bad Request: No sir, I didn't like it")
83
+ end
84
+
85
+ end
86
+
87
+ context "with an empty response body" do
88
+
89
+ let(:response_body) { "" }
90
+
91
+ it "gives a customized exception message including the server response" do
92
+ expect(inspector.message).to eq("HTTP 400 Bad Request: (No explanation provided by server)")
93
+ end
94
+
95
+ end
96
+
97
+ context "with a JSON response body in the standard Chef Server format" do
98
+
99
+ let(:response_body) { %q[{"error":["Field 'name' invalid"]}] }
100
+
101
+ it "gives a customized exception message including the server response" do
102
+ expect(inspector.message).to eq("HTTP 400 Bad Request: Field 'name' invalid")
103
+ end
104
+
105
+ end
106
+
107
+ describe "showing the request and response in extended error info" do
108
+
109
+ let(:response_body) { "this is the response" }
110
+
111
+ it "shows the request in a format similar to HTTP messages" do
112
+ expected_request_string = <<-E
113
+ --- REQUEST DATA ----
114
+ POST /organizations/chef-oss-dev/cookbooks
115
+ content-type: application/json
116
+ accept: application/json
117
+
118
+ this is the request
119
+
120
+ E
121
+ expect(inspector.extended_error_info).to include(expected_request_string)
122
+ end
123
+
124
+ it "shows the response in a format similar to HTTP messages" do
125
+ expected_response_string = <<-E
126
+ --- RESPONSE DATA ---
127
+ 400 Bad Request
128
+ server: ngx_openresty
129
+ date: Wed, 29 Oct 2014 22:27:47 GMT
130
+
131
+
132
+ this is the response
133
+ E
134
+ expect(inspector.extended_error_info).to include(expected_response_string)
135
+ end
136
+
137
+ end
138
+
139
+ end
140
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-dk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel DeLeo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-10-07 00:00:00.000000000 Z
13
+ date: 2014-12-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mixlib-cli
@@ -176,6 +176,7 @@ files:
176
176
  - lib/chef-dk/command/generator_commands/cookbook_code_file.rb
177
177
  - lib/chef-dk/command/generator_commands/cookbook_file.rb
178
178
  - lib/chef-dk/command/generator_commands/lwrp.rb
179
+ - lib/chef-dk/command/generator_commands/policyfile.rb
179
180
  - lib/chef-dk/command/generator_commands/recipe.rb
180
181
  - lib/chef-dk/command/generator_commands/repo.rb
181
182
  - lib/chef-dk/command/generator_commands/template.rb
@@ -211,6 +212,10 @@ files:
211
212
  - lib/chef-dk/policyfile_lock.rb
212
213
  - lib/chef-dk/policyfile_services/install.rb
213
214
  - lib/chef-dk/policyfile_services/push.rb
215
+ - lib/chef-dk/service_exception_inspectors.rb
216
+ - lib/chef-dk/service_exception_inspectors/base.rb
217
+ - lib/chef-dk/service_exception_inspectors/http.rb
218
+ - lib/chef-dk/service_exceptions.rb
214
219
  - lib/chef-dk/shell_out.rb
215
220
  - lib/chef-dk/skeletons/code_generator/files/default/Berksfile
216
221
  - lib/chef-dk/skeletons/code_generator/files/default/chefignore
@@ -231,6 +236,7 @@ files:
231
236
  - lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb
232
237
  - lib/chef-dk/skeletons/code_generator/recipes/cookbook_file.rb
233
238
  - lib/chef-dk/skeletons/code_generator/recipes/lwrp.rb
239
+ - lib/chef-dk/skeletons/code_generator/recipes/policyfile.rb
234
240
  - lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
235
241
  - lib/chef-dk/skeletons/code_generator/recipes/repo.rb
236
242
  - lib/chef-dk/skeletons/code_generator/recipes/template.rb
@@ -239,6 +245,7 @@ files:
239
245
  - lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.gplv2.erb
240
246
  - lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.gplv3.erb
241
247
  - lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.mit.erb
248
+ - lib/chef-dk/skeletons/code_generator/templates/default/Policyfile.rb.erb
242
249
  - lib/chef-dk/skeletons/code_generator/templates/default/README.md.erb
243
250
  - lib/chef-dk/skeletons/code_generator/templates/default/attribute.rb.erb
244
251
  - lib/chef-dk/skeletons/code_generator/templates/default/cookbook_file.erb
@@ -269,6 +276,7 @@ files:
269
276
  - spec/unit/command/generator_commands/cookbook_file_spec.rb
270
277
  - spec/unit/command/generator_commands/cookbook_spec.rb
271
278
  - spec/unit/command/generator_commands/lwrp_spec.rb
279
+ - spec/unit/command/generator_commands/policyfile_spec.rb
272
280
  - spec/unit/command/generator_commands/recipe_spec.rb
273
281
  - spec/unit/command/generator_commands/repo_spec.rb
274
282
  - spec/unit/command/generator_commands/template_spec.rb
@@ -324,6 +332,19 @@ files:
324
332
  - spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/test-kitchen/verify_me
325
333
  - spec/unit/fixtures/eg_omnibus_dir/valid/embedded/bin/.keep
326
334
  - spec/unit/fixtures/example_app/Policyfile.rb
335
+ - spec/unit/fixtures/example_cookbook/.git/HEAD
336
+ - spec/unit/fixtures/example_cookbook/.git/config
337
+ - spec/unit/fixtures/example_cookbook/.git/description
338
+ - spec/unit/fixtures/example_cookbook/.git/hooks/applypatch-msg.sample
339
+ - spec/unit/fixtures/example_cookbook/.git/hooks/commit-msg.sample
340
+ - spec/unit/fixtures/example_cookbook/.git/hooks/post-update.sample
341
+ - spec/unit/fixtures/example_cookbook/.git/hooks/pre-applypatch.sample
342
+ - spec/unit/fixtures/example_cookbook/.git/hooks/pre-commit.sample
343
+ - spec/unit/fixtures/example_cookbook/.git/hooks/pre-push.sample
344
+ - spec/unit/fixtures/example_cookbook/.git/hooks/pre-rebase.sample
345
+ - spec/unit/fixtures/example_cookbook/.git/hooks/prepare-commit-msg.sample
346
+ - spec/unit/fixtures/example_cookbook/.git/hooks/update.sample
347
+ - spec/unit/fixtures/example_cookbook/.git/info/exclude
327
348
  - spec/unit/fixtures/example_cookbook/.gitignore
328
349
  - spec/unit/fixtures/example_cookbook/.kitchen.yml
329
350
  - spec/unit/fixtures/example_cookbook/Berksfile
@@ -366,6 +387,8 @@ files:
366
387
  - spec/unit/policyfile_lock_validation_spec.rb
367
388
  - spec/unit/policyfile_services/install_spec.rb
368
389
  - spec/unit/policyfile_services/push_spec.rb
390
+ - spec/unit/service_exception_inspectors/base_spec.rb
391
+ - spec/unit/service_exception_inspectors/http_spec.rb
369
392
  - spec/unit/shell_out_spec.rb
370
393
  homepage: http://www.getchef.com/
371
394
  licenses: []
@@ -407,6 +430,7 @@ test_files:
407
430
  - spec/unit/command/generator_commands/cookbook_file_spec.rb
408
431
  - spec/unit/command/generator_commands/cookbook_spec.rb
409
432
  - spec/unit/command/generator_commands/lwrp_spec.rb
433
+ - spec/unit/command/generator_commands/policyfile_spec.rb
410
434
  - spec/unit/command/generator_commands/recipe_spec.rb
411
435
  - spec/unit/command/generator_commands/repo_spec.rb
412
436
  - spec/unit/command/generator_commands/template_spec.rb
@@ -462,6 +486,19 @@ test_files:
462
486
  - spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/test-kitchen/verify_me
463
487
  - spec/unit/fixtures/eg_omnibus_dir/valid/embedded/bin/.keep
464
488
  - spec/unit/fixtures/example_app/Policyfile.rb
489
+ - spec/unit/fixtures/example_cookbook/.git/HEAD
490
+ - spec/unit/fixtures/example_cookbook/.git/config
491
+ - spec/unit/fixtures/example_cookbook/.git/description
492
+ - spec/unit/fixtures/example_cookbook/.git/hooks/applypatch-msg.sample
493
+ - spec/unit/fixtures/example_cookbook/.git/hooks/commit-msg.sample
494
+ - spec/unit/fixtures/example_cookbook/.git/hooks/post-update.sample
495
+ - spec/unit/fixtures/example_cookbook/.git/hooks/pre-applypatch.sample
496
+ - spec/unit/fixtures/example_cookbook/.git/hooks/pre-commit.sample
497
+ - spec/unit/fixtures/example_cookbook/.git/hooks/pre-push.sample
498
+ - spec/unit/fixtures/example_cookbook/.git/hooks/pre-rebase.sample
499
+ - spec/unit/fixtures/example_cookbook/.git/hooks/prepare-commit-msg.sample
500
+ - spec/unit/fixtures/example_cookbook/.git/hooks/update.sample
501
+ - spec/unit/fixtures/example_cookbook/.git/info/exclude
465
502
  - spec/unit/fixtures/example_cookbook/.gitignore
466
503
  - spec/unit/fixtures/example_cookbook/.kitchen.yml
467
504
  - spec/unit/fixtures/example_cookbook/Berksfile
@@ -504,5 +541,7 @@ test_files:
504
541
  - spec/unit/policyfile_lock_validation_spec.rb
505
542
  - spec/unit/policyfile_services/install_spec.rb
506
543
  - spec/unit/policyfile_services/push_spec.rb
544
+ - spec/unit/service_exception_inspectors/base_spec.rb
545
+ - spec/unit/service_exception_inspectors/http_spec.rb
507
546
  - spec/unit/shell_out_spec.rb
508
547
  has_rdoc: