chef 11.16.4-x86-mingw32 → 11.18.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -2
  3. data/lib/chef/api_client.rb +1 -1
  4. data/lib/chef/chef_fs/chef_fs_data_store.rb +3 -2
  5. data/lib/chef/chef_fs/command_line.rb +3 -2
  6. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +5 -1
  7. data/lib/chef/chef_fs/file_system/acl_entry.rb +2 -1
  8. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +2 -1
  9. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +3 -2
  10. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +5 -4
  11. data/lib/chef/config_fetcher.rb +1 -1
  12. data/lib/chef/cookbook/cookbook_version_loader.rb +4 -4
  13. data/lib/chef/cookbook/metadata.rb +1 -1
  14. data/lib/chef/cookbook_version.rb +2 -2
  15. data/lib/chef/data_bag.rb +1 -1
  16. data/lib/chef/data_bag_item.rb +1 -1
  17. data/lib/chef/encrypted_data_bag_item/decryptor.rb +3 -3
  18. data/lib/chef/environment.rb +1 -1
  19. data/lib/chef/exceptions.rb +19 -2
  20. data/lib/chef/json_compat.rb +64 -45
  21. data/lib/chef/knife/bootstrap.rb +2 -2
  22. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  23. data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -2
  24. data/lib/chef/knife/bootstrap/chef-aix.erb +2 -2
  25. data/lib/chef/knife/bootstrap/chef-full.erb +2 -2
  26. data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -2
  27. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
  28. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +2 -2
  29. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +2 -2
  30. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  31. data/lib/chef/knife/cookbook_site_install.rb +34 -10
  32. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  33. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  34. data/lib/chef/knife/cookbook_site_share.rb +2 -2
  35. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  36. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  37. data/lib/chef/knife/core/subcommand_loader.rb +24 -0
  38. data/lib/chef/knife/deps.rb +3 -2
  39. data/lib/chef/node.rb +1 -1
  40. data/lib/chef/provider/deploy/revision.rb +1 -1
  41. data/lib/chef/provider/dsc_script.rb +32 -5
  42. data/lib/chef/provider/env.rb +25 -10
  43. data/lib/chef/provider/remote_file/cache_control_data.rb +1 -1
  44. data/lib/chef/resource.rb +1 -1
  45. data/lib/chef/resource/dsc_script.rb +2 -16
  46. data/lib/chef/resource_collection.rb +1 -1
  47. data/lib/chef/resource_reporter.rb +3 -3
  48. data/lib/chef/role.rb +1 -1
  49. data/lib/chef/run_list.rb +1 -1
  50. data/lib/chef/user.rb +1 -1
  51. data/lib/chef/util/dsc/local_configuration_manager.rb +15 -11
  52. data/lib/chef/util/powershell/cmdlet_result.rb +2 -2
  53. data/lib/chef/version.rb +1 -2
  54. data/spec/data/bootstrap/test-hints.erb +1 -1
  55. data/spec/data/bootstrap/test.erb +1 -1
  56. data/spec/functional/knife/cookbook_delete_spec.rb +3 -3
  57. data/spec/functional/knife/exec_spec.rb +1 -1
  58. data/spec/functional/resource/dsc_script_spec.rb +92 -47
  59. data/spec/functional/resource/env_spec.rb +3 -4
  60. data/spec/functional/util/powershell/cmdlet_spec.rb +1 -2
  61. data/spec/integration/knife/chef_fs_data_store_spec.rb +1 -1
  62. data/spec/integration/knife/chef_repo_path_spec.rb +6 -1
  63. data/spec/integration/knife/chef_repository_file_system_spec.rb +1 -1
  64. data/spec/integration/knife/chefignore_spec.rb +1 -1
  65. data/spec/integration/knife/common_options_spec.rb +1 -1
  66. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +1 -1
  67. data/spec/integration/knife/delete_spec.rb +1 -1
  68. data/spec/integration/knife/deps_spec.rb +1 -1
  69. data/spec/integration/knife/diff_spec.rb +3 -3
  70. data/spec/integration/knife/download_spec.rb +3 -3
  71. data/spec/integration/knife/list_spec.rb +1 -1
  72. data/spec/integration/knife/raw_spec.rb +11 -1
  73. data/spec/integration/knife/redirection_spec.rb +1 -1
  74. data/spec/integration/knife/serve_spec.rb +1 -1
  75. data/spec/integration/knife/show_spec.rb +1 -1
  76. data/spec/integration/knife/upload_spec.rb +9 -9
  77. data/spec/spec_helper.rb +6 -0
  78. data/spec/support/shared/integration/integration_helper.rb +1 -2
  79. data/spec/support/shared/shared_examples.rb +10 -0
  80. data/spec/tiny_server.rb +2 -1
  81. data/spec/unit/api_client_spec.rb +3 -3
  82. data/spec/unit/chef_fs/data_handler/group_handler_spec.rb +63 -0
  83. data/spec/unit/config_fetcher_spec.rb +1 -1
  84. data/spec/unit/cookbook/metadata_spec.rb +7 -3
  85. data/spec/unit/cookbook_loader_spec.rb +1 -1
  86. data/spec/unit/cookbook_version_spec.rb +4 -0
  87. data/spec/unit/data_bag_item_spec.rb +5 -1
  88. data/spec/unit/data_bag_spec.rb +5 -1
  89. data/spec/unit/deprecation_spec.rb +1 -1
  90. data/spec/unit/encrypted_data_bag_item_spec.rb +14 -7
  91. data/spec/unit/environment_spec.rb +7 -3
  92. data/spec/unit/exceptions_spec.rb +6 -0
  93. data/spec/unit/json_compat_spec.rb +58 -17
  94. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +0 -1
  95. data/spec/unit/knife/cookbook_site_download_spec.rb +2 -1
  96. data/spec/unit/knife/cookbook_site_install_spec.rb +161 -116
  97. data/spec/unit/knife/cookbook_site_share_spec.rb +6 -6
  98. data/spec/unit/knife/core/bootstrap_context_spec.rb +2 -2
  99. data/spec/unit/knife/core/subcommand_loader_spec.rb +66 -1
  100. data/spec/unit/knife/data_bag_from_file_spec.rb +1 -2
  101. data/spec/unit/node_spec.rb +4 -0
  102. data/spec/unit/provider/dsc_script_spec.rb +134 -105
  103. data/spec/unit/provider/env/windows_spec.rb +2 -2
  104. data/spec/unit/provider/env_spec.rb +76 -11
  105. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +1 -1
  106. data/spec/unit/resource/dsc_script_spec.rb +0 -29
  107. data/spec/unit/resource_collection_spec.rb +5 -1
  108. data/spec/unit/resource_reporter_spec.rb +3 -3
  109. data/spec/unit/resource_spec.rb +5 -1
  110. data/spec/unit/role_spec.rb +4 -0
  111. data/spec/unit/run_list_spec.rb +5 -1
  112. data/spec/unit/user_spec.rb +5 -1
  113. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +15 -10
  114. metadata +11 -9
@@ -58,20 +58,22 @@ class Chef
58
58
  # ==== Returns
59
59
  # <true>:: If a change is required
60
60
  # <false>:: If a change is not required
61
- def compare_value
61
+ def requires_modify_or_create?
62
62
  if @new_resource.delim
63
63
  #e.g. check for existing value within PATH
64
- not @current_resource.value.split(@new_resource.delim).any? do |val|
65
- val == @new_resource.value
64
+ not new_values.all? do |val|
65
+ current_values.include? val
66
66
  end
67
67
  else
68
68
  @new_resource.value != @current_resource.value
69
69
  end
70
70
  end
71
71
 
72
+ alias_method :compare_value, :requires_modify_or_create?
73
+
72
74
  def action_create
73
75
  if @key_exists
74
- if compare_value
76
+ if requires_modify_or_create?
75
77
  modify_env
76
78
  Chef::Log.info("#{@new_resource} altered")
77
79
  @new_resource.updated_by_last_action(true)
@@ -91,13 +93,14 @@ class Chef
91
93
  # after we removed the element.
92
94
  def delete_element
93
95
  return false unless @new_resource.delim #no delim: delete the key
94
- if compare_value
96
+ needs_delete = new_values.any? { |v| current_values.include?(v) }
97
+ if !needs_delete
95
98
  Chef::Log.debug("#{@new_resource} element '#{@new_resource.value}' does not exist")
96
99
  return true #do not delete the key
97
100
  else
98
101
  new_value =
99
- @current_resource.value.split(@new_resource.delim).select { |item|
100
- item != @new_resource.value
102
+ current_values.select { |item|
103
+ not new_values.include?(item)
101
104
  }.join(@new_resource.delim)
102
105
 
103
106
  if new_value.empty?
@@ -122,7 +125,7 @@ class Chef
122
125
 
123
126
  def action_modify
124
127
  if @key_exists
125
- if compare_value
128
+ if requires_modify_or_create?
126
129
  modify_env
127
130
  Chef::Log.info("#{@new_resource} modified")
128
131
  @new_resource.updated_by_last_action(true)
@@ -142,11 +145,23 @@ class Chef
142
145
 
143
146
  def modify_env
144
147
  if @new_resource.delim
145
- #e.g. add to PATH
146
- @new_resource.value << @new_resource.delim << @current_resource.value
148
+ values = new_values.reject do |v|
149
+ current_values.include?(v)
150
+ end
151
+ @new_resource.value((values + [@current_resource.value]).join(@new_resource.delim))
147
152
  end
148
153
  create_env
149
154
  end
155
+
156
+ # Returns the current values to split by delimiter
157
+ def current_values
158
+ @current_values ||= @current_resource.value.split(@new_resource.delim)
159
+ end
160
+
161
+ # Returns the new values to split by delimiter
162
+ def new_values
163
+ @new_values ||= @new_resource.value.split(@new_resource.delim)
164
+ end
150
165
  end
151
166
  end
152
167
  end
@@ -140,7 +140,7 @@ class Chef
140
140
 
141
141
  def load_data
142
142
  Chef::JSONCompat.from_json(load_json_data)
143
- rescue Chef::Exceptions::FileNotFound, FFI_Yajl::ParseError, JSON::ParserError
143
+ rescue Chef::Exceptions::FileNotFound, FFI_Yajl::ParseError, Chef::Exceptions::JSON::ParseError
144
144
  false
145
145
  end
146
146
 
@@ -544,7 +544,7 @@ F
544
544
  # Serialize this object as a hash
545
545
  def to_json(*a)
546
546
  results = as_json
547
- results.to_json(*a)
547
+ Chef::JSONCompat.to_json(results, *a)
548
548
  end
549
549
 
550
550
  def to_hash
@@ -28,12 +28,8 @@ class Chef
28
28
  super
29
29
  @allowed_actions.push(:run)
30
30
  @action = :run
31
- if(run_context && Chef::Platform.supports_dsc?(run_context.node))
32
- @provider = Chef::Provider::DscScript
33
- else
34
- raise Chef::Exceptions::NoProviderAvailable,
35
- "#{powershell_info_str(run_context)}\nPowershell 4.0 or higher was not detected on your system and is required to use the dsc_script resource."
36
- end
31
+ @provider = Chef::Provider::DscScript
32
+ @resource_name = :dsc_script
37
33
  end
38
34
 
39
35
  def code(arg=nil)
@@ -125,16 +121,6 @@ class Chef
125
121
  :kind_of => [ Integer ]
126
122
  )
127
123
  end
128
-
129
- private
130
-
131
- def powershell_info_str(run_context)
132
- if run_context && run_context.node[:languages] && run_context.node[:languages][:powershell]
133
- install_info = "Powershell #{run_context.node[:languages][:powershell][:version]} was found on the system."
134
- else
135
- install_info = 'Powershell was not found.'
136
- end
137
- end
138
124
  end
139
125
  end
140
126
  end
@@ -198,7 +198,7 @@ class Chef
198
198
  'json_class' => self.class.name,
199
199
  'instance_vars' => instance_vars
200
200
  }
201
- results.to_json(*a)
201
+ Chef::JSONCompat.to_json(results, *a)
202
202
  end
203
203
 
204
204
  def self.json_create(o)
@@ -230,7 +230,7 @@ class Chef
230
230
  resource_history_url = "reports/nodes/#{node_name}/runs/#{run_id}"
231
231
  Chef::Log.info("Sending resource update report (run-id: #{run_id})")
232
232
  Chef::Log.debug run_data.inspect
233
- compressed_data = encode_gzip(run_data.to_json)
233
+ compressed_data = encode_gzip(Chef::JSONCompat.to_json(run_data))
234
234
  Chef::Log.debug("Sending compressed run data...")
235
235
  # Since we're posting compressed data we can not directly call post_rest which expects JSON
236
236
  reporting_url = @rest_client.create_url(resource_history_url)
@@ -273,7 +273,7 @@ class Chef
273
273
  resource_record.for_json
274
274
  end
275
275
  run_data["status"] = @status
276
- run_data["run_list"] = @run_status.node.run_list.to_json
276
+ run_data["run_list"] = Chef::JSONCompat.to_json(@run_status.node.run_list)
277
277
  run_data["total_res_count"] = @total_res_count.to_s
278
278
  run_data["data"] = {}
279
279
  run_data["start_time"] = start_time.to_s
@@ -283,7 +283,7 @@ class Chef
283
283
  exception_data = {}
284
284
  exception_data["class"] = exception.inspect
285
285
  exception_data["message"] = exception.message
286
- exception_data["backtrace"] = exception.backtrace.to_json
286
+ exception_data["backtrace"] = Chef::JSONCompat.to_json(exception.backtrace)
287
287
  exception_data["description"] = @error_descriptions
288
288
  run_data["data"]["exception"] = exception_data
289
289
  end
@@ -143,7 +143,7 @@ class Chef
143
143
 
144
144
  # Serialize this object as a hash
145
145
  def to_json(*a)
146
- to_hash.to_json(*a)
146
+ Chef::JSONCompat.to_json(to_hash, *a)
147
147
  end
148
148
 
149
149
  def update_from!(o)
@@ -86,7 +86,7 @@ class Chef
86
86
  end
87
87
 
88
88
  def to_json(*args)
89
- to_a.map { |item| item.to_s}.to_json(*args)
89
+ Chef::JSONCompat.to_json(to_a.map { |item| item.to_s}, *args)
90
90
  end
91
91
 
92
92
  def empty?
@@ -73,7 +73,7 @@ class Chef
73
73
  end
74
74
 
75
75
  def to_json(*a)
76
- to_hash.to_json(*a)
76
+ Chef::JSONCompat.to_json(to_hash, *a)
77
77
  end
78
78
 
79
79
  def destroy
@@ -29,7 +29,7 @@ class Chef::Util::DSC
29
29
 
30
30
  def test_configuration(configuration_document)
31
31
  status = run_configuration_cmdlet(configuration_document)
32
- handle_what_if_exception!(status.stderr) unless status.succeeded?
32
+ log_what_if_exception(status.stderr) unless status.succeeded?
33
33
  configuration_update_required?(status.return_value)
34
34
  end
35
35
 
@@ -78,18 +78,22 @@ $ProgressPreference = 'SilentlyContinue';start-dscconfiguration -path #{@configu
78
78
  EOH
79
79
  end
80
80
 
81
- def handle_what_if_exception!(what_if_exception_output)
82
- if what_if_exception_output.gsub(/\s+/, ' ') =~ /A parameter cannot be found that matches parameter name 'Whatif'/i
83
- # LCM returns an error if any of the resources do not support the opptional What-If
84
- Chef::Log::warn("Received error while testing configuration due to resource not supporting 'WhatIf'")
85
- elsif output_has_dsc_module_failure?(what_if_exception_output)
86
- Chef::Log::warn("Received error while testing configuration due to a module for an imported resource possibly not being fully installed:\n#{what_if_exception_output.gsub(/\s+/, ' ')}")
87
- else
88
- raise Chef::Exceptions::PowershellCmdletException, "Powershell Cmdlet failed: #{what_if_exception_output.gsub(/\s+/, ' ')}"
89
- end
81
+ def log_what_if_exception(what_if_exception_output)
82
+ if whatif_not_supported?(what_if_exception_output)
83
+ # LCM returns an error if any of the resources do not support the opptional What-If
84
+ Chef::Log::warn("Received error while testing configuration due to resource not supporting 'WhatIf'")
85
+ elsif dsc_module_import_failure?(what_if_exception_output)
86
+ Chef::Log::warn("Received error while testing configuration due to a module for an imported resource possibly not being fully installed:\n#{what_if_exception_output.gsub(/\s+/, ' ')}")
87
+ else
88
+ Chef::Log::warn("Received error while testing configuration:\n#{what_if_exception_output.gsub(/\s+/, ' ')}")
89
+ end
90
+ end
91
+
92
+ def whatif_not_supported?(what_if_exception_output)
93
+ !! (what_if_exception_output.gsub(/[\r\n]+/, '').gsub(/\s+/, ' ') =~ /A parameter cannot be found that matches parameter name 'Whatif'/i)
90
94
  end
91
95
 
92
- def output_has_dsc_module_failure?(what_if_output)
96
+ def dsc_module_import_failure?(what_if_output)
93
97
  !! (what_if_output =~ /\sCimException/ &&
94
98
  what_if_output =~ /ProviderOperationExecutionFailure/ &&
95
99
  what_if_output =~ /\smodule\s+is\s+installed/)
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'json'
19
+ require 'chef/json_compat'
20
20
 
21
21
  class Chef::Util::Powershell
22
22
  class CmdletResult
@@ -33,7 +33,7 @@ class Chef::Util::Powershell
33
33
 
34
34
  def return_value
35
35
  if output_format == :object
36
- JSON.parse(@status.stdout)
36
+ Chef::JSONCompat.parse(@status.stdout)
37
37
  else
38
38
  @status.stdout
39
39
  end
@@ -1,4 +1,3 @@
1
-
2
1
  # Author:: Daniel DeLeo (<dan@opscode.com>)
3
2
  # Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
4
3
  # License:: Apache License, Version 2.0
@@ -17,7 +16,7 @@
17
16
 
18
17
  class Chef
19
18
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
20
- VERSION = '11.16.4'
19
+ VERSION = '11.18.0'
21
20
  end
22
21
 
23
22
  # NOTE: the Chef::Version class is defined in version_class.rb
@@ -6,7 +6,7 @@ mkdir -p /etc/chef/ohai/hints
6
6
  <% @chef_config[:knife][:hints].each do |name, hash| -%>
7
7
  (
8
8
  cat <<'EOP'
9
- <%= hash.to_json %>
9
+ <%= Chef::JSONCompat.to_json(hash) %>
10
10
  EOP
11
11
  ) > /etc/chef/ohai/hints/<%= name %>.json
12
12
  <% end -%>
@@ -1 +1 @@
1
- <%= first_boot.to_json %>
1
+ <%= Chef::JSONCompat.to_json(first_boot) %>
@@ -47,7 +47,7 @@ describe Chef::Knife::CookbookDelete do
47
47
  Chef::Log.level = :debug
48
48
 
49
49
  @knife.name_args = %w{no-such-cookbook}
50
- @api.get("/cookbooks/no-such-cookbook", 404, {'error'=>'dear Tim, no. -Sent from my iPad'}.to_json)
50
+ @api.get("/cookbooks/no-such-cookbook", 404, Chef::JSONCompat.to_json({'error'=>'dear Tim, no. -Sent from my iPad'}))
51
51
  end
52
52
 
53
53
  it "logs an error and exits" do
@@ -62,7 +62,7 @@ describe Chef::Knife::CookbookDelete do
62
62
  before do
63
63
  @knife.name_args = %w{obsolete-cookbook}
64
64
  @cookbook_list = {'obsolete-cookbook' => { 'versions' => ['version' => '1.0.0']} }
65
- @api.get("/cookbooks/obsolete-cookbook", 200, @cookbook_list.to_json)
65
+ @api.get("/cookbooks/obsolete-cookbook", 200, Chef::JSONCompat.to_json(@cookbook_list))
66
66
  end
67
67
 
68
68
  it "asks for confirmation, then deletes the cookbook" do
@@ -105,7 +105,7 @@ describe Chef::Knife::CookbookDelete do
105
105
  versions = ['1.0.0', '1.1.0', '1.2.0']
106
106
  with_version = lambda { |version| { 'version' => version } }
107
107
  @cookbook_list = {'obsolete-cookbook' => { 'versions' => versions.map(&with_version) } }
108
- @api.get("/cookbooks/obsolete-cookbook", 200, @cookbook_list.to_json)
108
+ @api.get("/cookbooks/obsolete-cookbook", 200, Chef::JSONCompat.to_json(@cookbook_list))
109
109
  end
110
110
 
111
111
  it "deletes all versions of a cookbook when given the '-a' flag" do
@@ -47,7 +47,7 @@ describe Chef::Knife::Exec do
47
47
  @node = Chef::Node.new
48
48
  @node.name("ohai-world")
49
49
  response = {"rows" => [@node],"start" => 0,"total" => 1}
50
- @api.get(%r{^/search/node}, 200, response.to_json)
50
+ @api.get(%r{^/search/node}, 200, Chef::JSONCompat.to_json(response))
51
51
  code = "$output.puts nodes.all"
52
52
  @knife.config[:exec] = code
53
53
  @knife.run
@@ -81,17 +81,28 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do
81
81
  let(:test_registry_value) { 'Registration' }
82
82
  let(:test_registry_data1) { 'LL927' }
83
83
  let(:test_registry_data2) { 'LL928' }
84
- let(:dsc_code) { <<-EOH
84
+ let(:reg_key_name_param_name) { 'testregkeyname' }
85
+ let(:reg_key_value_param_name) { 'testregvaluename' }
86
+ let(:registry_embedded_parameters) { "$#{reg_key_name_param_name} = '#{test_registry_key}';$#{reg_key_value_param_name} = '#{test_registry_value}'"}
87
+ let(:dsc_reg_code) { <<-EOH
88
+ #{registry_embedded_parameters}
85
89
  Registry "ChefRegKey"
86
90
  {
87
- Key = '#{test_registry_key}'
88
- ValueName = '#{test_registry_value}'
91
+ Key = $#{reg_key_name_param_name}
92
+ ValueName = $#{reg_key_value_param_name}
89
93
  ValueData = '#{test_registry_data}'
90
94
  Ensure = 'Present'
91
95
  }
92
96
  EOH
93
97
  }
94
98
 
99
+ let(:dsc_code) { dsc_reg_code }
100
+ let(:dsc_reg_script) { <<-EOH
101
+ param($testregkeyname, $testregvaluename)
102
+ #{dsc_reg_code}
103
+ EOH
104
+ }
105
+
95
106
  let(:dsc_user_prefix) { 'dsc' }
96
107
  let(:dsc_user_suffix) { 'chefx' }
97
108
  let(:dsc_user) {"#{dsc_user_prefix}_usr_#{dsc_user_suffix}" }
@@ -175,7 +186,7 @@ environment "whatsmydir"
175
186
  Ensure = 'Present'
176
187
  }
177
188
  EOH
178
- }
189
+ }
179
190
 
180
191
  let(:dsc_config_name) {
181
192
  dsc_test_resource_base.name
@@ -227,41 +238,79 @@ environment 'removethis'
227
238
  EOH
228
239
  removal_resource.run_action(:run)
229
240
  end
230
- let(:dsc_code) { dsc_environment_config }
231
- it 'should not raise an exception if the cwd is not etc' do
232
- dsc_test_resource.cwd(dsc_environment_no_fail_not_etc_directory)
233
- expect {dsc_test_resource.run_action(:run)}.not_to raise_error
234
- end
235
241
 
236
- it 'should raise an exception if the cwd is etc' do
237
- dsc_test_resource.cwd(dsc_environment_fail_etc_directory)
238
- expect {dsc_test_resource.run_action(:run)}.to raise_error(Chef::Exceptions::PowershellCmdletException)
239
- begin
240
- dsc_test_resource.run_action(:run)
241
- rescue Chef::Exceptions::PowershellCmdletException => e
242
- expect(e.message).to match(exception_message_signature)
242
+ describe 'when the DSC configuration contains code that raises an exception if cwd has a specific value' do
243
+ let(:dsc_code) { dsc_environment_config }
244
+ it 'should not raise an exception if the cwd is not etc' do
245
+ dsc_test_resource.cwd(dsc_environment_no_fail_not_etc_directory)
246
+ expect {dsc_test_resource.run_action(:run)}.not_to raise_error
247
+ end
248
+
249
+ it 'should raise an exception if the cwd is etc' do
250
+ dsc_test_resource.cwd(dsc_environment_fail_etc_directory)
251
+ expect {dsc_test_resource.run_action(:run)}.to raise_error(Chef::Exceptions::PowershellCmdletException)
252
+ begin
253
+ dsc_test_resource.run_action(:run)
254
+ rescue Chef::Exceptions::PowershellCmdletException => e
255
+ expect(e.message).to match(exception_message_signature)
256
+ end
243
257
  end
244
258
  end
245
259
  end
246
260
 
247
261
  shared_examples_for 'a parameterized DSC configuration script' do
248
- context 'when specifying environment variables in the environment attribute' do
249
- let(:dsc_user_prefix_code) { dsc_user_prefix_env_code }
250
- let(:dsc_user_suffix_code) { dsc_user_suffix_env_code }
251
- it_behaves_like 'a dsc_script with configuration that uses environment variables'
262
+ let(:dsc_user_prefix_code) { dsc_user_prefix_env_code }
263
+ let(:dsc_user_suffix_code) { dsc_user_suffix_env_code }
264
+ it_behaves_like 'a dsc_script with configuration that uses environment variables'
265
+ end
266
+
267
+ shared_examples_for 'a dsc_script without configuration data that takes parameters' do
268
+ context 'when configuration data is not specified' do
269
+
270
+ before(:each) do
271
+ test_key_resource = Chef::Resource::RegistryKey.new(test_registry_key, dsc_test_run_context)
272
+ test_key_resource.recursive(true)
273
+ test_key_resource.run_action(:delete_key)
274
+ end
275
+
276
+ after(:each) do
277
+ test_key_resource = Chef::Resource::RegistryKey.new(test_registry_key, dsc_test_run_context)
278
+ test_key_resource.recursive(true)
279
+ test_key_resource.run_action(:delete_key)
280
+ end
281
+
282
+ let(:test_registry_data) { test_registry_data1 }
283
+ let(:dsc_parameterized_env_param_value) { "val" + Random::rand.to_s }
284
+
285
+ it 'should have a default value of nil for the configuration_data attribute' do
286
+ expect(dsc_test_resource.configuration_data).to eql(nil)
287
+ end
288
+
289
+ it 'should have a default value of nil for the configuration_data_path attribute' do
290
+ expect(dsc_test_resource.configuration_data_script).to eql(nil)
291
+ end
292
+
293
+ let(:dsc_test_resource) { dsc_resource_from_path }
294
+ let(:registry_embedded_parameters) { '' }
295
+ let(:dsc_code) { dsc_reg_script }
296
+
297
+ it 'should set a registry key according to parameters passed to the configuration' do
298
+ dsc_test_resource.configuration_name(config_name_value)
299
+ dsc_test_resource.flags({:"#{reg_key_name_param_name}" => test_registry_key, :"#{reg_key_value_param_name}" => test_registry_value})
300
+ expect(dsc_test_resource.registry_key_exists?(test_registry_key)).to eq(false)
301
+ dsc_test_resource.run_action(:run)
302
+ expect(dsc_test_resource.registry_key_exists?(test_registry_key)).to eq(true)
303
+ expect(dsc_test_resource.registry_value_exists?(test_registry_key, {:name => test_registry_value, :type => :string, :data => test_registry_data})).to eq(true)
304
+ end
252
305
  end
253
306
  end
254
307
 
255
308
  shared_examples_for 'a dsc_script with configuration data' do
256
- context 'when using the configuration_data attribute' do
257
- let(:configuration_data_attribute) { 'configuration_data' }
258
- it_behaves_like 'a dsc_script with configuration data set via an attribute'
259
- end
309
+ let(:configuration_data_attribute) { 'configuration_data' }
310
+ it_behaves_like 'a dsc_script with configuration data set via an attribute'
260
311
 
261
- context 'when using the configuration_data_script attribute' do
262
- let(:configuration_data_attribute) { 'configuration_data_script' }
263
- it_behaves_like 'a dsc_script with configuration data set via an attribute'
264
- end
312
+ let(:configuration_data_attribute) { 'configuration_data_script' }
313
+ it_behaves_like 'a dsc_script with configuration data set via an attribute'
265
314
  end
266
315
 
267
316
  shared_examples_for 'a dsc_script with configuration data set via an attribute' do
@@ -282,33 +331,28 @@ EOH
282
331
  end
283
332
 
284
333
  shared_examples_for 'a dsc_script with configuration data that takes parameters' do
285
- context 'when script code takes parameters for configuration' do
286
- let(:dsc_user_code) { dsc_user_param_code }
287
- let(:config_param_section) { config_params }
288
- let(:config_flags) {{:"#{dsc_user_prefix_param_name}" => "#{dsc_user_prefix}", :"#{dsc_user_suffix_param_name}" => "#{dsc_user_suffix}"}}
289
- it 'does not directly contain the user name' do
290
- configuration_script_content = ::File.open(dsc_test_resource.command) do | file |
291
- file.read
292
- end
293
- expect(configuration_script_content.include?(dsc_user)).to be(false)
334
+ let(:dsc_user_code) { dsc_user_param_code }
335
+ let(:config_param_section) { config_params }
336
+ let(:config_flags) {{:"#{dsc_user_prefix_param_name}" => "#{dsc_user_prefix}", :"#{dsc_user_suffix_param_name}" => "#{dsc_user_suffix}"}}
337
+ it 'does not directly contain the user name' do
338
+ configuration_script_content = ::File.open(dsc_test_resource.command) do | file |
339
+ file.read
294
340
  end
295
- it_behaves_like 'a dsc_script with configuration data'
341
+ expect(configuration_script_content.include?(dsc_user)).to be(false)
296
342
  end
297
-
343
+ it_behaves_like 'a dsc_script with configuration data'
298
344
  end
299
345
 
300
346
  shared_examples_for 'a dsc_script with configuration data that uses environment variables' do
301
- context 'when script code uses environment variables' do
302
- let(:dsc_user_code) { dsc_user_env_code }
347
+ let(:dsc_user_code) { dsc_user_env_code }
303
348
 
304
- it 'does not directly contain the user name' do
305
- configuration_script_content = ::File.open(dsc_test_resource.command) do | file |
306
- file.read
307
- end
308
- expect(configuration_script_content.include?(dsc_user)).to be(false)
349
+ it 'does not directly contain the user name' do
350
+ configuration_script_content = ::File.open(dsc_test_resource.command) do | file |
351
+ file.read
309
352
  end
310
- it_behaves_like 'a dsc_script with configuration data'
353
+ expect(configuration_script_content.include?(dsc_user)).to be(false)
311
354
  end
355
+ it_behaves_like 'a dsc_script with configuration data'
312
356
  end
313
357
 
314
358
  context 'when supplying configuration through the configuration attribute' do
@@ -333,5 +377,6 @@ EOH
333
377
  it_behaves_like 'a dsc_script with configuration data'
334
378
  it_behaves_like 'a dsc_script with configuration data that uses environment variables'
335
379
  it_behaves_like 'a dsc_script with configuration data that takes parameters'
380
+ it_behaves_like 'a dsc_script without configuration data that takes parameters'
336
381
  end
337
382
  end