chef 12.4.0 → 12.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef/api_client.rb +31 -129
  3. data/lib/chef/api_client_v1.rb +325 -0
  4. data/lib/chef/chef_class.rb +15 -7
  5. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +2 -2
  6. data/lib/chef/dsl/resources.rb +6 -4
  7. data/lib/chef/exceptions.rb +2 -2
  8. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +2 -1
  9. data/lib/chef/knife/bootstrap/templates/chef-full.erb +4 -4
  10. data/lib/chef/knife/client_bulk_delete.rb +2 -2
  11. data/lib/chef/knife/client_create.rb +4 -4
  12. data/lib/chef/knife/client_delete.rb +3 -3
  13. data/lib/chef/knife/client_edit.rb +10 -2
  14. data/lib/chef/knife/client_list.rb +2 -2
  15. data/lib/chef/knife/client_reregister.rb +2 -2
  16. data/lib/chef/knife/client_show.rb +2 -2
  17. data/lib/chef/knife/osc_user_create.rb +3 -3
  18. data/lib/chef/knife/osc_user_delete.rb +2 -2
  19. data/lib/chef/knife/osc_user_edit.rb +3 -3
  20. data/lib/chef/knife/osc_user_list.rb +2 -2
  21. data/lib/chef/knife/osc_user_reregister.rb +2 -2
  22. data/lib/chef/knife/osc_user_show.rb +2 -2
  23. data/lib/chef/knife/user_create.rb +3 -3
  24. data/lib/chef/knife/user_delete.rb +4 -4
  25. data/lib/chef/knife/user_edit.rb +3 -3
  26. data/lib/chef/knife/user_list.rb +2 -2
  27. data/lib/chef/knife/user_reregister.rb +2 -2
  28. data/lib/chef/knife/user_show.rb +2 -2
  29. data/lib/chef/node_map.rb +14 -18
  30. data/lib/chef/platform/handler_map.rb +45 -0
  31. data/lib/chef/platform/priority_map.rb +19 -32
  32. data/lib/chef/platform/provider_handler_map.rb +29 -0
  33. data/lib/chef/platform/provider_mapping.rb +3 -2
  34. data/lib/chef/platform/resource_handler_map.rb +29 -0
  35. data/lib/chef/platform/resource_priority_map.rb +0 -6
  36. data/lib/chef/provider.rb +1 -1
  37. data/lib/chef/provider/dsc_resource.rb +2 -2
  38. data/lib/chef/provider/dsc_script.rb +1 -1
  39. data/lib/chef/provider/mount/aix.rb +1 -1
  40. data/lib/chef/provider/package.rb +0 -31
  41. data/lib/chef/provider/package/aix.rb +1 -0
  42. data/lib/chef/provider/package/apt.rb +1 -0
  43. data/lib/chef/provider/package/homebrew.rb +1 -0
  44. data/lib/chef/provider/package/ips.rb +1 -0
  45. data/lib/chef/provider/package/macports.rb +1 -0
  46. data/lib/chef/provider/package/openbsd.rb +1 -0
  47. data/lib/chef/provider/package/pacman.rb +1 -0
  48. data/lib/chef/provider/package/paludis.rb +1 -0
  49. data/lib/chef/provider/package/portage.rb +2 -0
  50. data/lib/chef/provider/package/smartos.rb +1 -0
  51. data/lib/chef/provider/package/solaris.rb +2 -0
  52. data/lib/chef/provider/package/yum.rb +1 -0
  53. data/lib/chef/provider/package/zypper.rb +1 -0
  54. data/lib/chef/provider/service.rb +4 -22
  55. data/lib/chef/provider/service/debian.rb +2 -0
  56. data/lib/chef/provider/service/insserv.rb +2 -0
  57. data/lib/chef/provider/service/invokercd.rb +2 -0
  58. data/lib/chef/provider/service/openbsd.rb +1 -1
  59. data/lib/chef/provider/service/redhat.rb +2 -0
  60. data/lib/chef/provider/service/upstart.rb +3 -0
  61. data/lib/chef/provider_resolver.rb +59 -53
  62. data/lib/chef/resource.rb +22 -73
  63. data/lib/chef/resource/dsc_script.rb +1 -1
  64. data/lib/chef/resource/ips_package.rb +1 -0
  65. data/lib/chef/resource/mount.rb +8 -0
  66. data/lib/chef/resource/openbsd_package.rb +0 -11
  67. data/lib/chef/resource/solaris_package.rb +1 -4
  68. data/lib/chef/resource_resolver.rb +54 -26
  69. data/lib/chef/run_list/versioned_recipe_list.rb +6 -5
  70. data/lib/chef/user.rb +52 -188
  71. data/lib/chef/user_v1.rb +335 -0
  72. data/lib/chef/version.rb +1 -1
  73. data/spec/data/trusted_certs/opscode.pem +53 -56
  74. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +1 -1
  75. data/spec/functional/resource/package_spec.rb +0 -2
  76. data/spec/integration/recipes/recipe_dsl_spec.rb +661 -126
  77. data/spec/spec_helper.rb +19 -13
  78. data/spec/support/shared/unit/api_versioning.rb +2 -2
  79. data/spec/unit/api_client_spec.rb +22 -201
  80. data/spec/unit/api_client_v1_spec.rb +457 -0
  81. data/spec/unit/knife/client_bulk_delete_spec.rb +4 -4
  82. data/spec/unit/knife/client_create_spec.rb +1 -1
  83. data/spec/unit/knife/client_delete_spec.rb +3 -3
  84. data/spec/unit/knife/client_edit_spec.rb +14 -1
  85. data/spec/unit/knife/client_list_spec.rb +1 -1
  86. data/spec/unit/knife/client_reregister_spec.rb +2 -2
  87. data/spec/unit/knife/client_show_spec.rb +2 -2
  88. data/spec/unit/knife/osc_user_create_spec.rb +5 -5
  89. data/spec/unit/knife/osc_user_delete_spec.rb +1 -1
  90. data/spec/unit/knife/osc_user_edit_spec.rb +1 -1
  91. data/spec/unit/knife/osc_user_list_spec.rb +1 -1
  92. data/spec/unit/knife/osc_user_reregister_spec.rb +1 -1
  93. data/spec/unit/knife/osc_user_show_spec.rb +1 -1
  94. data/spec/unit/knife/user_create_spec.rb +1 -1
  95. data/spec/unit/knife/user_delete_spec.rb +2 -2
  96. data/spec/unit/knife/user_edit_spec.rb +2 -2
  97. data/spec/unit/knife/user_list_spec.rb +1 -1
  98. data/spec/unit/knife/user_reregister_spec.rb +1 -1
  99. data/spec/unit/knife/user_show_spec.rb +2 -2
  100. data/spec/unit/lwrp_spec.rb +146 -134
  101. data/spec/unit/node_map_spec.rb +12 -0
  102. data/spec/unit/platform_spec.rb +1 -1
  103. data/spec/unit/provider/deploy_spec.rb +1 -1
  104. data/spec/unit/provider/dsc_resource_spec.rb +3 -3
  105. data/spec/unit/provider/dsc_script_spec.rb +2 -2
  106. data/spec/unit/provider_resolver_spec.rb +170 -135
  107. data/spec/unit/recipe_spec.rb +3 -3
  108. data/spec/unit/resource/breakpoint_spec.rb +1 -1
  109. data/spec/unit/resource/cron_spec.rb +1 -1
  110. data/spec/unit/resource/directory_spec.rb +1 -1
  111. data/spec/unit/resource/dsc_resource_spec.rb +1 -1
  112. data/spec/unit/resource/dsc_script_spec.rb +2 -2
  113. data/spec/unit/resource/env_spec.rb +1 -1
  114. data/spec/unit/resource/erl_call_spec.rb +1 -1
  115. data/spec/unit/resource/file_spec.rb +1 -1
  116. data/spec/unit/resource/group_spec.rb +1 -1
  117. data/spec/unit/resource/link_spec.rb +1 -1
  118. data/spec/unit/resource/mdadm_spec.rb +1 -1
  119. data/spec/unit/resource/mount_spec.rb +1 -1
  120. data/spec/unit/resource/ohai_spec.rb +1 -1
  121. data/spec/unit/resource/registry_key_spec.rb +1 -1
  122. data/spec/unit/resource/route_spec.rb +1 -1
  123. data/spec/unit/resource/ruby_block_spec.rb +3 -3
  124. data/spec/unit/resource/user_spec.rb +1 -1
  125. data/spec/unit/resource/windows_service_spec.rb +1 -1
  126. data/spec/unit/resource_resolver_spec.rb +8 -4
  127. data/spec/unit/resource_spec.rb +89 -3
  128. data/spec/unit/run_list/versioned_recipe_list_spec.rb +115 -48
  129. data/spec/unit/user_spec.rb +97 -405
  130. data/spec/unit/user_v1_spec.rb +584 -0
  131. metadata +11 -6
  132. data/lib/chef/osc_user.rb +0 -194
  133. data/spec/unit/osc_user_spec.rb +0 -276
@@ -409,8 +409,8 @@ describe Chef::Recipe do
409
409
  end
410
410
 
411
411
  it "does not copy the action from the first resource" do
412
- expect(original_resource.action).to eq(:score)
413
- expect(duplicated_resource.action).to eq(:nothing)
412
+ expect(original_resource.action).to eq([:score])
413
+ expect(duplicated_resource.action).to eq([:nothing])
414
414
  end
415
415
 
416
416
  it "does not copy the source location of the first resource" do
@@ -505,7 +505,7 @@ describe Chef::Recipe do
505
505
  recipe.from_file(File.join(CHEF_SPEC_DATA, "recipes", "test.rb"))
506
506
  res = recipe.resources(:file => "/etc/nsswitch.conf")
507
507
  expect(res.name).to eql("/etc/nsswitch.conf")
508
- expect(res.action).to eql(:create)
508
+ expect(res.action).to eql([:create])
509
509
  expect(res.owner).to eql("root")
510
510
  expect(res.group).to eql("root")
511
511
  expect(res.mode).to eql(0644)
@@ -37,7 +37,7 @@ describe Chef::Resource::Breakpoint do
37
37
  end
38
38
 
39
39
  it "defaults to the break action" do
40
- expect(@breakpoint.action).to eq(:break)
40
+ expect(@breakpoint.action).to eq([:break])
41
41
  end
42
42
 
43
43
  it "names itself after the line number of the file where it's created" do
@@ -35,7 +35,7 @@ describe Chef::Resource::Cron do
35
35
  end
36
36
 
37
37
  it "should have a default action of 'create'" do
38
- expect(@resource.action).to eql(:create)
38
+ expect(@resource.action).to eql([:create])
39
39
  end
40
40
 
41
41
  it "should accept create or delete for action" do
@@ -35,7 +35,7 @@ describe Chef::Resource::Directory do
35
35
  end
36
36
 
37
37
  it "should have a default action of 'create'" do
38
- expect(@resource.action).to eql(:create)
38
+ expect(@resource.action).to eql([:create])
39
39
  end
40
40
 
41
41
  it "should accept create or delete for action" do
@@ -35,7 +35,7 @@ describe Chef::Resource::DscResource do
35
35
  }
36
36
 
37
37
  it "has a default action of `:run`" do
38
- expect(dsc_test_resource.action).to eq(:run)
38
+ expect(dsc_test_resource.action).to eq([:run])
39
39
  end
40
40
 
41
41
  it "has an allowed_actions attribute with only the `:run` and `:nothing` attributes" do
@@ -29,7 +29,7 @@ describe Chef::Resource::DscScript do
29
29
  Chef::RunContext.new(node, {}, empty_events)
30
30
  }
31
31
  let(:dsc_test_resource) {
32
- Chef::Resource::DscScript.new(dsc_test_resource_name, dsc_test_run_context)
32
+ Chef::Resource::DscScript.new(dsc_test_resource_name, dsc_test_run_context)
33
33
  }
34
34
  let(:configuration_code) {'echo "This is supposed to create a configuration document."'}
35
35
  let(:configuration_path) {'c:/myconfigs/formatc.ps1'}
@@ -38,7 +38,7 @@ describe Chef::Resource::DscScript do
38
38
  let(:configuration_data_script) { 'c:/myconfigs/data/safedata.psd1' }
39
39
 
40
40
  it "has a default action of `:run`" do
41
- expect(dsc_test_resource.action).to eq(:run)
41
+ expect(dsc_test_resource.action).to eq([:run])
42
42
  end
43
43
 
44
44
  it "has an allowed_actions attribute with only the `:run` and `:nothing` attributes" do
@@ -35,7 +35,7 @@ describe Chef::Resource::Env do
35
35
  end
36
36
 
37
37
  it "should have a default action of 'create'" do
38
- expect(@resource.action).to eql(:create)
38
+ expect(@resource.action).to eql([:create])
39
39
  end
40
40
 
41
41
  { :create => false, :delete => false, :modify => false, :flibber => true }.each do |action,bad_value|
@@ -35,7 +35,7 @@ describe Chef::Resource::ErlCall do
35
35
  end
36
36
 
37
37
  it "should have a default action of run" do
38
- expect(@resource.action).to eql(:run)
38
+ expect(@resource.action).to eql([:run])
39
39
  end
40
40
 
41
41
  it "should accept run as an action" do
@@ -29,7 +29,7 @@ describe Chef::Resource::File do
29
29
  end
30
30
 
31
31
  it "should have a default action of 'create'" do
32
- expect(@resource.action).to eql(:create)
32
+ expect(@resource.action).to eql([:create])
33
33
  end
34
34
 
35
35
  it "should have a default content of nil" do
@@ -50,7 +50,7 @@ describe Chef::Resource::Group, "initialize" do
50
50
  end
51
51
 
52
52
  it "should set action to :create" do
53
- expect(@resource.action).to eql(:create)
53
+ expect(@resource.action).to eql([:create])
54
54
  end
55
55
 
56
56
  %w{create remove modify manage}.each do |action|
@@ -36,7 +36,7 @@ describe Chef::Resource::Link do
36
36
  end
37
37
 
38
38
  it "should have a default action of 'create'" do
39
- expect(@resource.action).to eql(:create)
39
+ expect(@resource.action).to eql([:create])
40
40
  end
41
41
 
42
42
  { :create => false, :delete => false, :blues => true }.each do |action,bad_value|
@@ -35,7 +35,7 @@ describe Chef::Resource::Mdadm do
35
35
  end
36
36
 
37
37
  it "should have a default action of create" do
38
- expect(@resource.action).to eql(:create)
38
+ expect(@resource.action).to eql([:create])
39
39
  end
40
40
 
41
41
  it "should accept create, assemble, stop as actions" do
@@ -38,7 +38,7 @@ describe Chef::Resource::Mount do
38
38
  end
39
39
 
40
40
  it "should have a default action of mount" do
41
- expect(@resource.action).to eql(:mount)
41
+ expect(@resource.action).to eql([:mount])
42
42
  end
43
43
 
44
44
  it "should accept mount, umount and remount as actions" do
@@ -34,7 +34,7 @@ describe Chef::Resource::Ohai do
34
34
  end
35
35
 
36
36
  it "should have a default action of create" do
37
- expect(@resource.action).to eql(:reload)
37
+ expect(@resource.action).to eql([:reload])
38
38
  end
39
39
 
40
40
  it "should allow you to set the plugin attribute" do
@@ -45,7 +45,7 @@ describe Chef::Resource::RegistryKey, "initialize" do
45
45
  end
46
46
 
47
47
  it "should set action to :create" do
48
- expect(@resource.action).to eql(:create)
48
+ expect(@resource.action).to eql([:create])
49
49
  end
50
50
 
51
51
  %w{create create_if_missing delete delete_key}.each do |action|
@@ -35,7 +35,7 @@ describe Chef::Resource::Route do
35
35
  end
36
36
 
37
37
  it "should have a default action of 'add'" do
38
- expect(@resource.action).to eql(:add)
38
+ expect(@resource.action).to eql([:add])
39
39
  end
40
40
 
41
41
  it "should accept add or delete for action" do
@@ -30,8 +30,8 @@ describe Chef::Resource::RubyBlock do
30
30
  expect(@resource).to be_a_kind_of(Chef::Resource::RubyBlock)
31
31
  end
32
32
 
33
- it "should have a default action of 'create'" do
34
- expect(@resource.action).to eql(:run)
33
+ it "should have a default action of 'run'" do
34
+ expect(@resource.action).to eql([:run])
35
35
  end
36
36
 
37
37
  it "should have a resource name of :ruby_block" do
@@ -46,7 +46,7 @@ describe Chef::Resource::RubyBlock do
46
46
 
47
47
  it "allows the action to be 'create'" do
48
48
  @resource.action :create
49
- expect(@resource.action).to eq(:create)
49
+ expect(@resource.action).to eq([:create])
50
50
  end
51
51
 
52
52
  describe "when it has been initialized with block code" do
@@ -43,7 +43,7 @@ describe Chef::Resource::User, "initialize" do
43
43
  end
44
44
 
45
45
  it "should set action to :create" do
46
- expect(@resource.action).to eql(:create)
46
+ expect(@resource.action).to eql([:create])
47
47
  end
48
48
 
49
49
  it "should set supports[:manage_home] to false" do
@@ -44,6 +44,6 @@ describe Chef::Resource::WindowsService, "initialize" do
44
44
 
45
45
  it "allows the action to be 'configure_startup'" do
46
46
  resource.action :configure_startup
47
- expect(resource.action).to eq(:configure_startup)
47
+ expect(resource.action).to eq([:configure_startup])
48
48
  end
49
49
  end
@@ -31,19 +31,23 @@ describe Chef::ResourceResolver do
31
31
 
32
32
  context 'instance methods' do
33
33
  let(:resolver) do
34
- described_class.new(Chef::Node.new, 'execute[echo]')
34
+ described_class.new(Chef::Node.new, 'execute')
35
35
  end
36
36
 
37
37
  it '#resolve' do
38
- expect(resolver.resolve).to be_nil
38
+ expect(resolver.resolve).to eq Chef::Resource::Execute
39
39
  end
40
40
 
41
41
  it '#list' do
42
- expect(resolver.list).to be_empty
42
+ expect(resolver.list).to eq [ Chef::Resource::Execute ]
43
43
  end
44
44
 
45
- it '#provided_by?' do
45
+ it '#provided_by? returns true when resource class is in the list' do
46
46
  expect(resolver.provided_by?(Chef::Resource::Execute)).to be_truthy
47
47
  end
48
+
49
+ it '#provided_by? returns false when resource class is not in the list' do
50
+ expect(resolver.provided_by?(Chef::Resource::File)).to be_falsey
51
+ end
48
52
  end
49
53
  end
@@ -810,21 +810,21 @@ describe Chef::Resource do
810
810
  end
811
811
 
812
812
  it 'adds mappings for a single platform' do
813
- expect(Chef.resource_priority_map).to receive(:set).with(
813
+ expect(Chef.resource_handler_map).to receive(:set).with(
814
814
  :dinobot, Chef::Resource::Klz, { platform: ['autobots'] }
815
815
  )
816
816
  klz.provides :dinobot, platform: ['autobots']
817
817
  end
818
818
 
819
819
  it 'adds mappings for multiple platforms' do
820
- expect(Chef.resource_priority_map).to receive(:set).with(
820
+ expect(Chef.resource_handler_map).to receive(:set).with(
821
821
  :energy, Chef::Resource::Klz, { platform: ['autobots', 'decepticons']}
822
822
  )
823
823
  klz.provides :energy, platform: ['autobots', 'decepticons']
824
824
  end
825
825
 
826
826
  it 'adds mappings for all platforms' do
827
- expect(Chef.resource_priority_map).to receive(:set).with(
827
+ expect(Chef.resource_handler_map).to receive(:set).with(
828
828
  :tape_deck, Chef::Resource::Klz, {}
829
829
  )
830
830
  klz.provides :tape_deck
@@ -977,4 +977,90 @@ describe Chef::Resource do
977
977
  end
978
978
 
979
979
  end
980
+
981
+ describe "#action" do
982
+ let(:resource_class) do
983
+ Class.new(described_class) do
984
+ allowed_actions(%i{one two})
985
+ end
986
+ end
987
+ let(:resource) { resource_class.new('test', nil) }
988
+ subject { resource.action }
989
+
990
+ context "with a no action" do
991
+ it { is_expected.to eq [:nothing] }
992
+ end
993
+
994
+ context "with a default action" do
995
+ let(:resource_class) do
996
+ Class.new(described_class) do
997
+ default_action(:one)
998
+ end
999
+ end
1000
+ it { is_expected.to eq [:one] }
1001
+ end
1002
+
1003
+ context "with a symbol action" do
1004
+ before { resource.action(:one) }
1005
+ it { is_expected.to eq [:one] }
1006
+ end
1007
+
1008
+ context "with a string action" do
1009
+ before { resource.action('two') }
1010
+ it { is_expected.to eq [:two] }
1011
+ end
1012
+
1013
+ context "with an array action" do
1014
+ before { resource.action([:two, :one]) }
1015
+ it { is_expected.to eq [:two, :one] }
1016
+ end
1017
+
1018
+ context "with an assignment" do
1019
+ before { resource.action = :one }
1020
+ it { is_expected.to eq [:one] }
1021
+ end
1022
+
1023
+ context "with an array assignment" do
1024
+ before { resource.action = [:two, :one] }
1025
+ it { is_expected.to eq [:two, :one] }
1026
+ end
1027
+
1028
+ context "with an invalid action" do
1029
+ it { expect { resource.action(:three) }.to raise_error Chef::Exceptions::ValidationFailed }
1030
+ end
1031
+
1032
+ context "with an invalid assignment action" do
1033
+ it { expect { resource.action = :three }.to raise_error Chef::Exceptions::ValidationFailed }
1034
+ end
1035
+ end
1036
+
1037
+ describe ".default_action" do
1038
+ let(:default_action) { }
1039
+ let(:resource_class) do
1040
+ actions = default_action
1041
+ Class.new(described_class) do
1042
+ default_action(actions) if actions
1043
+ end
1044
+ end
1045
+ subject { resource_class.default_action }
1046
+
1047
+ context "with no default actions" do
1048
+ it { is_expected.to eq [:nothing] }
1049
+ end
1050
+
1051
+ context "with a symbol default action" do
1052
+ let(:default_action) { :one }
1053
+ it { is_expected.to eq [:one] }
1054
+ end
1055
+
1056
+ context "with a string default action" do
1057
+ let(:default_action) { 'one' }
1058
+ it { is_expected.to eq [:one] }
1059
+ end
1060
+
1061
+ context "with an array default action" do
1062
+ let(:default_action) { [:two, :one] }
1063
+ it { is_expected.to eq [:two, :one] }
1064
+ end
1065
+ end
980
1066
  end
@@ -26,98 +26,165 @@ describe Chef::RunList::VersionedRecipeList do
26
26
  end
27
27
  end
28
28
 
29
+ let(:list) { described_class.new }
30
+
31
+ let(:versioned_recipes) { [] }
32
+
33
+ let(:recipes) { [] }
34
+
35
+ before do
36
+ recipes.each { |r| list << r }
37
+ versioned_recipes.each {|r| list.add_recipe r[:name], r[:version]}
38
+ end
39
+
29
40
  describe "add_recipe" do
30
- before(:each) do
31
- @list = Chef::RunList::VersionedRecipeList.new
32
- @list << "apt"
33
- @list << "god"
34
- @list << "apache2"
35
- end
41
+
42
+ let(:recipes) { %w[ apt god apache2 ] }
36
43
 
37
44
  it "should append the recipe to the end of the list" do
38
- @list.add_recipe "rails"
39
- expect(@list).to eq(["apt", "god", "apache2", "rails"])
45
+ list.add_recipe "rails"
46
+ expect(list).to eq(["apt", "god", "apache2", "rails"])
40
47
  end
41
48
 
42
49
  it "should not duplicate entries" do
43
- @list.add_recipe "apt"
44
- expect(@list).to eq(["apt", "god", "apache2"])
50
+ list.add_recipe "apt"
51
+ expect(list).to eq(["apt", "god", "apache2"])
45
52
  end
46
53
 
47
54
  it "should allow you to specify a version" do
48
- @list.add_recipe "rails", "1.0.0"
49
- expect(@list).to eq(["apt", "god", "apache2", "rails"])
50
- expect(@list.with_versions).to include({:name => "rails", :version => "1.0.0"})
55
+ list.add_recipe "rails", "1.0.0"
56
+ expect(list).to eq(["apt", "god", "apache2", "rails"])
57
+ expect(list.with_versions).to include({:name => "rails", :version => "1.0.0"})
51
58
  end
52
59
 
53
60
  it "should allow you to specify a version for a recipe that already exists" do
54
- @list.add_recipe "apt", "1.2.3"
55
- expect(@list).to eq(["apt", "god", "apache2"])
56
- expect(@list.with_versions).to include({:name => "apt", :version => "1.2.3"})
61
+ list.add_recipe "apt", "1.2.3"
62
+ expect(list).to eq(["apt", "god", "apache2"])
63
+ expect(list.with_versions).to include({:name => "apt", :version => "1.2.3"})
57
64
  end
58
65
 
59
66
  it "should allow you to specify the same version of a recipe twice" do
60
- @list.add_recipe "rails", "1.0.0"
61
- @list.add_recipe "rails", "1.0.0"
62
- expect(@list.with_versions).to include({:name => "rails", :version => "1.0.0"})
67
+ list.add_recipe "rails", "1.0.0"
68
+ list.add_recipe "rails", "1.0.0"
69
+ expect(list.with_versions).to include({:name => "rails", :version => "1.0.0"})
63
70
  end
64
71
 
65
72
  it "should allow you to spcify no version, even when a version already exists" do
66
- @list.add_recipe "rails", "1.0.0"
67
- @list.add_recipe "rails"
68
- expect(@list.with_versions).to include({:name => "rails", :version => "1.0.0"})
73
+ list.add_recipe "rails", "1.0.0"
74
+ list.add_recipe "rails"
75
+ expect(list.with_versions).to include({:name => "rails", :version => "1.0.0"})
69
76
  end
70
77
 
71
78
  it "should not allow multiple versions of the same recipe" do
72
- @list.add_recipe "rails", "1.0.0"
73
- expect {@list.add_recipe "rails", "0.1.0"}.to raise_error Chef::Exceptions::CookbookVersionConflict
79
+ list.add_recipe "rails", "1.0.0"
80
+ expect {list.add_recipe "rails", "0.1.0"}.to raise_error Chef::Exceptions::CookbookVersionConflict
74
81
  end
75
82
  end
76
83
 
77
84
  describe "with_versions" do
78
- before(:each) do
79
- @recipes = [
85
+
86
+ let(:versioned_recipes) do
87
+ [
80
88
  {:name => "apt", :version => "1.0.0"},
81
89
  {:name => "god", :version => nil},
82
90
  {:name => "apache2", :version => "0.0.1"}
83
91
  ]
84
- @list = Chef::RunList::VersionedRecipeList.new
85
- @recipes.each {|i| @list.add_recipe i[:name], i[:version]}
86
92
  end
87
-
88
93
  it "should return an array of hashes with :name and :version" do
89
- expect(@list.with_versions).to eq(@recipes)
94
+ expect(list.with_versions).to eq(versioned_recipes)
90
95
  end
91
96
 
92
97
  it "should retain the same order as the version-less list" do
93
- with_versions = @list.with_versions
94
- @list.each_with_index do |item, index|
98
+ with_versions = list.with_versions
99
+ list.each_with_index do |item, index|
95
100
  expect(with_versions[index][:name]).to eq(item)
96
101
  end
97
102
  end
98
103
  end
99
104
 
100
105
  describe "with_version_constraints" do
101
- before(:each) do
102
- @recipes = [
103
- {:name => "apt", :version => "~> 1.2.0"},
104
- {:name => "god", :version => nil},
105
- {:name => "apache2", :version => "0.0.1"}
106
- ]
107
- @list = Chef::RunList::VersionedRecipeList.new
108
- @recipes.each {|i| @list.add_recipe i[:name], i[:version]}
109
- @constraints = @recipes.map do |x|
110
- { :name => x[:name],
111
- :version_constraint => Chef::VersionConstraint.new(x[:version])
112
- }
113
- end
106
+
107
+ let(:versioned_recipes) do
108
+ [
109
+ {:name => "apt", :version => "~> 1.2.0"},
110
+ {:name => "god", :version => nil},
111
+ {:name => "apache2", :version => "0.0.1"}
112
+ ]
114
113
  end
115
114
 
115
+
116
116
  it "should return an array of hashes with :name and :version_constraint" do
117
- @list.with_version_constraints.each do |x|
118
- expect(x).to have_key :name
119
- expect(x[:version_constraint]).not_to be nil
117
+ list.with_version_constraints.each_with_index do |recipe_spec, i|
118
+
119
+ expected_recipe = versioned_recipes[i]
120
+
121
+ expect(recipe_spec[:name]).to eq(expected_recipe[:name])
122
+ expect(recipe_spec[:version_constraint]).to eq(Chef::VersionConstraint.new(expected_recipe[:version]))
120
123
  end
121
124
  end
122
125
  end
126
+
127
+ describe "with_fully_qualified_names_and_version_constraints" do
128
+
129
+ let(:fq_names) { list.with_fully_qualified_names_and_version_constraints }
130
+
131
+ context "with bare cookbook names" do
132
+
133
+ let(:recipes) { %w[ apache2 ] }
134
+
135
+ it "gives $cookbook_name::default" do
136
+ expect(fq_names).to eq( %w[ apache2::default ] )
137
+ end
138
+
139
+ end
140
+
141
+ context "with qualified recipe names but no versions" do
142
+
143
+ let(:recipes) { %w[ mysql::server ] }
144
+
145
+ it "returns the qualified recipe names" do
146
+ expect(fq_names).to eq( %w[ mysql::server ] )
147
+ end
148
+
149
+ end
150
+
151
+ context "with unqualified names that have version constraints" do
152
+
153
+ let(:versioned_recipes) do
154
+ [
155
+ {:name => "apt", :version => "~> 1.2.0"},
156
+ ]
157
+ end
158
+
159
+ it "gives qualified names with their versions" do
160
+ expect(fq_names).to eq([ "apt::default@~> 1.2.0" ])
161
+ end
162
+
163
+ it "does not mutate the recipe name" do
164
+ expect(fq_names).to eq([ "apt::default@~> 1.2.0" ])
165
+ expect(list).to eq( [ "apt" ] )
166
+ end
167
+
168
+ end
169
+
170
+ context "with fully qualified names that have version constraints" do
171
+
172
+ let(:versioned_recipes) do
173
+ [
174
+ {:name => "apt::cacher", :version => "~> 1.2.0"},
175
+ ]
176
+ end
177
+
178
+ it "gives qualified names with their versions" do
179
+ expect(fq_names).to eq([ "apt::cacher@~> 1.2.0" ])
180
+ end
181
+
182
+ it "does not mutate the recipe name" do
183
+ expect(fq_names).to eq([ "apt::cacher@~> 1.2.0" ])
184
+ expect(list).to eq( [ "apt::cacher" ] )
185
+ end
186
+
187
+ end
188
+ end
189
+
123
190
  end