chef 11.12.0.alpha.1 → 11.12.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef/api_client/registration.rb +46 -9
  3. data/lib/chef/application.rb +1 -0
  4. data/lib/chef/application/client.rb +25 -24
  5. data/lib/chef/client.rb +34 -0
  6. data/lib/chef/config.rb +11 -0
  7. data/lib/chef/cookbook/chefignore.rb +10 -2
  8. data/lib/chef/cookbook/metadata.rb +31 -3
  9. data/lib/chef/cookbook/synchronizer.rb +2 -2
  10. data/lib/chef/cookbook/syntax_check.rb +4 -4
  11. data/lib/chef/encrypted_data_bag_item.rb +37 -1
  12. data/lib/chef/exceptions.rb +1 -0
  13. data/lib/chef/guard_interpreter/default_guard_interpreter.rb +42 -0
  14. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +122 -0
  15. data/lib/chef/http.rb +0 -1
  16. data/lib/chef/http/decompressor.rb +7 -4
  17. data/lib/chef/http/simple.rb +5 -0
  18. data/lib/chef/http/validate_content_length.rb +28 -12
  19. data/lib/chef/knife.rb +1 -0
  20. data/lib/chef/knife/client_bulk_delete.rb +48 -9
  21. data/lib/chef/knife/client_delete.rb +4 -4
  22. data/lib/chef/knife/cookbook_bulk_delete.rb +1 -1
  23. data/lib/chef/knife/cookbook_upload.rb +17 -7
  24. data/lib/chef/knife/core/bootstrap_context.rb +1 -1
  25. data/lib/chef/knife/core/ui.rb +42 -5
  26. data/lib/chef/knife/node_run_list_add.rb +31 -2
  27. data/lib/chef/knife/ssh.rb +44 -31
  28. data/lib/chef/knife/ssl_check.rb +213 -0
  29. data/lib/chef/knife/ssl_fetch.rb +145 -0
  30. data/lib/chef/mixin/deep_merge.rb +13 -5
  31. data/lib/chef/mixin/shell_out.rb +9 -3
  32. data/lib/chef/node.rb +23 -4
  33. data/lib/chef/node/immutable_collections.rb +32 -0
  34. data/lib/chef/platform/provider_mapping.rb +21 -18
  35. data/lib/chef/platform/query_helpers.rb +10 -2
  36. data/lib/chef/policy_builder/expand_node_object.rb +3 -6
  37. data/lib/chef/provider/cron.rb +25 -3
  38. data/lib/chef/provider/mount/mount.rb +1 -1
  39. data/lib/chef/provider/package/dpkg.rb +2 -1
  40. data/lib/chef/provider/package/windows.rb +80 -0
  41. data/lib/chef/provider/package/windows/msi.rb +69 -0
  42. data/lib/chef/provider/powershell_script.rb +19 -6
  43. data/lib/chef/provider/service/solaris.rb +11 -7
  44. data/lib/chef/resource.rb +18 -5
  45. data/lib/chef/resource/conditional.rb +20 -7
  46. data/lib/chef/resource/cron.rb +18 -2
  47. data/lib/chef/resource/execute.rb +0 -2
  48. data/lib/chef/resource/powershell_script.rb +23 -1
  49. data/lib/chef/resource/script.rb +25 -0
  50. data/lib/chef/resource/subversion.rb +4 -0
  51. data/lib/chef/resource/windows_package.rb +79 -0
  52. data/lib/chef/resource/windows_script.rb +0 -5
  53. data/lib/chef/resources.rb +1 -0
  54. data/lib/chef/rest.rb +6 -1
  55. data/lib/chef/run_context.rb +22 -2
  56. data/lib/chef/run_context/cookbook_compiler.rb +12 -0
  57. data/lib/chef/util/editor.rb +92 -0
  58. data/lib/chef/util/file_edit.rb +22 -54
  59. data/lib/chef/version.rb +2 -2
  60. data/lib/chef/win32/api/installer.rb +166 -0
  61. data/lib/chef/win32/version.rb +8 -0
  62. data/spec/data/standalone_cookbook/Gemfile +1 -0
  63. data/spec/data/standalone_cookbook/chefignore +9 -0
  64. data/spec/data/standalone_cookbook/recipes/default.rb +3 -0
  65. data/spec/data/standalone_cookbook/vendor/bundle/ruby/2.0.0/gems/multi_json-1.9.0/lib/multi_json.rb +1 -0
  66. data/spec/functional/resource/powershell_spec.rb +262 -1
  67. data/spec/functional/win32/versions_spec.rb +3 -3
  68. data/spec/integration/knife/chefignore_spec.rb +1 -2
  69. data/spec/integration/knife/raw_spec.rb +8 -13
  70. data/spec/integration/knife/redirection_spec.rb +6 -14
  71. data/spec/integration/solo/solo_spec.rb +19 -0
  72. data/spec/support/shared/functional/windows_script.rb +1 -1
  73. data/spec/support/shared/integration/app_server_support.rb +42 -0
  74. data/spec/support/shared/integration/integration_helper.rb +1 -0
  75. data/spec/support/shared/unit/script_resource.rb +38 -0
  76. data/spec/unit/api_client/registration_spec.rb +109 -38
  77. data/spec/unit/application/client_spec.rb +48 -1
  78. data/spec/unit/cookbook/chefignore_spec.rb +10 -0
  79. data/spec/unit/cookbook/metadata_spec.rb +45 -1
  80. data/spec/unit/cookbook/syntax_check_spec.rb +28 -0
  81. data/spec/unit/cookbook_spec.rb +0 -10
  82. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +56 -0
  83. data/spec/unit/http/simple_spec.rb +32 -0
  84. data/spec/unit/http/validate_content_length_spec.rb +187 -0
  85. data/spec/unit/knife/bootstrap_spec.rb +13 -4
  86. data/spec/unit/knife/client_bulk_delete_spec.rb +123 -38
  87. data/spec/unit/knife/client_delete_spec.rb +4 -4
  88. data/spec/unit/knife/cookbook_upload_spec.rb +181 -88
  89. data/spec/unit/knife/core/bootstrap_context_spec.rb +11 -1
  90. data/spec/unit/knife/core/ui_spec.rb +109 -38
  91. data/spec/unit/knife/node_run_list_add_spec.rb +24 -1
  92. data/spec/unit/knife/ssh_spec.rb +17 -6
  93. data/spec/unit/knife/ssl_check_spec.rb +187 -0
  94. data/spec/unit/knife/ssl_fetch_spec.rb +151 -0
  95. data/spec/unit/mixin/deep_merge_spec.rb +17 -0
  96. data/spec/unit/node/immutable_collections_spec.rb +55 -0
  97. data/spec/unit/node_spec.rb +9 -0
  98. data/spec/unit/platform/query_helpers_spec.rb +32 -0
  99. data/spec/unit/platform_spec.rb +193 -175
  100. data/spec/unit/policy_builder/expand_node_object_spec.rb +1 -1
  101. data/spec/unit/provider/cron_spec.rb +175 -1
  102. data/spec/unit/provider/mount/mount_spec.rb +33 -3
  103. data/spec/unit/provider/package/dpkg_spec.rb +4 -0
  104. data/spec/unit/provider/package/windows/msi_spec.rb +60 -0
  105. data/spec/unit/provider/package/windows_spec.rb +80 -0
  106. data/spec/unit/provider/service/macosx_spec.rb +3 -3
  107. data/spec/unit/provider/service/solaris_smf_service_spec.rb +35 -10
  108. data/spec/unit/pure_application_spec.rb +32 -0
  109. data/spec/unit/recipe_spec.rb +4 -0
  110. data/spec/unit/resource/conditional_spec.rb +13 -12
  111. data/spec/unit/resource/cron_spec.rb +7 -2
  112. data/spec/unit/resource/powershell_spec.rb +85 -2
  113. data/spec/unit/resource/subversion_spec.rb +5 -0
  114. data/spec/unit/resource/windows_package_spec.rb +74 -0
  115. data/spec/unit/resource_spec.rb +23 -1
  116. data/spec/unit/rest_spec.rb +15 -0
  117. data/spec/unit/run_context/cookbook_compiler_spec.rb +12 -0
  118. data/spec/unit/run_context_spec.rb +7 -0
  119. data/spec/unit/util/editor_spec.rb +152 -0
  120. data/spec/unit/util/file_edit_spec.rb +37 -1
  121. metadata +41 -30
@@ -63,15 +63,15 @@ XML
63
63
  Dir.stub(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], [])
64
64
  provider.stub(:shell_out!).
65
65
  with("launchctl list", {:group => 1001, :user => 101}).
66
- and_return(mock("Status", :stdout => launchctl_stdout))
66
+ and_return(double("Status", :stdout => launchctl_stdout))
67
67
  provider.stub(:shell_out).
68
68
  with(/launchctl list /,
69
69
  {:group => nil, :user => nil}).
70
- and_return(mock("Status",
70
+ and_return(double("Status",
71
71
  :stdout => launchctl_stdout, :exitstatus => 0))
72
72
  provider.stub(:shell_out!).
73
73
  with(/plutil -convert xml1 -o/).
74
- and_return(mock("Status", :stdout => plutil_stdout))
74
+ and_return(double("Status", :stdout => plutil_stdout))
75
75
 
76
76
  File.stub(:stat).and_return(double("stat", :gid => 1001, :uid => 101))
77
77
  end
@@ -54,34 +54,47 @@ describe Chef::Provider::Service::Solaris do
54
54
 
55
55
  describe "when discovering the current service state" do
56
56
  it "should create a current resource with the name of the new resource" do
57
- @provider.stub(:popen4).with("/bin/svcs -l chef").and_return(@status)
57
+ @provider.stub!(:shell_out!).with("/bin/svcs -l chef").and_return(@status)
58
58
  Chef::Resource::Service.should_receive(:new).and_return(@current_resource)
59
59
  @provider.load_current_resource
60
60
  end
61
61
 
62
62
 
63
63
  it "should return the current resource" do
64
- @provider.stub(:popen4).with("/bin/svcs -l chef").and_return(@status)
64
+ @provider.stub!(:shell_out!).with("/bin/svcs -l chef").and_return(@status)
65
65
  @provider.load_current_resource.should eql(@current_resource)
66
66
  end
67
67
 
68
- it "should popen4 '/bin/svcs -l service_name'" do
69
- @provider.should_receive(:popen4).with("/bin/svcs -l chef").and_return(@status)
68
+ it "should call '/bin/svcs -l service_name'" do
69
+ @provider.should_receive(:shell_out!).with("/bin/svcs -l chef").and_return(@status)
70
70
  @provider.load_current_resource
71
71
  end
72
72
 
73
73
  it "should mark service as not running" do
74
- @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
74
+ @provider.stub!(:shell_out!).and_return(@status)
75
75
  @current_resource.should_receive(:running).with(false)
76
76
  @provider.load_current_resource
77
77
  end
78
78
 
79
79
  it "should mark service as running" do
80
- @stdout.stub(:each).and_yield("state online")
81
- @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
80
+ @status = mock("Status", :exitstatus => 0, :stdout => 'state online')
81
+ @provider.stub!(:shell_out!).and_return(@status)
82
82
  @current_resource.should_receive(:running).with(true)
83
83
  @provider.load_current_resource
84
84
  end
85
+
86
+ it "should not mark service as maintenance" do
87
+ @provider.stub!(:shell_out!).and_return(@status)
88
+ @provider.load_current_resource
89
+ @provider.maintenance.should be_false
90
+ end
91
+
92
+ it "should mark service as maintenance" do
93
+ @status = mock("Status", :exitstatus => 0, :stdout => 'state maintenance')
94
+ @provider.stub!(:shell_out!).and_return(@status)
95
+ @provider.load_current_resource
96
+ @provider.maintenance.should be_true
97
+ end
85
98
  end
86
99
 
87
100
  describe "when enabling the service" do
@@ -91,19 +104,31 @@ describe Chef::Provider::Service::Solaris do
91
104
  end
92
105
 
93
106
  it "should call svcadm enable -s chef" do
94
- @new_resource.stub(:enable_command).and_return("#{@new_resource.enable_command}")
107
+ @new_resource.stub!(:enable_command).and_return("#{@new_resource.enable_command}")
108
+ @provider.should_not_receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}")
95
109
  @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status)
96
- @provider.enable_service.should be_true
110
+ @provider.enable_service.should be_true
97
111
  @current_resource.enabled.should be_true
98
112
  end
99
113
 
100
114
  it "should call svcadm enable -s chef for start_service" do
101
- @new_resource.stub(:start_command).and_return("#{@new_resource.start_command}")
115
+ @new_resource.stub!(:start_command).and_return("#{@new_resource.start_command}")
116
+ @provider.should_not_receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}")
102
117
  @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status)
103
118
  @provider.start_service.should be_true
104
119
  @current_resource.enabled.should be_true
105
120
  end
106
121
 
122
+ it "should call svcadm clear chef for start_service when state maintenance" do
123
+ @status = mock("Status", :exitstatus => 0, :stdout => 'state maintenance')
124
+ @provider.stub!(:shell_out!).and_return(@status)
125
+ @provider.load_current_resource
126
+ @new_resource.stub!(:enable_command).and_return("#{@new_resource.enable_command}")
127
+ @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}").and_return(@status)
128
+ @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status)
129
+ @provider.enable_service.should be_true
130
+ @current_resource.enabled.should be_true
131
+ end
107
132
  end
108
133
 
109
134
 
@@ -0,0 +1,32 @@
1
+ #
2
+ # Author:: Serdar Sutay (<serdar@getchef.com>)
3
+ # Copyright:: Copyright (c) 2014 Chef Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ # This spec file intentionally doesn't include spec_helper.rb to
19
+ # be able to test only Chef::Application.
20
+ # Regression test for CHEF-5169
21
+
22
+ require 'chef/application'
23
+
24
+ describe "Chef::Application" do
25
+ let(:app) { Chef::Application.new }
26
+
27
+ describe "load_config_file" do
28
+ it "calls ConfigFetcher successfully without NameError" do
29
+ expect { app.load_config_file }.not_to raise_error
30
+ end
31
+ end
32
+ end
@@ -339,6 +339,7 @@ describe Chef::Recipe do
339
339
  describe "include_recipe" do
340
340
  it "should evaluate another recipe with include_recipe" do
341
341
  node.should_receive(:loaded_recipe).with(:openldap, "gigantor")
342
+ run_context.stub(:unreachable_cookbook?).with(:openldap).and_return(false)
342
343
  run_context.include_recipe "openldap::gigantor"
343
344
  res = run_context.resource_collection.resources(:cat => "blanket")
344
345
  res.name.should eql("blanket")
@@ -347,6 +348,7 @@ describe Chef::Recipe do
347
348
 
348
349
  it "should load the default recipe for a cookbook if include_recipe is called without a ::" do
349
350
  node.should_receive(:loaded_recipe).with(:openldap, "default")
351
+ run_context.stub(:unreachable_cookbook?).with(:openldap).and_return(false)
350
352
  run_context.include_recipe "openldap"
351
353
  res = run_context.resource_collection.resources(:cat => "blanket")
352
354
  res.name.should eql("blanket")
@@ -355,12 +357,14 @@ describe Chef::Recipe do
355
357
 
356
358
  it "should store that it has seen a recipe in the run_context" do
357
359
  node.should_receive(:loaded_recipe).with(:openldap, "default")
360
+ run_context.stub(:unreachable_cookbook?).with(:openldap).and_return(false)
358
361
  run_context.include_recipe "openldap"
359
362
  run_context.loaded_recipe?("openldap").should be_true
360
363
  end
361
364
 
362
365
  it "should not include the same recipe twice" do
363
366
  node.should_receive(:loaded_recipe).with(:openldap, "default").exactly(:once)
367
+ run_context.stub(:unreachable_cookbook?).with(:openldap).and_return(false)
364
368
  cookbook_collection[:openldap].should_receive(:load_recipe).with("default", run_context)
365
369
  recipe.include_recipe "openldap"
366
370
  cookbook_collection[:openldap].should_not_receive(:load_recipe).with("default", run_context)
@@ -24,12 +24,13 @@ describe Chef::Resource::Conditional do
24
24
  Mixlib::ShellOut.any_instance.stub(:run_command).and_return(nil)
25
25
  @status = OpenStruct.new(:success? => true)
26
26
  Mixlib::ShellOut.any_instance.stub(:status).and_return(@status)
27
+ @parent_resource = Chef::Resource.new(nil, Chef::Node.new)
27
28
  end
28
29
 
29
30
  describe "when created as an `only_if`" do
30
31
  describe "after running a successful command" do
31
32
  before do
32
- @conditional = Chef::Resource::Conditional.only_if("true")
33
+ @conditional = Chef::Resource::Conditional.only_if(@parent_resource, "true")
33
34
  end
34
35
 
35
36
  it "indicates that resource convergence should continue" do
@@ -40,7 +41,7 @@ describe Chef::Resource::Conditional do
40
41
  describe "after running a negative/false command" do
41
42
  before do
42
43
  @status.send("success?=", false)
43
- @conditional = Chef::Resource::Conditional.only_if("false")
44
+ @conditional = Chef::Resource::Conditional.only_if(@parent_resource, "false")
44
45
  end
45
46
 
46
47
  it "indicates that resource convergence should not continue" do
@@ -50,8 +51,8 @@ describe Chef::Resource::Conditional do
50
51
 
51
52
  describe 'after running a command which timed out' do
52
53
  before do
53
- @conditional = Chef::Resource::Conditional.only_if("false")
54
- @conditional.stub(:shell_out).and_raise(Chef::Exceptions::CommandTimeout)
54
+ @conditional = Chef::Resource::Conditional.only_if(@parent_resource, "false")
55
+ Chef::GuardInterpreter::DefaultGuardInterpreter.any_instance.stub(:shell_out).and_raise(Chef::Exceptions::CommandTimeout)
55
56
  end
56
57
 
57
58
  it 'indicates that resource convergence should not continue' do
@@ -66,7 +67,7 @@ describe Chef::Resource::Conditional do
66
67
 
67
68
  describe "after running a block that returns a truthy value" do
68
69
  before do
69
- @conditional = Chef::Resource::Conditional.only_if { Object.new }
70
+ @conditional = Chef::Resource::Conditional.only_if(@parent_resource) { Object.new }
70
71
  end
71
72
 
72
73
  it "indicates that resource convergence should continue" do
@@ -76,7 +77,7 @@ describe Chef::Resource::Conditional do
76
77
 
77
78
  describe "after running a block that returns a falsey value" do
78
79
  before do
79
- @conditional = Chef::Resource::Conditional.only_if { nil }
80
+ @conditional = Chef::Resource::Conditional.only_if(@parent_resource) { nil }
80
81
  end
81
82
 
82
83
  it "indicates that resource convergence should not continue" do
@@ -88,7 +89,7 @@ describe Chef::Resource::Conditional do
88
89
  describe "when created as a `not_if`" do
89
90
  describe "after running a successful/true command" do
90
91
  before do
91
- @conditional = Chef::Resource::Conditional.not_if("true")
92
+ @conditional = Chef::Resource::Conditional.not_if(@parent_resource, "true")
92
93
  end
93
94
 
94
95
  it "indicates that resource convergence should not continue" do
@@ -99,7 +100,7 @@ describe Chef::Resource::Conditional do
99
100
  describe "after running a failed/false command" do
100
101
  before do
101
102
  @status.send("success?=", false)
102
- @conditional = Chef::Resource::Conditional.not_if("false")
103
+ @conditional = Chef::Resource::Conditional.not_if(@parent_resource, "false")
103
104
  end
104
105
 
105
106
  it "indicates that resource convergence should continue" do
@@ -109,8 +110,8 @@ describe Chef::Resource::Conditional do
109
110
 
110
111
  describe 'after running a command which timed out' do
111
112
  before do
112
- @conditional = Chef::Resource::Conditional.not_if("false")
113
- @conditional.stub(:shell_out).and_raise(Chef::Exceptions::CommandTimeout)
113
+ @conditional = Chef::Resource::Conditional.not_if(@parent_resource, "false")
114
+ Chef::GuardInterpreter::DefaultGuardInterpreter.any_instance.stub(:shell_out).and_raise(Chef::Exceptions::CommandTimeout)
114
115
  end
115
116
 
116
117
  it 'indicates that resource convergence should continue' do
@@ -125,7 +126,7 @@ describe Chef::Resource::Conditional do
125
126
 
126
127
  describe "after running a block that returns a truthy value" do
127
128
  before do
128
- @conditional = Chef::Resource::Conditional.not_if { Object.new }
129
+ @conditional = Chef::Resource::Conditional.not_if(@parent_resource) { Object.new }
129
130
  end
130
131
 
131
132
  it "indicates that resource convergence should not continue" do
@@ -135,7 +136,7 @@ describe Chef::Resource::Conditional do
135
136
 
136
137
  describe "after running a block that returns a falsey value" do
137
138
  before do
138
- @conditional = Chef::Resource::Conditional.not_if { nil }
139
+ @conditional = Chef::Resource::Conditional.not_if(@parent_resource) { nil }
139
140
  end
140
141
 
141
142
  it "indicates that resource convergence should continue" do
@@ -143,8 +143,13 @@ describe Chef::Resource::Cron do
143
143
  lambda { @resource.month "13" }.should raise_error(RangeError)
144
144
  end
145
145
 
146
- it "should reject any weekday over 7" do
147
- lambda { @resource.weekday "8" }.should raise_error(RangeError)
146
+ describe "weekday" do
147
+ it "should reject any weekday over 7" do
148
+ lambda { @resource.weekday "8" }.should raise_error(RangeError)
149
+ end
150
+ it "should reject any symbols which don't represent day of week" do
151
+ lambda { @resource.weekday :foo }.should raise_error(RangeError)
152
+ end
148
153
  end
149
154
 
150
155
  it "should convert integer schedule values to a string" do
@@ -36,7 +36,91 @@ describe Chef::Resource::PowershellScript do
36
36
  @resource.should be_a_kind_of(Chef::Resource::PowershellScript)
37
37
  end
38
38
 
39
- context "windowsscript" do
39
+ it "should set convert_boolean_return to false by default" do
40
+ @resource.convert_boolean_return.should == false
41
+ end
42
+
43
+ it "should return the value for convert_boolean_return that was set" do
44
+ @resource.convert_boolean_return true
45
+ @resource.convert_boolean_return.should == true
46
+ @resource.convert_boolean_return false
47
+ @resource.convert_boolean_return.should == false
48
+ end
49
+
50
+ context "when using guards" do
51
+ let(:resource) { @resource }
52
+ before(:each) do
53
+ resource.stub(:run_action)
54
+ resource.stub(:updated).and_return(true)
55
+ end
56
+
57
+ it "inherits exactly the :cwd, :environment, :group, :path, :user, :umask, and :architecture attributes from a parent resource class" do
58
+ inherited_difference = Chef::Resource::PowershellScript.guard_inherited_attributes -
59
+ [:cwd, :environment, :group, :path, :user, :umask, :architecture ]
60
+
61
+ inherited_difference.should == []
62
+ end
63
+
64
+ it "should allow guard interpreter to be set to Chef::Resource::Script" do
65
+ resource.guard_interpreter(:script)
66
+ allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
67
+ resource.only_if("echo hi")
68
+ end
69
+
70
+ it "should allow guard interpreter to be set to Chef::Resource::Bash derived from Chef::Resource::Script" do
71
+ resource.guard_interpreter(:bash)
72
+ allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
73
+ resource.only_if("echo hi")
74
+ end
75
+
76
+ it "should allow guard interpreter to be set to Chef::Resource::PowershellScript derived indirectly from Chef::Resource::Script" do
77
+ resource.guard_interpreter(:powershell_script)
78
+ allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
79
+ resource.only_if("echo hi")
80
+ end
81
+
82
+ it "should enable convert_boolean_return by default for guards in the context of powershell_script when no guard params are specified" do
83
+ allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(true)
84
+ allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
85
+ {:convert_boolean_return => true, :code => "$true"}).and_return(Proc.new {})
86
+ resource.only_if("$true")
87
+ end
88
+
89
+ it "should enable convert_boolean_return by default for guards in non-Chef::Resource::Script derived resources when no guard params are specified" do
90
+ node = Chef::Node.new
91
+ run_context = Chef::RunContext.new(node, nil, nil)
92
+ file_resource = Chef::Resource::File.new('idontexist', run_context)
93
+ file_resource.guard_interpreter :powershell_script
94
+
95
+ allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
96
+ {:convert_boolean_return => true, :code => "$true"}).and_return(Proc.new {})
97
+ resource.only_if("$true")
98
+ end
99
+
100
+ it "should enable convert_boolean_return by default for guards in the context of powershell_script when guard params are specified" do
101
+ guard_parameters = {:cwd => '/etc/chef', :architecture => :x86_64}
102
+ allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
103
+ {:convert_boolean_return => true, :code => "$true"}.merge(guard_parameters)).and_return(Proc.new {})
104
+ resource.only_if("$true", guard_parameters)
105
+ end
106
+
107
+ it "should pass convert_boolean_return as true if it was specified as true in a guard parameter" do
108
+ guard_parameters = {:cwd => '/etc/chef', :convert_boolean_return => true, :architecture => :x86_64}
109
+ allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
110
+ {:convert_boolean_return => true, :code => "$true"}.merge(guard_parameters)).and_return(Proc.new {})
111
+ resource.only_if("$true", guard_parameters)
112
+ end
113
+
114
+ it "should pass convert_boolean_return as false if it was specified as true in a guard parameter" do
115
+ other_guard_parameters = {:cwd => '/etc/chef', :architecture => :x86_64}
116
+ parameters_with_boolean_disabled = other_guard_parameters.merge({:convert_boolean_return => false, :code => "$true"})
117
+ allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
118
+ parameters_with_boolean_disabled).and_return(Proc.new {})
119
+ resource.only_if("$true", parameters_with_boolean_disabled)
120
+ end
121
+ end
122
+
123
+ context "as a script running in Windows-based scripting language" do
40
124
  let(:resource_instance) { @resource }
41
125
  let(:resource_instance_name ) { @resource.command }
42
126
  let(:resource_name) { :powershell_script }
@@ -44,5 +128,4 @@ describe Chef::Resource::PowershellScript do
44
128
 
45
129
  it_should_behave_like "a Windows script resource"
46
130
  end
47
-
48
131
  end
@@ -55,4 +55,9 @@ describe Chef::Resource::Subversion do
55
55
  @svn.svn_arguments.should be_nil
56
56
  end
57
57
 
58
+ it "hides password from custom exception message" do
59
+ @svn.svn_password "l33th4x0rpa$$w0rd"
60
+ e = @svn.customize_exception(Chef::Exceptions::Exec.new "Exception with password #{@svn.svn_password}")
61
+ e.message.include?(@svn.svn_password).should be_false
62
+ end
58
63
  end
@@ -0,0 +1,74 @@
1
+ #
2
+ # Author:: Bryan McLellan <btm@loftninjas.org>
3
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ describe Chef::Resource::WindowsPackage, "initialize", :windows_only do
22
+
23
+ let(:resource) { Chef::Resource::WindowsPackage.new("solitaire.msi") }
24
+
25
+ it "returns a Chef::Resource::WindowsPackage" do
26
+ expect(resource).to be_a_kind_of(Chef::Resource::WindowsPackage)
27
+ end
28
+
29
+ it "sets the resource_name to :windows_package" do
30
+ expect(resource.resource_name).to eql(:windows_package)
31
+ end
32
+
33
+ it "sets the provider to Chef::Provider::Package::Windows" do
34
+ expect(resource.provider).to eql(Chef::Provider::Package::Windows)
35
+ end
36
+
37
+ it "supports setting installer_type" do
38
+ resource.installer_type("msi")
39
+ expect(resource.installer_type).to eql("msi")
40
+ end
41
+
42
+ # String, Integer
43
+ [ "600", 600 ].each do |val|
44
+ it "supports setting a timeout as a #{val.class}" do
45
+ resource.timeout(val)
46
+ expect(resource.timeout).to eql(val)
47
+ end
48
+ end
49
+
50
+ # String, Integer, Array
51
+ [ "42", 42, [47, 48, 49] ].each do |val|
52
+ it "supports setting an alternate return value as a #{val.class}" do
53
+ resource.returns(val)
54
+ expect(resource.returns).to eql(val)
55
+ end
56
+ end
57
+
58
+ it "coverts a source to an absolute path" do
59
+ ::File.stub(:absolute_path).and_return("c:\\Files\\frost.msi")
60
+ resource.source("frost.msi")
61
+ expect(resource.source).to eql "c:\\Files\\frost.msi"
62
+ end
63
+
64
+ it "converts slashes to backslashes in the source path" do
65
+ ::File.stub(:absolute_path).and_return("c:\\frost.msi")
66
+ resource.source("c:/frost.msi")
67
+ expect(resource.source).to eql "c:\\frost.msi"
68
+ end
69
+
70
+ it "defaults source to the resource name" do
71
+ # it's a little late to stub out File.absolute_path
72
+ expect(resource.source).to include("solitaire.msi")
73
+ end
74
+ end