chef 12.4.0-universal-mingw32 → 12.4.1-universal-mingw32

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
@@ -45,7 +45,7 @@ describe Chef::Knife::ClientBulkDelete do
45
45
  clients = Hash.new
46
46
 
47
47
  nonvalidator_client_names.each do |client_name|
48
- client = Chef::ApiClient.new()
48
+ client = Chef::ApiClientV1.new()
49
49
  client.name(client_name)
50
50
  allow(client).to receive(:destroy).and_return(true)
51
51
  clients[client_name] = client
@@ -59,7 +59,7 @@ describe Chef::Knife::ClientBulkDelete do
59
59
  clients = Hash.new
60
60
 
61
61
  validator_client_names.each do |validator_client_name|
62
- validator_client = Chef::ApiClient.new()
62
+ validator_client = Chef::ApiClientV1.new()
63
63
  validator_client.name(validator_client_name)
64
64
  allow(validator_client).to receive(:validator).and_return(true)
65
65
  allow(validator_client).to receive(:destroy).and_return(true)
@@ -75,7 +75,7 @@ describe Chef::Knife::ClientBulkDelete do
75
75
  }
76
76
 
77
77
  before(:each) do
78
- allow(Chef::ApiClient).to receive(:list).and_return(clients)
78
+ allow(Chef::ApiClientV1).to receive(:list).and_return(clients)
79
79
  end
80
80
 
81
81
  describe "run" do
@@ -89,7 +89,7 @@ describe Chef::Knife::ClientBulkDelete do
89
89
 
90
90
  describe "with any clients" do
91
91
  it "should get the list of the clients" do
92
- expect(Chef::ApiClient).to receive(:list)
92
+ expect(Chef::ApiClientV1).to receive(:list)
93
93
  knife.run
94
94
  end
95
95
 
@@ -34,7 +34,7 @@ describe Chef::Knife::ClientCreate do
34
34
  end
35
35
 
36
36
  let(:client) do
37
- Chef::ApiClient.new
37
+ Chef::ApiClientV1.new
38
38
  end
39
39
 
40
40
  let(:knife) do
@@ -30,7 +30,7 @@ describe Chef::Knife::ClientDelete do
30
30
 
31
31
  describe 'run' do
32
32
  it 'should delete the client' do
33
- expect(@knife).to receive(:delete_object).with(Chef::ApiClient, 'adam', 'client')
33
+ expect(@knife).to receive(:delete_object).with(Chef::ApiClientV1, 'adam', 'client')
34
34
  @knife.run
35
35
  end
36
36
 
@@ -46,8 +46,8 @@ describe Chef::Knife::ClientDelete do
46
46
  before(:each) do
47
47
  allow(Chef::Knife::UI).to receive(:confirm).and_return(true)
48
48
  allow(@knife).to receive(:confirm).and_return(true)
49
- @client = Chef::ApiClient.new
50
- expect(Chef::ApiClient).to receive(:load).and_return(@client)
49
+ @client = Chef::ApiClientV1.new
50
+ expect(Chef::ApiClientV1).to receive(:load).and_return(@client)
51
51
  end
52
52
 
53
53
  it 'should delete non-validator client if --delete-validators is not set' do
@@ -17,16 +17,29 @@
17
17
  #
18
18
 
19
19
  require 'spec_helper'
20
+ require 'chef/api_client_v1'
20
21
 
21
22
  describe Chef::Knife::ClientEdit do
22
23
  before(:each) do
23
24
  @knife = Chef::Knife::ClientEdit.new
24
25
  @knife.name_args = [ 'adam' ]
26
+ @knife.config[:disable_editing] = true
25
27
  end
26
28
 
27
29
  describe 'run' do
30
+ let(:data) {
31
+ {
32
+ "name" => "adam",
33
+ "validator" => false,
34
+ "admin" => false,
35
+ "chef_type" => "client",
36
+ "create_key" => true
37
+ }
38
+ }
39
+
28
40
  it 'should edit the client' do
29
- expect(@knife).to receive(:edit_object).with(Chef::ApiClient, 'adam')
41
+ allow(Chef::ApiClientV1).to receive(:load).with('adam').and_return(data)
42
+ expect(@knife).to receive(:edit_data).with(data).and_return(data)
30
43
  @knife.run
31
44
  end
32
45
 
@@ -26,7 +26,7 @@ describe Chef::Knife::ClientList do
26
26
 
27
27
  describe 'run' do
28
28
  it 'should list the clients' do
29
- expect(Chef::ApiClient).to receive(:list)
29
+ expect(Chef::ApiClientV1).to receive(:list)
30
30
  expect(@knife).to receive(:format_list_for_display)
31
31
  @knife.run
32
32
  end
@@ -41,7 +41,7 @@ describe Chef::Knife::ClientReregister do
41
41
 
42
42
  context 'when not configured for file output' do
43
43
  it 'reregisters the client and prints the key' do
44
- expect(Chef::ApiClient).to receive(:reregister).with('adam').and_return(@client_mock)
44
+ expect(Chef::ApiClientV1).to receive(:reregister).with('adam').and_return(@client_mock)
45
45
  @knife.run
46
46
  expect(@stdout.string).to match( /foo_key/ )
47
47
  end
@@ -49,7 +49,7 @@ describe Chef::Knife::ClientReregister do
49
49
 
50
50
  context 'when configured for file output' do
51
51
  it 'should write the private key to a file' do
52
- expect(Chef::ApiClient).to receive(:reregister).with('adam').and_return(@client_mock)
52
+ expect(Chef::ApiClientV1).to receive(:reregister).with('adam').and_return(@client_mock)
53
53
 
54
54
  @knife.config[:file] = '/tmp/monkeypants'
55
55
  filehandle = StringIO.new
@@ -27,7 +27,7 @@ describe Chef::Knife::ClientShow do
27
27
 
28
28
  describe 'run' do
29
29
  it 'should list the client' do
30
- expect(Chef::ApiClient).to receive(:load).with('adam').and_return(@client_mock)
30
+ expect(Chef::ApiClientV1).to receive(:load).with('adam').and_return(@client_mock)
31
31
  expect(@knife).to receive(:format_for_display).with(@client_mock)
32
32
  @knife.run
33
33
  end
@@ -37,7 +37,7 @@ describe Chef::Knife::ClientShow do
37
37
  @stdout = StringIO.new
38
38
  allow(@knife.ui).to receive(:stdout).and_return(@stdout)
39
39
  fake_client_contents = {"foo"=>"bar", "baz"=>"qux"}
40
- expect(Chef::ApiClient).to receive(:load).with('adam').and_return(fake_client_contents)
40
+ expect(Chef::ApiClientV1).to receive(:load).with('adam').and_return(fake_client_contents)
41
41
  @knife.run
42
42
  expect(@stdout.string).to eql("{\n \"foo\": \"bar\",\n \"baz\": \"qux\"\n}\n")
43
43
  end
@@ -36,19 +36,19 @@ describe Chef::Knife::OscUserCreate do
36
36
 
37
37
  @knife.name_args = [ 'a_user' ]
38
38
  @knife.config[:user_password] = "foobar"
39
- @user = Chef::OscUser.new
39
+ @user = Chef::User.new
40
40
  @user.name "a_user"
41
- @user_with_private_key = Chef::OscUser.new
41
+ @user_with_private_key = Chef::User.new
42
42
  @user_with_private_key.name "a_user"
43
43
  @user_with_private_key.private_key 'private_key'
44
44
  allow(@user).to receive(:create).and_return(@user_with_private_key)
45
- allow(Chef::OscUser).to receive(:new).and_return(@user)
46
- allow(Chef::OscUser).to receive(:from_hash).and_return(@user)
45
+ allow(Chef::User).to receive(:new).and_return(@user)
46
+ allow(Chef::User).to receive(:from_hash).and_return(@user)
47
47
  allow(@knife).to receive(:edit_data).and_return(@user.to_hash)
48
48
  end
49
49
 
50
50
  it "creates a new user" do
51
- expect(Chef::OscUser).to receive(:new).and_return(@user)
51
+ expect(Chef::User).to receive(:new).and_return(@user)
52
52
  expect(@user).to receive(:create)
53
53
  @knife.run
54
54
  expect(@stderr.string).to match /created user.+a_user/i
@@ -31,7 +31,7 @@ describe Chef::Knife::OscUserDelete do
31
31
  end
32
32
 
33
33
  it 'deletes the user' do
34
- expect(@knife).to receive(:delete_object).with(Chef::OscUser, 'my_user')
34
+ expect(@knife).to receive(:delete_object).with(Chef::User, 'my_user')
35
35
  @knife.run
36
36
  end
37
37
 
@@ -38,7 +38,7 @@ describe Chef::Knife::OscUserEdit do
38
38
 
39
39
  it 'loads and edits the user' do
40
40
  data = { :name => "my_user" }
41
- allow(Chef::OscUser).to receive(:load).with("my_user").and_return(data)
41
+ allow(Chef::User).to receive(:load).with("my_user").and_return(data)
42
42
  expect(@knife).to receive(:edit_data).with(data).and_return(data)
43
43
  @knife.run
44
44
  end
@@ -30,7 +30,7 @@ describe Chef::Knife::OscUserList do
30
30
  end
31
31
 
32
32
  it 'lists the users' do
33
- expect(Chef::OscUser).to receive(:list)
33
+ expect(Chef::User).to receive(:list)
34
34
  expect(@knife).to receive(:format_list_for_display)
35
35
  @knife.run
36
36
  end
@@ -29,7 +29,7 @@ describe Chef::Knife::OscUserReregister do
29
29
  @knife = Chef::Knife::OscUserReregister.new
30
30
  @knife.name_args = [ 'a_user' ]
31
31
  @user_mock = double('user_mock', :private_key => "private_key")
32
- allow(Chef::OscUser).to receive(:load).and_return(@user_mock)
32
+ allow(Chef::User).to receive(:load).and_return(@user_mock)
33
33
  @stdout = StringIO.new
34
34
  allow(@knife.ui).to receive(:stdout).and_return(@stdout)
35
35
  end
@@ -32,7 +32,7 @@ describe Chef::Knife::OscUserShow do
32
32
  end
33
33
 
34
34
  it 'loads and displays the user' do
35
- expect(Chef::OscUser).to receive(:load).with('my_user').and_return(@user_mock)
35
+ expect(Chef::User).to receive(:load).with('my_user').and_return(@user_mock)
36
36
  expect(@knife).to receive(:format_for_display).with(@user_mock)
37
37
  @knife.run
38
38
  end
@@ -186,7 +186,7 @@ describe Chef::Knife::UserCreate do
186
186
 
187
187
  context "when a private_key is returned" do
188
188
  before do
189
- allow(knife).to receive(:create_user_from_hash).and_return(Chef::User.from_hash(knife.user.to_hash.merge({"private_key" => "some_private_key"})))
189
+ allow(knife).to receive(:create_user_from_hash).and_return(Chef::UserV1.from_hash(knife.user.to_hash.merge({"private_key" => "some_private_key"})))
190
190
  end
191
191
 
192
192
  context "when --file is passed" do
@@ -26,7 +26,7 @@ describe Chef::Knife::UserDelete do
26
26
  before(:each) do
27
27
  Chef::Knife::UserDelete.load_deps
28
28
  knife.name_args = [ 'my_user' ]
29
- allow(Chef::User).to receive(:load).and_return(user)
29
+ allow(Chef::UserV1).to receive(:load).and_return(user)
30
30
  allow(user).to receive(:username).and_return('my_user')
31
31
  allow(knife.ui).to receive(:stderr).and_return(stdout)
32
32
  allow(knife.ui).to receive(:stdout).and_return(stdout)
@@ -51,7 +51,7 @@ describe Chef::Knife::UserDelete do
51
51
  end
52
52
 
53
53
  it 'deletes the user' do
54
- #expect(knife).to receive(:delete_object).with(Chef::User, 'my_user')
54
+ #expect(knife).to receive(:delete_object).with(Chef::UserV1, 'my_user')
55
55
  expect(knife).to receive(:delete_object).with('my_user')
56
56
  knife.run
57
57
  end
@@ -36,7 +36,7 @@ describe Chef::Knife::UserEdit do
36
36
  context "when the username field is not supported by the server" do
37
37
  before do
38
38
  allow(knife).to receive(:run_osc_11_user_edit).and_raise(SystemExit)
39
- allow(Chef::User).to receive(:load).and_return({"username" => nil})
39
+ allow(Chef::UserV1).to receive(:load).and_return({"username" => nil})
40
40
  end
41
41
 
42
42
  it "displays the osc warning" do
@@ -52,7 +52,7 @@ describe Chef::Knife::UserEdit do
52
52
 
53
53
  it 'loads and edits the user' do
54
54
  data = { "username" => "my_user" }
55
- allow(Chef::User).to receive(:load).with("my_user").and_return(data)
55
+ allow(Chef::UserV1).to receive(:load).with("my_user").and_return(data)
56
56
  expect(knife).to receive(:edit_data).with(data).and_return(data)
57
57
  knife.run
58
58
  end
@@ -29,7 +29,7 @@ describe Chef::Knife::UserList do
29
29
  end
30
30
 
31
31
  it 'lists the users' do
32
- expect(Chef::User).to receive(:list)
32
+ expect(Chef::UserV1).to receive(:list)
33
33
  expect(knife).to receive(:format_list_for_display)
34
34
  knife.run
35
35
  end
@@ -26,7 +26,7 @@ describe Chef::Knife::UserReregister do
26
26
  before do
27
27
  Chef::Knife::UserReregister.load_deps
28
28
  knife.name_args = [ 'a_user' ]
29
- allow(Chef::User).to receive(:load).and_return(user_mock)
29
+ allow(Chef::UserV1).to receive(:load).and_return(user_mock)
30
30
  allow(knife.ui).to receive(:stdout).and_return(stdout)
31
31
  allow(knife.ui).to receive(:stderr).and_return(stdout)
32
32
  allow(user_mock).to receive(:username).and_return('a_user')
@@ -35,7 +35,7 @@ describe Chef::Knife::UserShow do
35
35
  context "when the username field is not supported by the server" do
36
36
  before do
37
37
  allow(knife).to receive(:run_osc_11_user_show).and_raise(SystemExit)
38
- allow(Chef::User).to receive(:load).with('my_user').and_return(user_mock)
38
+ allow(Chef::UserV1).to receive(:load).with('my_user').and_return(user_mock)
39
39
  allow(user_mock).to receive(:username).and_return(nil)
40
40
  end
41
41
 
@@ -51,7 +51,7 @@ describe Chef::Knife::UserShow do
51
51
  end
52
52
 
53
53
  it 'loads and displays the user' do
54
- expect(Chef::User).to receive(:load).with('my_user').and_return(user_mock)
54
+ expect(Chef::UserV1).to receive(:load).with('my_user').and_return(user_mock)
55
55
  expect(knife).to receive(:format_for_display).with(user_mock)
56
56
  knife.run
57
57
  end
@@ -163,7 +163,7 @@ describe "LWRP" do
163
163
  it "Should load the old content, and not the new" do
164
164
  resource = Chef::ResourceResolver.resolve(:lwrp_foo)
165
165
  expect(resource).to eq @original_resource
166
- expect(resource.default_action).to eq(:pass_buck)
166
+ expect(resource.default_action).to eq([:pass_buck])
167
167
  expect(Chef.method_defined?(:method_created_by_override_lwrp_foo)).to be_falsey
168
168
  end
169
169
  end
@@ -177,10 +177,6 @@ describe "LWRP" do
177
177
  end
178
178
  end
179
179
 
180
- it "should load the resource into a properly-named class and emit a warning when it is initialized" do
181
- expect { Chef::Resource::LwrpFoo.new('hi') }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
182
- end
183
-
184
180
  it "should be resolvable with Chef::ResourceResolver.resolve(:lwrp_foo)" do
185
181
  expect(Chef::ResourceResolver.resolve(:lwrp_foo, node: Chef::Node.new)).to eq(get_lwrp(:lwrp_foo))
186
182
  end
@@ -202,7 +198,7 @@ describe "LWRP" do
202
198
  end
203
199
 
204
200
  it "should set the specified action as the default action" do
205
- expect(get_lwrp(:lwrp_foo).new("blah").action).to eq(:pass_buck)
201
+ expect(get_lwrp(:lwrp_foo).new("blah").action).to eq([:pass_buck])
206
202
  end
207
203
 
208
204
  it "should create a method for each attribute" do
@@ -228,127 +224,6 @@ describe "LWRP" do
228
224
  expect(cls.node[:penguin_name]).to eql("jackass")
229
225
  end
230
226
 
231
- context "resource class created" do
232
- before do
233
- @old_treat_deprecation_warnings_as_errors = Chef::Config[:treat_deprecation_warnings_as_errors]
234
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
235
- end
236
- after do
237
- Chef::Config[:treat_deprecation_warnings_as_errors] = @old_treat_deprecation_warnings_as_errors
238
- end
239
-
240
- it "should load the resource into a properly-named class" do
241
- expect(Chef::Resource::LwrpFoo).to be_kind_of(Class)
242
- expect(Chef::Resource::LwrpFoo <= Chef::Resource::LWRPBase).to be_truthy
243
- end
244
-
245
- it "get_lwrp(:lwrp_foo).new is a Chef::Resource::LwrpFoo" do
246
- lwrp = get_lwrp(:lwrp_foo).new('hi')
247
- expect(lwrp.kind_of?(Chef::Resource::LwrpFoo)).to be_truthy
248
- expect(lwrp.is_a?(Chef::Resource::LwrpFoo)).to be_truthy
249
- expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
250
- expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
251
- end
252
-
253
- it "Chef::Resource::LwrpFoo.new is a get_lwrp(:lwrp_foo)" do
254
- lwrp = Chef::Resource::LwrpFoo.new('hi')
255
- expect(lwrp.kind_of?(get_lwrp(:lwrp_foo))).to be_truthy
256
- expect(lwrp.is_a?(get_lwrp(:lwrp_foo))).to be_truthy
257
- expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
258
- expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
259
- end
260
-
261
- it "works even if LwrpFoo exists in the top level" do
262
- module ::LwrpFoo
263
- end
264
- expect(Chef::Resource::LwrpFoo).not_to eq(::LwrpFoo)
265
- end
266
-
267
- context "with a subclass of get_lwrp(:lwrp_foo)" do
268
- let(:subclass) do
269
- Class.new(get_lwrp(:lwrp_foo))
270
- end
271
-
272
- it "subclass.new is a subclass" do
273
- lwrp = subclass.new('hi')
274
- expect(lwrp.kind_of?(subclass)).to be_truthy
275
- expect(lwrp.is_a?(subclass)).to be_truthy
276
- expect(subclass === lwrp).to be_truthy
277
- expect(lwrp.class === subclass)
278
- end
279
- it "subclass.new is a Chef::Resource::LwrpFoo" do
280
- lwrp = subclass.new('hi')
281
- expect(lwrp.kind_of?(Chef::Resource::LwrpFoo)).to be_truthy
282
- expect(lwrp.is_a?(Chef::Resource::LwrpFoo)).to be_truthy
283
- expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
284
- expect(lwrp.class === Chef::Resource::LwrpFoo)
285
- end
286
- it "subclass.new is a get_lwrp(:lwrp_foo)" do
287
- lwrp = subclass.new('hi')
288
- expect(lwrp.kind_of?(get_lwrp(:lwrp_foo))).to be_truthy
289
- expect(lwrp.is_a?(get_lwrp(:lwrp_foo))).to be_truthy
290
- expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
291
- expect(lwrp.class === get_lwrp(:lwrp_foo))
292
- end
293
- it "Chef::Resource::LwrpFoo.new is *not* a subclass" do
294
- lwrp = Chef::Resource::LwrpFoo.new('hi')
295
- expect(lwrp.kind_of?(subclass)).to be_falsey
296
- expect(lwrp.is_a?(subclass)).to be_falsey
297
- expect(subclass === lwrp.class).to be_falsey
298
- expect(subclass === Chef::Resource::LwrpFoo).to be_falsey
299
- end
300
- it "get_lwrp(:lwrp_foo).new is *not* a subclass" do
301
- lwrp = get_lwrp(:lwrp_foo).new('hi')
302
- expect(lwrp.kind_of?(subclass)).to be_falsey
303
- expect(lwrp.is_a?(subclass)).to be_falsey
304
- expect(subclass === lwrp.class).to be_falsey
305
- expect(subclass === get_lwrp(:lwrp_foo)).to be_falsey
306
- end
307
- end
308
-
309
- context "with a subclass of Chef::Resource::LwrpFoo" do
310
- let(:subclass) do
311
- Class.new(Chef::Resource::LwrpFoo)
312
- end
313
-
314
- it "subclass.new is a subclass" do
315
- lwrp = subclass.new('hi')
316
- expect(lwrp.kind_of?(subclass)).to be_truthy
317
- expect(lwrp.is_a?(subclass)).to be_truthy
318
- expect(subclass === lwrp).to be_truthy
319
- expect(lwrp.class === subclass)
320
- end
321
- it "subclass.new is a Chef::Resource::LwrpFoo" do
322
- lwrp = subclass.new('hi')
323
- expect(lwrp.kind_of?(Chef::Resource::LwrpFoo)).to be_truthy
324
- expect(lwrp.is_a?(Chef::Resource::LwrpFoo)).to be_truthy
325
- expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
326
- expect(lwrp.class === Chef::Resource::LwrpFoo)
327
- end
328
- it "subclass.new is a get_lwrp(:lwrp_foo)" do
329
- lwrp = subclass.new('hi')
330
- expect(lwrp.kind_of?(get_lwrp(:lwrp_foo))).to be_truthy
331
- expect(lwrp.is_a?(get_lwrp(:lwrp_foo))).to be_truthy
332
- expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
333
- expect(lwrp.class === get_lwrp(:lwrp_foo))
334
- end
335
- it "Chef::Resource::LwrpFoo.new is *not* a subclass" do
336
- lwrp = Chef::Resource::LwrpFoo.new('hi')
337
- expect(lwrp.kind_of?(subclass)).to be_falsey
338
- expect(lwrp.is_a?(subclass)).to be_falsey
339
- expect(subclass === lwrp.class).to be_falsey
340
- expect(subclass === Chef::Resource::LwrpFoo).to be_falsey
341
- end
342
- it "get_lwrp(:lwrp_foo).new is *not* a subclass" do
343
- lwrp = get_lwrp(:lwrp_foo).new('hi')
344
- expect(lwrp.kind_of?(subclass)).to be_falsey
345
- expect(lwrp.is_a?(subclass)).to be_falsey
346
- expect(subclass === lwrp.class).to be_falsey
347
- expect(subclass === get_lwrp(:lwrp_foo)).to be_falsey
348
- end
349
- end
350
- end
351
-
352
227
  context "resource_name" do
353
228
  let(:klass) { Class.new(Chef::Resource::LWRPBase) }
354
229
 
@@ -419,7 +294,7 @@ describe "LWRP" do
419
294
  end
420
295
 
421
296
  it "delegates #default_action to the parent" do
422
- expect(child.default_action).to eq(:eat)
297
+ expect(child.default_action).to eq([:eat])
423
298
  end
424
299
  end
425
300
 
@@ -436,7 +311,7 @@ describe "LWRP" do
436
311
  end
437
312
 
438
313
  it "does not delegate #default_action to the parent" do
439
- expect(child.default_action).to eq(:dont_eat)
314
+ expect(child.default_action).to eq([:dont_eat])
440
315
  end
441
316
  end
442
317
 
@@ -564,7 +439,7 @@ describe "LWRP" do
564
439
  end
565
440
 
566
441
  it "sets itself as a provider for a resource of the same name" do
567
- found_providers = Chef::Platform::ProviderPriorityMap.instance.list_handlers(node, :lwrp_buck_passer)
442
+ found_providers = Chef::Platform::ProviderHandlerMap.instance.list(node, :lwrp_buck_passer)
568
443
  # we bypass the per-file loading to get the file to load each time,
569
444
  # which creates the LWRP class repeatedly. New things get prepended to
570
445
  # the list of providers.
@@ -576,7 +451,7 @@ describe "LWRP" do
576
451
  let(:lwrp_cookbok_name) { "l_w_r_p" }
577
452
 
578
453
  it "sets itself as a provider for a resource of the same name" do
579
- found_providers = Chef::Platform::ProviderPriorityMap.instance.list_handlers(node, :l_w_r_p_buck_passer)
454
+ found_providers = Chef::Platform::ProviderHandlerMap.instance.list(node, :l_w_r_p_buck_passer)
580
455
  expect(found_providers.size).to eq(1)
581
456
  expect(found_providers.last).to eq(get_lwrp_provider(:l_w_r_p_buck_passer))
582
457
  end
@@ -587,10 +462,10 @@ describe "LWRP" do
587
462
  let(:lwrp_cookbok_name) { "l-w-r-p" }
588
463
 
589
464
  it "sets itself as a provider for a resource of the same name" do
590
- incorrect_providers = Chef::Platform::ProviderPriorityMap.instance.list_handlers(node, :'l-w-r-p_buck_passer')
465
+ incorrect_providers = Chef::Platform::ProviderHandlerMap.instance.list(node, :'l-w-r-p_buck_passer')
591
466
  expect(incorrect_providers).to eq([])
592
467
 
593
- found_providers = Chef::Platform::ProviderPriorityMap.instance.list_handlers(node, :l_w_r_p_buck_passer)
468
+ found_providers = Chef::Platform::ProviderHandlerMap.instance.list(node, :l_w_r_p_buck_passer)
594
469
  expect(found_providers.first).to eq(get_lwrp_provider(:l_w_r_p_buck_passer))
595
470
  end
596
471
  end
@@ -704,7 +579,144 @@ describe "LWRP" do
704
579
  end
705
580
 
706
581
  end
707
-
708
582
  end
709
583
 
584
+ context "resource class created" do
585
+ before(:context) do
586
+ @tmpdir = Dir.mktmpdir("lwrp_test")
587
+ resource_path = File.join(@tmpdir, "once.rb")
588
+ IO.write(resource_path, "default_action :create")
589
+
590
+ @old_treat_deprecation_warnings_as_errors = Chef::Config[:treat_deprecation_warnings_as_errors]
591
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
592
+ Chef::Resource::LWRPBase.build_from_file("lwrp", resource_path, nil)
593
+ end
594
+
595
+ after(:context) do
596
+ FileUtils.remove_entry @tmpdir
597
+ Chef::Config[:treat_deprecation_warnings_as_errors] = @old_treat_deprecation_warnings_as_errors
598
+ end
599
+
600
+ it "should load the resource into a properly-named class" do
601
+ expect(Chef::Resource::LwrpOnce).to be_kind_of(Class)
602
+ expect(Chef::Resource::LwrpOnce <= Chef::Resource::LWRPBase).to be_truthy
603
+ end
604
+
605
+ it "get_lwrp(:lwrp_once).new is a Chef::Resource::LwrpOnce" do
606
+ lwrp = get_lwrp(:lwrp_once).new('hi')
607
+ expect(lwrp.kind_of?(Chef::Resource::LwrpOnce)).to be_truthy
608
+ expect(lwrp.is_a?(Chef::Resource::LwrpOnce)).to be_truthy
609
+ expect(get_lwrp(:lwrp_once) === lwrp).to be_truthy
610
+ expect(Chef::Resource::LwrpOnce === lwrp).to be_truthy
611
+ end
612
+
613
+ it "Chef::Resource::LwrpOnce.new is a get_lwrp(:lwrp_once)" do
614
+ lwrp = Chef::Resource::LwrpOnce.new('hi')
615
+ expect(lwrp.kind_of?(get_lwrp(:lwrp_once))).to be_truthy
616
+ expect(lwrp.is_a?(get_lwrp(:lwrp_once))).to be_truthy
617
+ expect(get_lwrp(:lwrp_once) === lwrp).to be_truthy
618
+ expect(Chef::Resource::LwrpOnce === lwrp).to be_truthy
619
+ end
620
+
621
+ it "works even if LwrpOnce exists in the top level" do
622
+ module ::LwrpOnce
623
+ end
624
+ expect(Chef::Resource::LwrpOnce).not_to eq(::LwrpOnce)
625
+ end
626
+
627
+ it "allows monkey patching of the lwrp through Chef::Resource" do
628
+ monkey = Module.new do
629
+ def issue_3607
630
+ end
631
+ end
632
+ Chef::Resource::LwrpOnce.send(:include, monkey)
633
+ expect { get_lwrp(:lwrp_once).new("blah").issue_3607 }.not_to raise_error
634
+ end
635
+
636
+ context "with a subclass of get_lwrp(:lwrp_once)" do
637
+ let(:subclass) do
638
+ Class.new(get_lwrp(:lwrp_once))
639
+ end
640
+
641
+ it "subclass.new is a subclass" do
642
+ lwrp = subclass.new('hi')
643
+ expect(lwrp.kind_of?(subclass)).to be_truthy
644
+ expect(lwrp.is_a?(subclass)).to be_truthy
645
+ expect(subclass === lwrp).to be_truthy
646
+ expect(lwrp.class === subclass)
647
+ end
648
+ it "subclass.new is a Chef::Resource::LwrpOnce" do
649
+ lwrp = subclass.new('hi')
650
+ expect(lwrp.kind_of?(Chef::Resource::LwrpOnce)).to be_truthy
651
+ expect(lwrp.is_a?(Chef::Resource::LwrpOnce)).to be_truthy
652
+ expect(Chef::Resource::LwrpOnce === lwrp).to be_truthy
653
+ expect(lwrp.class === Chef::Resource::LwrpOnce)
654
+ end
655
+ it "subclass.new is a get_lwrp(:lwrp_once)" do
656
+ lwrp = subclass.new('hi')
657
+ expect(lwrp.kind_of?(get_lwrp(:lwrp_once))).to be_truthy
658
+ expect(lwrp.is_a?(get_lwrp(:lwrp_once))).to be_truthy
659
+ expect(get_lwrp(:lwrp_once) === lwrp).to be_truthy
660
+ expect(lwrp.class === get_lwrp(:lwrp_once))
661
+ end
662
+ it "Chef::Resource::LwrpOnce.new is *not* a subclass" do
663
+ lwrp = Chef::Resource::LwrpOnce.new('hi')
664
+ expect(lwrp.kind_of?(subclass)).to be_falsey
665
+ expect(lwrp.is_a?(subclass)).to be_falsey
666
+ expect(subclass === lwrp.class).to be_falsey
667
+ expect(subclass === Chef::Resource::LwrpOnce).to be_falsey
668
+ end
669
+ it "get_lwrp(:lwrp_once).new is *not* a subclass" do
670
+ lwrp = get_lwrp(:lwrp_once).new('hi')
671
+ expect(lwrp.kind_of?(subclass)).to be_falsey
672
+ expect(lwrp.is_a?(subclass)).to be_falsey
673
+ expect(subclass === lwrp.class).to be_falsey
674
+ expect(subclass === get_lwrp(:lwrp_once)).to be_falsey
675
+ end
676
+ end
677
+
678
+ context "with a subclass of Chef::Resource::LwrpOnce" do
679
+ let(:subclass) do
680
+ Class.new(Chef::Resource::LwrpOnce)
681
+ end
682
+
683
+ it "subclass.new is a subclass" do
684
+ lwrp = subclass.new('hi')
685
+ expect(lwrp.kind_of?(subclass)).to be_truthy
686
+ expect(lwrp.is_a?(subclass)).to be_truthy
687
+ expect(subclass === lwrp).to be_truthy
688
+ expect(lwrp.class === subclass)
689
+ end
690
+ it "subclass.new is a Chef::Resource::LwrpOnce" do
691
+ lwrp = subclass.new('hi')
692
+ expect(lwrp.kind_of?(Chef::Resource::LwrpOnce)).to be_truthy
693
+ expect(lwrp.is_a?(Chef::Resource::LwrpOnce)).to be_truthy
694
+ expect(Chef::Resource::LwrpOnce === lwrp).to be_truthy
695
+ expect(lwrp.class === Chef::Resource::LwrpOnce)
696
+ end
697
+ it "subclass.new is a get_lwrp(:lwrp_once)" do
698
+ lwrp = subclass.new('hi')
699
+ expect(lwrp.kind_of?(get_lwrp(:lwrp_once))).to be_truthy
700
+ expect(lwrp.is_a?(get_lwrp(:lwrp_once))).to be_truthy
701
+ expect(get_lwrp(:lwrp_once) === lwrp).to be_truthy
702
+ expect(lwrp.class === get_lwrp(:lwrp_once))
703
+ end
704
+ it "Chef::Resource::LwrpOnce.new is *not* a subclass" do
705
+ lwrp = Chef::Resource::LwrpOnce.new('hi')
706
+ expect(lwrp.kind_of?(subclass)).to be_falsey
707
+ expect(lwrp.is_a?(subclass)).to be_falsey
708
+ expect(subclass === lwrp.class).to be_falsey
709
+ expect(subclass === Chef::Resource::LwrpOnce).to be_falsey
710
+ end
711
+ it "get_lwrp(:lwrp_once).new is *not* a subclass" do
712
+ lwrp = get_lwrp(:lwrp_once).new('hi')
713
+ expect(lwrp.kind_of?(subclass)).to be_falsey
714
+ expect(lwrp.is_a?(subclass)).to be_falsey
715
+ expect(subclass === lwrp.class).to be_falsey
716
+ expect(subclass === get_lwrp(:lwrp_once)).to be_falsey
717
+ end
718
+ end
719
+ end
710
720
  end
721
+
722
+