chef 15.6.10-universal-mingw32 → 15.7.30-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +2 -2
  4. data/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +22 -5
  5. data/lib/chef/cookbook/cookbook_version_loader.rb +12 -6
  6. data/lib/chef/cookbook_loader.rb +55 -2
  7. data/lib/chef/cookbook_uploader.rb +2 -0
  8. data/lib/chef/cookbook_version.rb +17 -0
  9. data/lib/chef/dist.rb +3 -3
  10. data/lib/chef/event_loggers/windows_eventlog.rb +1 -1
  11. data/lib/chef/knife/bootstrap.rb +5 -0
  12. data/lib/chef/knife/bootstrap/templates/chef-full.erb +11 -11
  13. data/lib/chef/knife/cookbook_upload.rb +75 -45
  14. data/lib/chef/knife/core/bootstrap_context.rb +5 -5
  15. data/lib/chef/knife/core/windows_bootstrap_context.rb +1 -1
  16. data/lib/chef/knife/supermarket_install.rb +1 -1
  17. data/lib/chef/log/winevt.rb +1 -1
  18. data/lib/chef/mixin/openssl_helper.rb +21 -0
  19. data/lib/chef/monkey_patches/net_http.rb +0 -38
  20. data/lib/chef/provider/cron.rb +54 -9
  21. data/lib/chef/provider/cron/aix.rb +9 -2
  22. data/lib/chef/provider/launchd.rb +1 -1
  23. data/lib/chef/provider/user/aix.rb +1 -1
  24. data/lib/chef/provider/user/mac.rb +17 -22
  25. data/lib/chef/provider/windows_task.rb +2 -2
  26. data/lib/chef/resource/archive_file.rb +5 -2
  27. data/lib/chef/resource/cron.rb +29 -0
  28. data/lib/chef/resource/cron_d.rb +29 -0
  29. data/lib/chef/resource/openssl_x509_certificate.rb +32 -21
  30. data/lib/chef/resource/sudo.rb +13 -4
  31. data/lib/chef/version.rb +2 -2
  32. data/lib/chef/version_string.rb +3 -126
  33. data/spec/data/cookbooks/apache2/metadata.json +33 -0
  34. data/spec/data/cookbooks/java/metadata.json +33 -0
  35. data/spec/functional/event_loggers/windows_eventlog_spec.rb +5 -5
  36. data/spec/integration/knife/chef_fs_data_store_spec.rb +7 -2
  37. data/spec/integration/knife/cookbook_upload_spec.rb +10 -0
  38. data/spec/integration/knife/deps_spec.rb +11 -0
  39. data/spec/integration/knife/upload_spec.rb +115 -14
  40. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +7 -4
  41. data/spec/unit/knife/cookbook_upload_spec.rb +79 -18
  42. data/spec/unit/mixin/openssl_helper_spec.rb +42 -0
  43. data/spec/unit/provider/cron_spec.rb +127 -0
  44. data/spec/unit/provider/user/aix_spec.rb +2 -2
  45. metadata +8 -6
@@ -197,6 +197,7 @@ describe "knife upload", :workstation do
197
197
  end
198
198
 
199
199
  it "knife upload adds the new files" do
200
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
200
201
  knife("upload /").should_succeed <<~EOM
201
202
  Created /clients/y.json
202
203
  Updated /cookbooks/x
@@ -209,10 +210,14 @@ describe "knife upload", :workstation do
209
210
  Created /roles/y.json
210
211
  Created /users/y.json
211
212
  EOM
212
- knife("diff /").should_succeed ""
213
+ knife("diff --name-status /").should_succeed <<~EOM
214
+ D\t/cookbooks/x/metadata.json
215
+ D\t/cookbooks/y/metadata.json
216
+ EOM
213
217
  end
214
218
 
215
219
  it "knife upload --no-diff adds the new files" do
220
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
216
221
  knife("upload --no-diff /").should_succeed <<~EOM
217
222
  Created /clients/y.json
218
223
  Updated /cookbooks/x
@@ -225,7 +230,10 @@ describe "knife upload", :workstation do
225
230
  Created /roles/y.json
226
231
  Created /users/y.json
227
232
  EOM
228
- knife("diff --name-status /").should_succeed ""
233
+ knife("diff --name-status /").should_succeed <<~EOM
234
+ D\t/cookbooks/x/metadata.json
235
+ D\t/cookbooks/y/metadata.json
236
+ EOM
229
237
  end
230
238
  end
231
239
  end
@@ -289,8 +297,8 @@ describe "knife upload", :workstation do
289
297
  Created /data_bags/x
290
298
  Created /data_bags/x/y.json
291
299
  EOM
292
- knife("diff --name-status /data_bags").should_succeed <<EOM
293
- EOM
300
+ knife("diff --name-status /data_bags").should_succeed <<~EOM
301
+ EOM
294
302
  expect(Chef::JSONCompat.parse(knife("raw /data/x/y").stdout, create_additions: false).keys.sort).to eq(%w{foo id})
295
303
  end
296
304
 
@@ -446,11 +454,30 @@ EOM
446
454
  # upload of a file is designed not to work at present. Make sure that is the
447
455
  # case.
448
456
  when_the_chef_server "has a cookbook" do
449
-
450
457
  before do
451
458
  cookbook "x", "1.0.0", { "z.rb" => "" }
452
459
  end
453
460
 
461
+ when_the_repository "does not have metadata file" do
462
+ before do
463
+ file "cookbooks/x/y.rb", "hi"
464
+ end
465
+
466
+ it "raises MetadataNotFound exception" do
467
+ expect { knife("upload /cookbooks/x") }.to raise_error(Chef::Exceptions::MetadataNotFound)
468
+ end
469
+ end
470
+
471
+ when_the_repository "does not have valid metadata" do
472
+ before do
473
+ file "cookbooks/x/metadata.rb", cb_metadata(nil, "1.0.0")
474
+ end
475
+
476
+ it "raises exception for invalid metadata" do
477
+ expect { knife("upload /cookbooks/x") }.to raise_error(Chef::Exceptions::MetadataNotValid)
478
+ end
479
+ end
480
+
454
481
  when_the_repository "has a modified, extra and missing file for the cookbook" do
455
482
  before do
456
483
  file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0", "#modified")
@@ -462,20 +489,28 @@ EOM
462
489
  knife("upload /cookbooks/x/y.rb").should_fail "ERROR: /cookbooks/x cannot have a child created under it.\n"
463
490
  knife("upload --purge /cookbooks/x/z.rb").should_fail "ERROR: /cookbooks/x/z.rb cannot be deleted.\n"
464
491
  end
492
+
465
493
  # TODO this is a bit of an inconsistency: if we didn't specify --purge,
466
494
  # technically we shouldn't have deleted missing files. But ... cookbooks
467
495
  # are a special case.
468
496
  it "knife upload of the cookbook itself succeeds" do
497
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
469
498
  knife("upload /cookbooks/x").should_succeed <<~EOM
470
499
  Updated /cookbooks/x
471
500
  EOM
472
- knife("diff --name-status /cookbooks").should_succeed ""
501
+ knife("diff --name-status /cookbooks").should_succeed <<~EOM
502
+ D\t/cookbooks/x/metadata.json
503
+ EOM
473
504
  end
505
+
474
506
  it "knife upload --purge of the cookbook itself succeeds" do
507
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
475
508
  knife("upload /cookbooks/x").should_succeed <<~EOM
476
509
  Updated /cookbooks/x
477
510
  EOM
478
- knife("diff --name-status /cookbooks").should_succeed ""
511
+ knife("diff --name-status /cookbooks").should_succeed <<~EOM
512
+ D\t/cookbooks/x/metadata.json
513
+ EOM
479
514
  end
480
515
  end
481
516
  when_the_repository "has a missing file for the cookbook" do
@@ -485,10 +520,13 @@ EOM
485
520
  end
486
521
 
487
522
  it "knife upload of the cookbook succeeds" do
523
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
488
524
  knife("upload /cookbooks/x").should_succeed <<~EOM
489
525
  Updated /cookbooks/x
490
526
  EOM
491
- knife("diff --name-status /cookbooks").should_succeed ""
527
+ knife("diff --name-status /cookbooks").should_succeed <<~EOM
528
+ D\t/cookbooks/x/metadata.json
529
+ EOM
492
530
  end
493
531
  end
494
532
  when_the_repository "has an extra file for the cookbook" do
@@ -500,10 +538,13 @@ EOM
500
538
  end
501
539
 
502
540
  it "knife upload of the cookbook succeeds" do
541
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
503
542
  knife("upload /cookbooks/x").should_succeed <<~EOM
504
543
  Updated /cookbooks/x
505
544
  EOM
506
- knife("diff --name-status /cookbooks").should_succeed ""
545
+ knife("diff --name-status /cookbooks").should_succeed <<~EOM
546
+ D\t/cookbooks/x/metadata.json
547
+ EOM
507
548
  end
508
549
  end
509
550
 
@@ -513,6 +554,7 @@ EOM
513
554
  end
514
555
 
515
556
  it "knife upload --freeze freezes the cookbook" do
557
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
516
558
  knife("upload --freeze /cookbooks/x").should_succeed <<~EOM
517
559
  Updated /cookbooks/x
518
560
  EOM
@@ -535,9 +577,11 @@ EOM
535
577
  end
536
578
 
537
579
  it "knife upload fails to upload the frozen cookbook" do
580
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
538
581
  knife("upload /cookbooks/frozencook").should_fail "ERROR: /cookbooks failed to write: Cookbook frozencook is frozen\n"
539
582
  end
540
583
  it "knife upload --force uploads the frozen cookbook" do
584
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
541
585
  knife("upload --force /cookbooks/frozencook").should_succeed <<~EOM
542
586
  Updated /cookbooks/frozencook
543
587
  EOM
@@ -548,6 +592,7 @@ EOM
548
592
  when_the_repository "has a cookbook" do
549
593
  before do
550
594
  file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0")
595
+ file "cookbooks/x/metadata.json", { name: "x", version: "1.0.0" }
551
596
  file "cookbooks/x/onlyin1.0.0.rb", "old_text"
552
597
  end
553
598
 
@@ -558,14 +603,48 @@ EOM
558
603
  end
559
604
 
560
605
  it "knife upload /cookbooks/x uploads the local version" do
606
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
561
607
  knife("diff --name-status /cookbooks").should_succeed <<~EOM
562
608
  M\t/cookbooks/x/metadata.rb
563
609
  D\t/cookbooks/x/onlyin1.0.1.rb
610
+ A\t/cookbooks/x/metadata.json
564
611
  A\t/cookbooks/x/onlyin1.0.0.rb
565
612
  EOM
566
613
  knife("upload --purge /cookbooks/x").should_succeed <<~EOM
567
614
  Updated /cookbooks/x
568
615
  EOM
616
+ knife("diff --name-status /cookbooks").should_succeed <<~EOM
617
+ M\t/cookbooks/x/metadata.rb
618
+ D\t/cookbooks/x/onlyin1.0.1.rb
619
+ A\t/cookbooks/x/metadata.json
620
+ A\t/cookbooks/x/onlyin1.0.0.rb
621
+ EOM
622
+ end
623
+ end
624
+ end
625
+
626
+ when_the_repository "has a cookbook" do
627
+ before do
628
+ file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0")
629
+ file "cookbooks/x/onlyin1.0.0.rb", "old_text"
630
+ end
631
+
632
+ when_the_chef_server "has a later version for the cookbook" do
633
+ before do
634
+ cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" }
635
+ cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" }
636
+ end
637
+
638
+ it "knife upload /cookbooks/x uploads the local version and generates metadata.json from metadata.rb and uploads it." do
639
+ knife("diff --name-status /cookbooks").should_succeed <<~EOM
640
+ M\t/cookbooks/x/metadata.rb
641
+ D\t/cookbooks/x/onlyin1.0.1.rb
642
+ A\t/cookbooks/x/onlyin1.0.0.rb
643
+ EOM
644
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
645
+ knife("upload --purge /cookbooks/x").should_succeed <<~EOM
646
+ Updated /cookbooks/x
647
+ EOM
569
648
  knife("diff --name-status /cookbooks").should_succeed <<~EOM
570
649
  M\t/cookbooks/x/metadata.rb
571
650
  D\t/cookbooks/x/onlyin1.0.1.rb
@@ -580,11 +659,14 @@ EOM
580
659
  cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" }
581
660
  end
582
661
 
583
- it "knife upload /cookbooks/x uploads the local version" do
662
+ it "knife upload /cookbooks/x uploads the local version generates metadata.json and uploads it." do
663
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
584
664
  knife("upload --purge /cookbooks/x").should_succeed <<~EOM
585
665
  Updated /cookbooks/x
586
666
  EOM
587
- knife("diff --name-status /cookbooks").should_succeed ""
667
+ knife("diff --name-status /cookbooks").should_succeed <<~EOM
668
+ D\t/cookbooks/x/metadata.json
669
+ EOM
588
670
  end
589
671
  end
590
672
 
@@ -593,7 +675,8 @@ EOM
593
675
  cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" }
594
676
  end
595
677
 
596
- it "knife upload /cookbooks/x uploads the local version" do
678
+ it "knife upload /cookbooks/x uploads the local version and generates metadata.json before upload and uploads it." do
679
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
597
680
  knife("diff --name-status /cookbooks").should_succeed <<~EOM
598
681
  M\t/cookbooks/x/metadata.rb
599
682
  D\t/cookbooks/x/onlyin1.0.1.rb
@@ -616,10 +699,13 @@ EOM
616
699
  end
617
700
 
618
701
  it "knife upload /cookbooks/x uploads the new version" do
702
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
619
703
  knife("upload --purge /cookbooks/x").should_succeed <<~EOM
620
704
  Updated /cookbooks/x
621
705
  EOM
622
- knife("diff --name-status /cookbooks").should_succeed ""
706
+ knife("diff --name-status /cookbooks").should_succeed <<~EOM
707
+ D\t/cookbooks/x/metadata.json
708
+ EOM
623
709
  end
624
710
  end
625
711
  end
@@ -716,10 +802,13 @@ EOM
716
802
  file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0", "\nchef_version '~> 999.0'")
717
803
  end
718
804
  it "knife upload succeeds" do
805
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
719
806
  knife("upload /cookbooks/x").should_succeed <<~EOM
720
807
  Created /cookbooks/x
721
808
  EOM
722
- knife("diff --name-status /cookbooks").should_succeed ""
809
+ knife("diff --name-status /cookbooks").should_succeed <<~EOM
810
+ D\t/cookbooks/x/metadata.json
811
+ EOM
723
812
  end
724
813
  end
725
814
  end
@@ -864,6 +953,7 @@ EOM
864
953
  end
865
954
 
866
955
  it "knife upload adds the new files" do
956
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(3).times
867
957
  knife("upload /").should_succeed <<~EOM
868
958
  Created /clients/y.json
869
959
  Updated /cookbooks/x-1.0.0
@@ -1070,6 +1160,7 @@ EOM
1070
1160
  # technically we shouldn't have deleted missing files. But ... cookbooks
1071
1161
  # are a special case.
1072
1162
  it "knife upload of the cookbook itself succeeds" do
1163
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).once
1073
1164
  knife("upload /cookbooks/x-1.0.0").should_succeed <<~EOM
1074
1165
  Updated /cookbooks/x-1.0.0
1075
1166
  EOM
@@ -1077,6 +1168,7 @@ EOM
1077
1168
  end
1078
1169
 
1079
1170
  it "knife upload --purge of the cookbook itself succeeds" do
1171
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).once
1080
1172
  knife("upload /cookbooks/x-1.0.0").should_succeed <<~EOM
1081
1173
  Updated /cookbooks/x-1.0.0
1082
1174
  EOM
@@ -1090,6 +1182,7 @@ EOM
1090
1182
  end
1091
1183
 
1092
1184
  it "knife upload of the cookbook succeeds" do
1185
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).once
1093
1186
  knife("upload /cookbooks/x-1.0.0").should_succeed <<~EOM
1094
1187
  Updated /cookbooks/x-1.0.0
1095
1188
  EOM
@@ -1105,6 +1198,7 @@ EOM
1105
1198
  end
1106
1199
 
1107
1200
  it "knife upload of the cookbook succeeds" do
1201
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).once
1108
1202
  knife("upload /cookbooks/x-1.0.0").should_succeed <<~EOM
1109
1203
  Updated /cookbooks/x-1.0.0
1110
1204
  EOM
@@ -1126,6 +1220,7 @@ EOM
1126
1220
  end
1127
1221
 
1128
1222
  it "knife upload /cookbooks uploads the local version" do
1223
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).once
1129
1224
  knife("diff --name-status /cookbooks").should_succeed <<~EOM
1130
1225
  M\t/cookbooks/x-1.0.0/onlyin1.0.0.rb
1131
1226
  D\t/cookbooks/x-1.0.1
@@ -1144,6 +1239,7 @@ EOM
1144
1239
  cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" }
1145
1240
  end
1146
1241
  it "knife upload /cookbooks uploads the local version" do
1242
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).once
1147
1243
  knife("upload --purge /cookbooks").should_succeed <<~EOM
1148
1244
  Updated /cookbooks/x-1.0.0
1149
1245
  Deleted extra entry /cookbooks/x-0.9.9 (purge is on)
@@ -1158,6 +1254,7 @@ EOM
1158
1254
  end
1159
1255
 
1160
1256
  it "knife upload /cookbooks/x uploads the local version" do
1257
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).once
1161
1258
  knife("diff --name-status /cookbooks").should_succeed <<~EOM
1162
1259
  D\t/cookbooks/x-1.0.1
1163
1260
  A\t/cookbooks/x-1.0.0
@@ -1176,6 +1273,7 @@ EOM
1176
1273
  end
1177
1274
 
1178
1275
  it "knife upload /cookbooks/x uploads the new version" do
1276
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).once
1179
1277
  knife("upload --purge /cookbooks").should_succeed <<~EOM
1180
1278
  Created /cookbooks/x-1.0.0
1181
1279
  Deleted extra entry /cookbooks/x-0.9.9 (purge is on)
@@ -1250,6 +1348,7 @@ EOM
1250
1348
  file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0", "\nchef_version '~> 999.0'")
1251
1349
  end
1252
1350
  it "knife upload succeeds" do
1351
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).once
1253
1352
  knife("upload /cookbooks/x-1.0.0").should_succeed <<~EOM
1254
1353
  Created /cookbooks/x-1.0.0
1255
1354
  EOM
@@ -1313,6 +1412,7 @@ EOM
1313
1412
  end
1314
1413
 
1315
1414
  it "knife upload / uploads everything" do
1415
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
1316
1416
  knife("upload /").should_succeed <<~EOM
1317
1417
  Updated /acls/groups/blah.json
1318
1418
  Created /clients/x.json
@@ -1420,6 +1520,7 @@ EOM
1420
1520
  end
1421
1521
 
1422
1522
  it "knife upload updates everything" do
1523
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/).at_least(2).times
1423
1524
  knife("upload /").should_succeed <<~EOM
1424
1525
  Updated /acls/groups/blah.json
1425
1526
  Updated /clients/x.json
@@ -124,8 +124,9 @@ describe Chef::Cookbook::CookbookVersionLoader do
124
124
  expect { cookbook_loader.load! }.to raise_error(Chef::Exceptions::CookbookNotFoundInRepo)
125
125
  end
126
126
 
127
- it "skips the cookbook when called with #load" do
128
- expect { cookbook_loader.load }.to_not raise_error
127
+ it "gives deprecation warning called with #load and raise error for Cookbook not found" do
128
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/)
129
+ expect { cookbook_loader.load }.to raise_error(Chef::Exceptions::CookbookNotFoundInRepo)
129
130
  end
130
131
 
131
132
  end
@@ -148,7 +149,8 @@ describe Chef::Cookbook::CookbookVersionLoader do
148
149
  expect { cookbook_loader.load! }.to raise_error("THIS METADATA HAS A BUG")
149
150
  end
150
151
 
151
- it "raises an error when called with #load" do
152
+ it "gives deprecation warning to us load! when called with #load and raises error" do
153
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/)
152
154
  expect { cookbook_loader.load }.to raise_error("THIS METADATA HAS A BUG")
153
155
  end
154
156
 
@@ -180,7 +182,8 @@ describe Chef::Cookbook::CookbookVersionLoader do
180
182
  expect { cookbook_loader.load! }.to raise_error(Chef::Exceptions::MetadataNotValid, error_message)
181
183
  end
182
184
 
183
- it "raises an error when called with #load" do
185
+ it "gives deprecation warning to use load! method when called with #load and raises error for invalid metadata" do
186
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/)
184
187
  expect { cookbook_loader.load }.to raise_error(Chef::Exceptions::MetadataNotValid, error_message)
185
188
  end
186
189
 
@@ -23,7 +23,12 @@ require "chef/cookbook_uploader"
23
23
  require "timeout"
24
24
 
25
25
  describe Chef::Knife::CookbookUpload do
26
- let(:cookbook) { Chef::CookbookVersion.new("test_cookbook", "/tmp/blah.txt") }
26
+ let(:cookbook) do
27
+ cookbook = Chef::CookbookVersion.new("test_cookbook", "/tmp/blah")
28
+ allow(cookbook).to receive(:has_metadata_file?).and_return(true)
29
+ allow(cookbook.metadata).to receive(:name).and_return(cookbook.name)
30
+ cookbook
31
+ end
27
32
 
28
33
  let(:cookbooks_by_name) do
29
34
  { cookbook.name => cookbook }
@@ -33,6 +38,9 @@ describe Chef::Knife::CookbookUpload do
33
38
  cookbook_loader = cookbooks_by_name.dup
34
39
  allow(cookbook_loader).to receive(:merged_cookbooks).and_return([])
35
40
  allow(cookbook_loader).to receive(:load_cookbooks).and_return(cookbook_loader)
41
+ allow(cookbook_loader).to receive(:compile_metadata).and_return(nil)
42
+ allow(cookbook_loader).to receive(:freeze_versions).and_return(nil)
43
+ allow(cookbook_loader).to receive(:unlink!).and_return(nil)
36
44
  cookbook_loader
37
45
  end
38
46
 
@@ -52,6 +60,7 @@ describe Chef::Knife::CookbookUpload do
52
60
 
53
61
  before(:each) do
54
62
  allow(Chef::CookbookLoader).to receive(:new).and_return(cookbook_loader)
63
+ allow(Chef::CookbookLoader).to receive(:copy_to_tmp_dir_from_array).and_return(cookbook_loader)
55
64
  end
56
65
 
57
66
  describe "with --concurrency" do
@@ -61,6 +70,7 @@ describe Chef::Knife::CookbookUpload do
61
70
  test_cookbook = Chef::CookbookVersion.new("test_cookbook", "/tmp/blah")
62
71
  allow(cookbook_loader).to receive(:each).and_yield("test_cookbook", test_cookbook)
63
72
  allow(cookbook_loader).to receive(:cookbook_names).and_return(["test_cookbook"])
73
+ allow(cookbook_loader).to receive(:tmp_working_dir_path).and_return("/tmp/blah")
64
74
  expect(Chef::CookbookUploader).to receive(:new)
65
75
  .with( kind_of(Array), { force: nil, concurrency: 3 })
66
76
  .and_return(double("Chef::CookbookUploader", upload_cookbooks: true))
@@ -81,6 +91,34 @@ describe Chef::Knife::CookbookUpload do
81
91
  expect { knife.run }.to raise_error(SystemExit)
82
92
  end
83
93
 
94
+ describe "when specifying cookbook without metadata.rb or metadata.json" do
95
+ let(:name_args) { ["test_cookbook1"] }
96
+ let(:cookbook) do
97
+ cookbook = Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah")
98
+ allow(cookbook).to receive(:has_metadata_file?).and_return(false)
99
+ cookbook
100
+ end
101
+
102
+ it "should upload the cookbook" do
103
+ expect { knife.run }.to raise_error(Chef::Exceptions::MetadataNotFound)
104
+ end
105
+ end
106
+
107
+ describe "when name attribute in metadata not set" do
108
+ let(:name_args) { ["test_cookbook1"] }
109
+
110
+ let(:cookbook) do
111
+ cookbook = Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah")
112
+ allow(cookbook).to receive(:has_metadata_file?).and_return(true)
113
+ allow(cookbook.metadata).to receive(:name).and_return(nil)
114
+ cookbook
115
+ end
116
+
117
+ it "should upload the cookbook" do
118
+ expect { knife.run }.to raise_error(Chef::Exceptions::MetadataNotValid)
119
+ end
120
+ end
121
+
84
122
  describe "when specifying a cookbook name" do
85
123
  it "should upload the cookbook" do
86
124
  expect(knife).to receive(:upload).once
@@ -105,12 +143,15 @@ describe Chef::Knife::CookbookUpload do
105
143
  describe "when specifying a cookbook name among many" do
106
144
  let(:name_args) { ["test_cookbook1"] }
107
145
 
146
+ let(:cookbook) do
147
+ cookbook = Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah")
148
+ allow(cookbook).to receive(:has_metadata_file?).and_return(true)
149
+ allow(cookbook.metadata).to receive(:name).and_return(cookbook.name)
150
+ cookbook
151
+ end
152
+
108
153
  let(:cookbooks_by_name) do
109
- {
110
- "test_cookbook1" => Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah"),
111
- "test_cookbook2" => Chef::CookbookVersion.new("test_cookbook2", "/tmp/blah"),
112
- "test_cookbook3" => Chef::CookbookVersion.new("test_cookbook3", "/tmp/blah"),
113
- }
154
+ { cookbook.name => cookbook }
114
155
  end
115
156
 
116
157
  it "should read only one cookbook" do
@@ -119,7 +160,7 @@ describe Chef::Knife::CookbookUpload do
119
160
  end
120
161
 
121
162
  it "should not read all cookbooks" do
122
- expect(cookbook_loader).not_to receive(:load_cookbooks)
163
+ expect(cookbook_loader).to receive(:load_cookbooks)
123
164
  knife.run
124
165
  end
125
166
 
@@ -133,17 +174,18 @@ describe Chef::Knife::CookbookUpload do
133
174
  describe "when specifying a cookbook name with dependencies" do
134
175
  let(:name_args) { ["test_cookbook2"] }
135
176
 
136
- let(:cookbooks_by_name) do
137
- { "test_cookbook1" => test_cookbook1,
138
- "test_cookbook2" => test_cookbook2,
139
- "test_cookbook3" => test_cookbook3 }
177
+ let(:test_cookbook1) do
178
+ cookbook = Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah")
179
+ allow(cookbook).to receive(:has_metadata_file?).and_return(true)
180
+ allow(cookbook.metadata).to receive(:name).and_return(cookbook.name)
181
+ cookbook
140
182
  end
141
183
 
142
- let(:test_cookbook1) { Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah") }
143
-
144
184
  let(:test_cookbook2) do
145
185
  c = Chef::CookbookVersion.new("test_cookbook2")
146
186
  c.metadata.depends("test_cookbook3")
187
+ allow(c).to receive(:has_metadata_file?).and_return(true)
188
+ allow(c.metadata).to receive(:name).and_return(c.name)
147
189
  c
148
190
  end
149
191
 
@@ -151,9 +193,17 @@ describe Chef::Knife::CookbookUpload do
151
193
  c = Chef::CookbookVersion.new("test_cookbook3")
152
194
  c.metadata.depends("test_cookbook1")
153
195
  c.metadata.depends("test_cookbook2")
196
+ allow(c).to receive(:has_metadata_file?).and_return(true)
197
+ allow(c.metadata).to receive(:name).and_return(c.name)
154
198
  c
155
199
  end
156
200
 
201
+ let(:cookbooks_by_name) do
202
+ { "test_cookbook1" => test_cookbook1,
203
+ "test_cookbook2" => test_cookbook2,
204
+ "test_cookbook3" => test_cookbook3 }
205
+ end
206
+
157
207
  it "should upload all dependencies once" do
158
208
  knife.config[:depends] = true
159
209
  allow(knife).to receive(:cookbook_names).and_return(%w{test_cookbook1 test_cookbook2 test_cookbook3})
@@ -182,7 +232,6 @@ describe Chef::Knife::CookbookUpload do
182
232
 
183
233
  it "should exit and not upload the cookbook" do
184
234
  expect(cookbook_loader).to receive(:[]).once.with("test_cookbook")
185
- expect(cookbook_loader).not_to receive(:load_cookbooks)
186
235
  expect(cookbook_uploader).not_to receive(:upload_cookbooks)
187
236
  expect { knife.run }.to raise_error(SystemExit)
188
237
  end
@@ -214,7 +263,7 @@ describe Chef::Knife::CookbookUpload do
214
263
 
215
264
  it "should freeze the version of the cookbooks if --freeze is specified" do
216
265
  knife.config[:freeze] = true
217
- expect(cookbook).to receive(:freeze_version).once
266
+ expect(cookbook_loader).to receive(:freeze_versions).once
218
267
  knife.run
219
268
  end
220
269
 
@@ -224,10 +273,22 @@ describe Chef::Knife::CookbookUpload do
224
273
  end
225
274
 
226
275
  context "when cookbooks exist in the cookbook path" do
276
+ let(:test_cookbook1) do
277
+ cookbook = Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah")
278
+ allow(cookbook).to receive(:has_metadata_file?).and_return(true)
279
+ allow(cookbook.metadata).to receive(:name).and_return(cookbook.name)
280
+ cookbook
281
+ end
282
+
283
+ let(:test_cookbook2) do
284
+ cookbook = Chef::CookbookVersion.new("test_cookbook2", "/tmp/blah")
285
+ allow(cookbook).to receive(:has_metadata_file?).and_return(true)
286
+ allow(cookbook.metadata).to receive(:name).and_return(cookbook.name)
287
+ cookbook
288
+ end
289
+
227
290
  before(:each) do
228
- @test_cookbook1 = Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah")
229
- @test_cookbook2 = Chef::CookbookVersion.new("test_cookbook2", "/tmp/blah")
230
- allow(cookbook_loader).to receive(:each).and_yield("test_cookbook1", @test_cookbook1).and_yield("test_cookbook2", @test_cookbook2)
291
+ allow(cookbook_loader).to receive(:each).and_yield("test_cookbook1", test_cookbook1).and_yield("test_cookbook2", test_cookbook2)
231
292
  allow(cookbook_loader).to receive(:cookbook_names).and_return(%w{test_cookbook1 test_cookbook2})
232
293
  end
233
294