chef 12.1.2-x86-mingw32 → 12.2.0.rc.1-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/lib/chef/application/client.rb +2 -2
  3. data/lib/chef/audit/audit_reporter.rb +1 -1
  4. data/lib/chef/audit/runner.rb +15 -2
  5. data/lib/chef/client.rb +1 -1
  6. data/lib/chef/config.rb +6 -4
  7. data/lib/chef/dsl/powershell.rb +29 -0
  8. data/lib/chef/exceptions.rb +18 -3
  9. data/lib/chef/formatters/doc.rb +2 -2
  10. data/lib/chef/knife/bootstrap.rb +2 -1
  11. data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
  12. data/lib/chef/knife/core/subcommand_loader.rb +13 -5
  13. data/lib/chef/knife/exec.rb +2 -1
  14. data/lib/chef/knife/ssh.rb +12 -2
  15. data/lib/chef/mixin/params_validate.rb +42 -19
  16. data/lib/chef/mixin/powershell_type_coercions.rb +82 -0
  17. data/lib/chef/mixin/windows_architecture_helper.rb +8 -0
  18. data/lib/chef/node.rb +1 -1
  19. data/lib/chef/platform/provider_mapping.rb +0 -107
  20. data/lib/chef/platform/query_helpers.rb +7 -0
  21. data/lib/chef/provider/batch.rb +2 -0
  22. data/lib/chef/provider/cron.rb +2 -0
  23. data/lib/chef/provider/cron/aix.rb +2 -0
  24. data/lib/chef/provider/cron/unix.rb +2 -0
  25. data/lib/chef/provider/deploy.rb +104 -87
  26. data/lib/chef/provider/dsc_resource.rb +157 -0
  27. data/lib/chef/provider/env.rb +2 -0
  28. data/lib/chef/provider/env/windows.rb +2 -0
  29. data/lib/chef/provider/git.rb +4 -0
  30. data/lib/chef/provider/group.rb +5 -5
  31. data/lib/chef/provider/group/dscl.rb +2 -0
  32. data/lib/chef/provider/group/groupmod.rb +2 -0
  33. data/lib/chef/provider/group/usermod.rb +2 -0
  34. data/lib/chef/provider/group/windows.rb +2 -0
  35. data/lib/chef/provider/mdadm.rb +2 -0
  36. data/lib/chef/provider/mount/windows.rb +2 -0
  37. data/lib/chef/provider/package/homebrew.rb +1 -1
  38. data/lib/chef/provider/package/openbsd.rb +49 -18
  39. data/lib/chef/provider/package/rubygems.rb +7 -2
  40. data/lib/chef/provider/powershell_script.rb +2 -0
  41. data/lib/chef/provider/service/macosx.rb +1 -2
  42. data/lib/chef/provider/user/dscl.rb +7 -1
  43. data/lib/chef/provider/user/windows.rb +2 -0
  44. data/lib/chef/providers.rb +1 -0
  45. data/lib/chef/recipe.rb +2 -0
  46. data/lib/chef/resource.rb +9 -0
  47. data/lib/chef/resource/batch.rb +2 -0
  48. data/lib/chef/resource/cron.rb +3 -3
  49. data/lib/chef/resource/deploy.rb +52 -217
  50. data/lib/chef/resource/dsc_resource.rb +83 -0
  51. data/lib/chef/resource/env.rb +2 -0
  52. data/lib/chef/resource/git.rb +1 -1
  53. data/lib/chef/resource/group.rb +2 -0
  54. data/lib/chef/resource/homebrew_package.rb +1 -1
  55. data/lib/chef/resource/lwrp_base.rb +0 -8
  56. data/lib/chef/resource/mdadm.rb +2 -0
  57. data/lib/chef/resource/mount.rb +2 -0
  58. data/lib/chef/resource/powershell_script.rb +2 -0
  59. data/lib/chef/resource/user.rb +2 -0
  60. data/lib/chef/resources.rb +1 -0
  61. data/lib/chef/run_context.rb +1 -1
  62. data/lib/chef/shell.rb +7 -5
  63. data/lib/chef/util/dsc/resource_store.rb +110 -0
  64. data/lib/chef/util/path_helper.rb +76 -0
  65. data/lib/chef/util/powershell/cmdlet.rb +41 -7
  66. data/lib/chef/util/powershell/cmdlet_result.rb +18 -3
  67. data/lib/chef/util/powershell/ps_credential.rb +38 -0
  68. data/lib/chef/version.rb +1 -1
  69. data/lib/chef/win32/api.rb +2 -0
  70. data/lib/chef/win32/api/crypto.rb +63 -0
  71. data/lib/chef/win32/api/installer.rb +1 -1
  72. data/lib/chef/win32/crypto.rb +49 -0
  73. data/lib/chef/workstation_config_loader.rb +4 -3
  74. data/spec/functional/file_content_management/deploy_strategies_spec.rb +1 -1
  75. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  76. data/spec/functional/resource/deploy_revision_spec.rb +35 -0
  77. data/spec/functional/resource/directory_spec.rb +1 -1
  78. data/spec/functional/resource/dsc_resource_spec.rb +93 -0
  79. data/spec/functional/resource/env_spec.rb +4 -3
  80. data/spec/functional/resource/file_spec.rb +1 -1
  81. data/spec/functional/resource/powershell_spec.rb +2 -1
  82. data/spec/functional/resource/remote_directory_spec.rb +1 -1
  83. data/spec/functional/resource/remote_file_spec.rb +1 -1
  84. data/spec/functional/resource/template_spec.rb +1 -1
  85. data/spec/functional/resource/user/dscl_spec.rb +1 -2
  86. data/spec/functional/resource/user/useradd_spec.rb +27 -13
  87. data/spec/functional/util/powershell/cmdlet_spec.rb +3 -3
  88. data/spec/functional/win32/crypto_spec.rb +57 -0
  89. data/spec/spec_helper.rb +3 -0
  90. data/spec/support/platform_helpers.rb +14 -0
  91. data/spec/support/shared/functional/securable_resource_with_reporting.rb +5 -5
  92. data/spec/unit/application/client_spec.rb +4 -4
  93. data/spec/unit/audit/audit_reporter_spec.rb +1 -1
  94. data/spec/unit/audit/runner_spec.rb +10 -0
  95. data/spec/unit/config_spec.rb +2 -8
  96. data/spec/unit/knife/bootstrap_spec.rb +20 -8
  97. data/spec/unit/knife/core/subcommand_loader_spec.rb +29 -29
  98. data/spec/unit/mixin/params_validate_spec.rb +75 -61
  99. data/spec/unit/mixin/powershell_type_coercions_spec.rb +72 -0
  100. data/spec/unit/platform/query_helpers_spec.rb +22 -0
  101. data/spec/unit/platform_spec.rb +0 -5
  102. data/spec/unit/provider/dsc_resource_spec.rb +84 -0
  103. data/spec/unit/provider/package/openbsd_spec.rb +105 -17
  104. data/spec/unit/provider/service/macosx_spec.rb +3 -3
  105. data/spec/unit/provider_resolver_spec.rb +132 -0
  106. data/spec/unit/recipe_spec.rb +4 -0
  107. data/spec/unit/resource/deploy_spec.rb +27 -0
  108. data/spec/unit/resource/dsc_resource_spec.rb +85 -0
  109. data/spec/unit/shell_spec.rb +1 -1
  110. data/spec/unit/util/dsc/resource_store.rb +76 -0
  111. data/spec/unit/util/powershell/ps_credential_spec.rb +37 -0
  112. data/spec/unit/workstation_config_loader_spec.rb +1 -1
  113. metadata +175 -226
@@ -339,69 +339,83 @@ describe Chef::Mixin::ParamsValidate do
339
339
  end.to raise_error(Chef::Exceptions::ValidationFailed)
340
340
  end
341
341
 
342
- it "should set and return a value, then return the same value" do
343
- value = "meow"
344
- expect(@vo.set_or_return(:test, value, {}).object_id).to eq(value.object_id)
345
- expect(@vo.set_or_return(:test, nil, {}).object_id).to eq(value.object_id)
342
+ def self.test_set_or_return_method(method)
343
+ # caller is responsible for passing in the right arg to get 'return' behavior
344
+ return_arg = method == :nillable_set_or_return ? TinyClass::NULL_ARG : nil
345
+
346
+ it "#{method} should set and return a value, then return the same value" do
347
+ value = "meow"
348
+ expect(@vo.send(method,:test, value, {}).object_id).to eq(value.object_id)
349
+ expect(@vo.send(method,:test, return_arg, {}).object_id).to eq(value.object_id)
350
+ end
351
+
352
+ it "#{method} should set and return a default value when the argument is nil, then return the same value" do
353
+ value = "meow"
354
+ expect(@vo.send(method,:test, return_arg, { :default => value }).object_id).to eq(value.object_id)
355
+ expect(@vo.send(method,:test, return_arg, {}).object_id).to eq(value.object_id)
356
+ end
357
+
358
+ it "#{method} should raise an ArgumentError when argument is nil and required is true" do
359
+ expect {
360
+ @vo.send(method,:test, return_arg, { :required => true })
361
+ }.to raise_error(ArgumentError)
362
+ end
363
+
364
+ it "#{method} should not raise an error when argument is nil and required is false" do
365
+ expect {
366
+ @vo.send(method,:test, return_arg, { :required => false })
367
+ }.not_to raise_error
368
+ end
369
+
370
+ it "#{method} should set and return @name, then return @name for foo when argument is nil" do
371
+ value = "meow"
372
+ expect(@vo.send(method,:name, value, { }).object_id).to eq(value.object_id)
373
+ expect(@vo.send(method,:foo, return_arg, { :name_attribute => true }).object_id).to eq(value.object_id)
374
+ end
375
+
376
+ it "#{method} should allow DelayedEvaluator instance to be set for value regardless of restriction" do
377
+ value = Chef::DelayedEvaluator.new{ 'test' }
378
+ @vo.send(method,:test, value, {:kind_of => Numeric})
379
+ end
380
+
381
+ it "#{method} should raise an error when delayed evaluated attribute is not valid" do
382
+ value = Chef::DelayedEvaluator.new{ 'test' }
383
+ @vo.send(method,:test, value, {:kind_of => Numeric})
384
+ expect do
385
+ @vo.send(method,:test, return_arg, {:kind_of => Numeric})
386
+ end.to raise_error(Chef::Exceptions::ValidationFailed)
387
+ end
388
+
389
+ it "#{method} should create DelayedEvaluator instance when #lazy is used" do
390
+ @vo.send(method,:delayed, @vo.lazy{ 'test' }, {})
391
+ expect(@vo.instance_variable_get(:@delayed)).to be_a(Chef::DelayedEvaluator)
392
+ end
393
+
394
+ it "#{method} should execute block on each call when DelayedEvaluator" do
395
+ value = 'fubar'
396
+ @vo.send(method,:test, @vo.lazy{ value }, {})
397
+ expect(@vo.send(method,:test, return_arg, {})).to eq('fubar')
398
+ value = 'foobar'
399
+ expect(@vo.send(method,:test, return_arg, {})).to eq('foobar')
400
+ value = 'fauxbar'
401
+ expect(@vo.send(method,:test, return_arg, {})).to eq('fauxbar')
402
+ end
403
+
404
+ it "#{method} should not evaluate non DelayedEvaluator instances" do
405
+ value = lambda{ 'test' }
406
+ @vo.send(method,:test, value, {})
407
+ expect(@vo.send(method,:test, return_arg, {}).object_id).to eq(value.object_id)
408
+ expect(@vo.send(method,:test, return_arg, {})).to be_a(Proc)
409
+ end
346
410
  end
347
411
 
348
- it "should set and return a default value when the argument is nil, then return the same value" do
349
- value = "meow"
350
- expect(@vo.set_or_return(:test, nil, { :default => value }).object_id).to eq(value.object_id)
351
- expect(@vo.set_or_return(:test, nil, {}).object_id).to eq(value.object_id)
352
- end
353
-
354
- it "should raise an ArgumentError when argument is nil and required is true" do
355
- expect {
356
- @vo.set_or_return(:test, nil, { :required => true })
357
- }.to raise_error(ArgumentError)
358
- end
359
-
360
- it "should not raise an error when argument is nil and required is false" do
361
- expect {
362
- @vo.set_or_return(:test, nil, { :required => false })
363
- }.not_to raise_error
364
- end
365
-
366
- it "should set and return @name, then return @name for foo when argument is nil" do
367
- value = "meow"
368
- expect(@vo.set_or_return(:name, value, { }).object_id).to eq(value.object_id)
369
- expect(@vo.set_or_return(:foo, nil, { :name_attribute => true }).object_id).to eq(value.object_id)
370
- end
412
+ test_set_or_return_method(:set_or_return)
413
+ test_set_or_return_method(:nillable_set_or_return)
371
414
 
372
- it "should allow DelayedEvaluator instance to be set for value regardless of restriction" do
373
- value = Chef::DelayedEvaluator.new{ 'test' }
374
- @vo.set_or_return(:test, value, {:kind_of => Numeric})
415
+ it "nillable_set_or_return supports nilling values" do
416
+ expect(@vo.nillable_set_or_return(:test, "meow", {})).to eq("meow")
417
+ expect(@vo.nillable_set_or_return(:test, TinyClass::NULL_ARG, {})).to eq("meow")
418
+ expect(@vo.nillable_set_or_return(:test, nil, {})).to be_nil
419
+ expect(@vo.nillable_set_or_return(:test, TinyClass::NULL_ARG, {})).to be_nil
375
420
  end
376
-
377
- it "should raise an error when delayed evaluated attribute is not valid" do
378
- value = Chef::DelayedEvaluator.new{ 'test' }
379
- @vo.set_or_return(:test, value, {:kind_of => Numeric})
380
- expect do
381
- @vo.set_or_return(:test, nil, {:kind_of => Numeric})
382
- end.to raise_error(Chef::Exceptions::ValidationFailed)
383
- end
384
-
385
- it "should create DelayedEvaluator instance when #lazy is used" do
386
- @vo.set_or_return(:delayed, @vo.lazy{ 'test' }, {})
387
- expect(@vo.instance_variable_get(:@delayed)).to be_a(Chef::DelayedEvaluator)
388
- end
389
-
390
- it "should execute block on each call when DelayedEvaluator" do
391
- value = 'fubar'
392
- @vo.set_or_return(:test, @vo.lazy{ value }, {})
393
- expect(@vo.set_or_return(:test, nil, {})).to eq('fubar')
394
- value = 'foobar'
395
- expect(@vo.set_or_return(:test, nil, {})).to eq('foobar')
396
- value = 'fauxbar'
397
- expect(@vo.set_or_return(:test, nil, {})).to eq('fauxbar')
398
- end
399
-
400
- it "should not evaluate non DelayedEvaluator instances" do
401
- value = lambda{ 'test' }
402
- @vo.set_or_return(:test, value, {})
403
- expect(@vo.set_or_return(:test, nil, {}).object_id).to eq(value.object_id)
404
- expect(@vo.set_or_return(:test, nil, {})).to be_a(Proc)
405
- end
406
-
407
421
  end
@@ -0,0 +1,72 @@
1
+ #
2
+ # Author:: Jay Mundrawala (<jdm@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 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
+ require 'chef/mixin/powershell_type_coercions'
21
+ require 'base64'
22
+
23
+ class Chef::PSTypeTester
24
+ include Chef::Mixin::PowershellTypeCoercions
25
+ end
26
+
27
+ describe Chef::Mixin::PowershellTypeCoercions do
28
+ let (:test_class) { Chef::PSTypeTester.new }
29
+
30
+ describe '#translate_type' do
31
+ it 'should single quote a string' do
32
+ expect(test_class.translate_type('foo')).to eq("'foo'")
33
+ end
34
+
35
+ ["'", '"', '#', '`'].each do |c|
36
+ it "should base64 encode a string that contains #{c}" do
37
+ expect(test_class.translate_type("#{c}")).to match(Base64.strict_encode64(c))
38
+ end
39
+ end
40
+
41
+ it 'should not quote an integer' do
42
+ expect(test_class.translate_type(123)).to eq('123')
43
+ end
44
+
45
+ it 'should not quote a floating point number' do
46
+ expect(test_class.translate_type(123.4)).to eq('123.4')
47
+ end
48
+
49
+ it 'should return $false when an instance of FalseClass is provided' do
50
+ expect(test_class.translate_type(false)).to eq('$false')
51
+ end
52
+
53
+ it 'should return $true when an instance of TrueClass is provided' do
54
+ expect(test_class.translate_type(true)).to eq('$true')
55
+ end
56
+
57
+ it 'should translate all members of a hash and wrap them in @{} separated by ;' do
58
+ expect(test_class.translate_type({"a" => 1, "b" => 1.2, "c" => false, "d" => true
59
+ })).to eq("@{a=1;b=1.2;c=$false;d=$true}")
60
+ end
61
+
62
+ it 'should translat all members of an array and them by a ,' do
63
+ expect(test_class.translate_type([true, false])).to eq('@($true,$false)')
64
+ end
65
+
66
+ it 'should fall back :to_psobject if we have not defined at explicit rule' do
67
+ ps_obj = double("PSObject")
68
+ expect(ps_obj).to receive(:to_psobject).and_return('$true')
69
+ expect(test_class.translate_type(ps_obj)).to eq('($true)')
70
+ end
71
+ end
72
+ end
@@ -53,3 +53,25 @@ describe 'Chef::Platform#supports_dsc?' do
53
53
  end
54
54
  end
55
55
  end
56
+
57
+ describe 'Chef::Platform#supports_dsc_invoke_resource?' do
58
+ it 'returns false if powershell is not present' do
59
+ node = Chef::Node.new
60
+ expect(Chef::Platform.supports_dsc_invoke_resource?(node)).to be_falsey
61
+ end
62
+
63
+ ['1.0', '2.0', '3.0', '4.0', '5.0.10017.9'].each do |version|
64
+ it "returns false for Powershell #{version}" do
65
+ node = Chef::Node.new
66
+ node.automatic[:languages][:powershell][:version] = version
67
+ expect(Chef::Platform.supports_dsc_invoke_resource?(node)).to be_falsey
68
+ end
69
+ end
70
+
71
+ it "returns true for Powershell 5.0.10018.0" do
72
+ node = Chef::Node.new
73
+ node.automatic[:languages][:powershell][:version] = "5.0.10018.0"
74
+ expect(Chef::Platform.supports_dsc_invoke_resource?(node)).to be_truthy
75
+ end
76
+ end
77
+
@@ -20,8 +20,6 @@ require 'spec_helper'
20
20
 
21
21
  describe "Chef::Platform supports" do
22
22
  [
23
- :mac_os_x,
24
- :mac_os_x_server,
25
23
  :freebsd,
26
24
  :ubuntu,
27
25
  :debian,
@@ -34,9 +32,6 @@ describe "Chef::Platform supports" do
34
32
  :gentoo,
35
33
  :arch,
36
34
  :solaris,
37
- :mswin,
38
- :mingw32,
39
- :windows,
40
35
  :gcel,
41
36
  :ibm_powerkvm
42
37
  ].each do |platform|
@@ -0,0 +1,84 @@
1
+ #
2
+ # Author:: Jay Mundrawala (<jdm@chef.io>)
3
+ #
4
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'chef'
21
+ require 'spec_helper'
22
+
23
+ describe Chef::Provider::DscResource do
24
+ let (:events) { Chef::EventDispatch::Dispatcher.new }
25
+ let (:run_context) { Chef::RunContext.new(node, {}, events) }
26
+ let (:resource) { Chef::Resource::DscResource.new("dscresource", run_context) }
27
+ let (:provider) do
28
+ Chef::Provider::DscResource.new(resource, run_context)
29
+ end
30
+
31
+ context 'when Powershell does not support Invoke-DscResource' do
32
+ let (:node) {
33
+ node = Chef::Node.new
34
+ node.automatic[:languages][:powershell][:version] = '4.0'
35
+ node
36
+ }
37
+
38
+ it 'raises a NoProviderAvailable exception' do
39
+ expect(provider).not_to receive(:meta_configuration)
40
+ expect{provider.run_action(:run)}.to raise_error(
41
+ Chef::Exceptions::NoProviderAvailable, /5\.0\.10018\.0/)
42
+ end
43
+ end
44
+
45
+ context 'when Powershell supports Invoke-DscResource' do
46
+ let (:node) {
47
+ node = Chef::Node.new
48
+ node.automatic[:languages][:powershell][:version] = '5.0.10018.0'
49
+ node
50
+ }
51
+
52
+ context 'when RefreshMode is not set to Disabled' do
53
+ let (:meta_configuration) { {'RefreshMode' => 'AnythingElse'}}
54
+
55
+ it 'raises an exception' do
56
+ expect(provider).to receive(:meta_configuration).and_return(
57
+ meta_configuration)
58
+ expect { provider.run_action(:run) }.to raise_error(
59
+ Chef::Exceptions::NoProviderAvailable, /Disabled/)
60
+ end
61
+ end
62
+
63
+ context 'when RefreshMode is set to Disabled' do
64
+ let (:meta_configuration) { {'RefreshMode' => 'Disabled'}}
65
+
66
+ it 'does not update the resource if it is up to date' do
67
+ expect(provider).to receive(:meta_configuration).and_return(
68
+ meta_configuration)
69
+ expect(provider).to receive(:test_resource).and_return(true)
70
+ provider.run_action(:run)
71
+ expect(resource).not_to be_updated
72
+ end
73
+
74
+ it 'converges the resource if it is not up to date' do
75
+ expect(provider).to receive(:meta_configuration).and_return(
76
+ meta_configuration)
77
+ expect(provider).to receive(:test_resource).and_return(false)
78
+ expect(provider).to receive(:set_resource)
79
+ provider.run_action(:run)
80
+ expect(resource).to be_updated
81
+ end
82
+ end
83
+ end
84
+ end
@@ -21,28 +21,116 @@ require 'ostruct'
21
21
 
22
22
  describe Chef::Provider::Package::Openbsd do
23
23
 
24
+ let(:node) do
25
+ node = Chef::Node.new
26
+ node.default['kernel'] = {'name' => 'OpenBSD', 'release' => '5.5', 'machine' => 'amd64'}
27
+ node
28
+ end
29
+
30
+ let (:provider) do
31
+ events = Chef::EventDispatch::Dispatcher.new
32
+ run_context = Chef::RunContext.new(node, {}, events)
33
+ Chef::Provider::Package::Openbsd.new(new_resource, run_context)
34
+ end
35
+
36
+ let(:new_resource) { Chef::Resource::Package.new(name)}
37
+
24
38
  before(:each) do
25
- @node = Chef::Node.new
26
- @node.default['kernel'] = {'name' => 'OpenBSD', 'release' => '5.5', 'machine' => 'amd64'}
27
- @events = Chef::EventDispatch::Dispatcher.new
28
- @run_context = Chef::RunContext.new(@node, {}, @events)
29
39
  ENV['PKG_PATH'] = nil
30
40
  end
31
41
 
32
42
  describe "install a package" do
33
- before do
34
- @name = 'ihavetoes'
35
- @new_resource = Chef::Resource::Package.new(@name)
36
- @current_resource = Chef::Resource::Package.new(@name)
37
- @provider = Chef::Provider::Package::Openbsd.new(@new_resource, @run_context)
38
- @provider.current_resource = @current_resource
39
- end
40
- it "should run the installation command" do
41
- expect(@provider).to receive(:shell_out!).with(
42
- "pkg_add -r #{@name}",
43
- {:env => {"PKG_PATH" => "http://ftp.OpenBSD.org/pub/OpenBSD/5.5/packages/amd64/"}}
44
- ) {OpenStruct.new :status => true}
45
- @provider.install_package(@name, nil)
43
+ let(:name) { 'ihavetoes' }
44
+ let(:version) {'0.0'}
45
+
46
+ context 'when not already installed' do
47
+ before do
48
+ allow(provider).to receive(:shell_out!).with("pkg_info -e \"#{name}->0\"", anything()).and_return(instance_double('shellout', :stdout => ''))
49
+ end
50
+
51
+ context 'when there is a single candidate' do
52
+
53
+ context 'when installing from source' do
54
+ it 'should run the installation command' do
55
+ pending('Installing from source is not supported yet')
56
+ # This is a consequence of load_current_resource being called before define_resource_requirements
57
+ # It can be deleted once an implementation is provided
58
+ allow(provider).to receive(:shell_out!).with("pkg_info -I \"#{name}\"", anything()).and_return(
59
+ instance_double('shellout', :stdout => "#{name}-#{version}\n"))
60
+ new_resource.source('/some/path/on/disk.tgz')
61
+ provider.run_action(:install)
62
+ end
63
+ end
64
+
65
+ context 'when source is not provided' do
66
+ it 'should run the installation command' do
67
+ expect(provider).to receive(:shell_out!).with("pkg_info -I \"#{name}\"", anything()).and_return(
68
+ instance_double('shellout', :stdout => "#{name}-#{version}\n"))
69
+ expect(provider).to receive(:shell_out!).with(
70
+ "pkg_add -r #{name}-#{version}",
71
+ {:env => {"PKG_PATH" => "http://ftp.OpenBSD.org/pub/OpenBSD/5.5/packages/amd64/"}}
72
+ ) {OpenStruct.new :status => true}
73
+ provider.run_action(:install)
74
+ end
75
+ end
76
+ end
77
+
78
+ context 'when there are multiple candidates' do
79
+ let(:flavor_a) { 'flavora' }
80
+ let(:flavor_b) { 'flavorb' }
81
+
82
+ context 'if no version is specified' do
83
+ it 'should raise an exception' do
84
+ expect(provider).to receive(:shell_out!).with("pkg_info -I \"#{name}\"", anything()).and_return(
85
+ instance_double('shellout', :stdout => "#{name}-#{version}-#{flavor_a}\n#{name}-#{version}-#{flavor_b}\n"))
86
+ expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /multiple matching candidates/)
87
+ end
88
+ end
89
+
90
+ context 'if a flavor is specified' do
91
+
92
+ let(:flavor) { 'flavora' }
93
+ let(:package_name) {'ihavetoes' }
94
+ let(:name) { "#{package_name}--#{flavor}" }
95
+
96
+ context 'if no version is specified' do
97
+ it 'should run the installation command' do
98
+ expect(provider).to receive(:shell_out!).with("pkg_info -e \"#{package_name}->0\"", anything()).and_return(instance_double('shellout', :stdout => ''))
99
+ expect(provider).to receive(:shell_out!).with("pkg_info -I \"#{name}\"", anything()).and_return(
100
+ instance_double('shellout', :stdout => "#{name}-#{version}-#{flavor}\n"))
101
+ expect(provider).to receive(:shell_out!).with(
102
+ "pkg_add -r #{name}-#{version}-#{flavor}",
103
+ {:env => {"PKG_PATH" => "http://ftp.OpenBSD.org/pub/OpenBSD/5.5/packages/amd64/"}}
104
+ ) {OpenStruct.new :status => true}
105
+ provider.run_action(:install)
106
+ end
107
+ end
108
+
109
+ context 'if a version is specified' do
110
+ it 'runs the installation command' do
111
+ pending('Specifying both a version and flavor is not supported')
112
+ new_resource.version(version)
113
+ allow(provider).to receive(:shell_out!).with(/pkg_info -e/, anything()).and_return(instance_double('shellout', :stdout => ''))
114
+ allow(provider).to receive(:candidate_version).and_return("#{package_name}-#{version}-#{flavor}")
115
+ provider.run_action(:install)
116
+ end
117
+ end
118
+ end
119
+
120
+ context 'if a version is specified' do
121
+ it 'should use the flavor from the version' do
122
+ expect(provider).to receive(:shell_out!).with("pkg_info -I \"#{name}-#{version}-#{flavor_b}\"", anything()).and_return(
123
+ instance_double('shellout', :stdout => "#{name}-#{version}-#{flavor_a}\n"))
124
+
125
+ new_resource.version("#{version}-#{flavor_b}")
126
+ expect(provider).to receive(:shell_out!).with(
127
+ "pkg_add -r #{name}-#{version}-#{flavor_b}",
128
+ {:env => {"PKG_PATH" => "http://ftp.OpenBSD.org/pub/OpenBSD/5.5/packages/amd64/"}}
129
+ ) {OpenStruct.new :status => true}
130
+ provider.run_action(:install)
131
+ end
132
+ end
133
+ end
46
134
  end
47
135
  end
48
136