diff options
author | Adam Edwards <adamed@opscode.com> | 2014-10-10 11:35:37 -0700 |
---|---|---|
committer | adamedx <adamed@getchef.com> | 2014-10-14 13:29:46 +0100 |
commit | 949b5c79d142dfc03b312bb40106b4477b957df3 (patch) | |
tree | dd04e75926f6b477111b169bf7878d93ef074e0b /spec/functional/resource/dsc_script_spec.rb | |
parent | 87ebd29a5632d4a2598b12b99ecc9d2ee2b4586f (diff) | |
download | chef-949b5c79d142dfc03b312bb40106b4477b957df3.tar.gz |
DSC parameters should be passed even when there is no config data file
Diffstat (limited to 'spec/functional/resource/dsc_script_spec.rb')
-rw-r--r-- | spec/functional/resource/dsc_script_spec.rb | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/spec/functional/resource/dsc_script_spec.rb b/spec/functional/resource/dsc_script_spec.rb index fa13296c02..8496dcd0e0 100644 --- a/spec/functional/resource/dsc_script_spec.rb +++ b/spec/functional/resource/dsc_script_spec.rb @@ -81,17 +81,28 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do let(:test_registry_value) { 'Registration' } let(:test_registry_data1) { 'LL927' } let(:test_registry_data2) { 'LL928' } - let(:dsc_code) { <<-EOH + let(:reg_key_name_param_name) { 'testregkeyname' } + let(:reg_key_value_param_name) { 'testregvaluename' } + let(:registry_embedded_parameters) { "$#{reg_key_name_param_name} = '#{test_registry_key}';$#{reg_key_value_param_name} = '#{test_registry_value}'"} + let(:dsc_reg_code) { <<-EOH + #{registry_embedded_parameters} Registry "ChefRegKey" { - Key = '#{test_registry_key}' - ValueName = '#{test_registry_value}' + Key = $#{reg_key_name_param_name} + ValueName = $#{reg_key_value_param_name} ValueData = '#{test_registry_data}' Ensure = 'Present' } EOH } + let(:dsc_code) { dsc_reg_code } + let(:dsc_reg_script) { <<-EOH + param($testregkeyname, $testregvaluename) + #{dsc_reg_code} +EOH + } + let(:dsc_user_prefix) { 'dsc' } let(:dsc_user_suffix) { 'chefx' } let(:dsc_user) {"#{dsc_user_prefix}_usr_#{dsc_user_suffix}" } @@ -175,7 +186,7 @@ environment "whatsmydir" Ensure = 'Present' } EOH - } +} let(:dsc_config_name) { dsc_test_resource_base.name @@ -252,6 +263,47 @@ EOH end end + shared_examples_for 'a dsc_script without configuration data that takes parameters' do + context 'when configuration data is not specified' do + + before(:each) do + test_key_resource = Chef::Resource::RegistryKey.new(test_registry_key, dsc_test_run_context) + test_key_resource.recursive(true) + test_key_resource.run_action(:delete_key) + end + + after(:each) do + test_key_resource = Chef::Resource::RegistryKey.new(test_registry_key, dsc_test_run_context) + test_key_resource.recursive(true) + test_key_resource.run_action(:delete_key) + end + + let(:test_registry_data) { test_registry_data1 } + let(:dsc_parameterized_env_param_value) { "val" + Random::rand.to_s } + + it 'should have a default value of nil for the configuration_data attribute' do + expect(dsc_test_resource.configuration_data).to eql(nil) + end + + it 'should have a default value of nil for the configuration_data_path attribute' do + expect(dsc_test_resource.configuration_data_script).to eql(nil) + end + + let(:dsc_test_resource) { dsc_resource_from_path } + let(:registry_embedded_parameters) { '' } + let(:dsc_code) { dsc_reg_script } + + it 'should set a registry key according to parameters passed to the configuration' do + dsc_test_resource.configuration_name(config_name_value) + dsc_test_resource.flags({:"#{reg_key_name_param_name}" => test_registry_key, :"#{reg_key_value_param_name}" => test_registry_value}) + expect(dsc_test_resource.registry_key_exists?(test_registry_key)).to eq(false) + dsc_test_resource.run_action(:run) + expect(dsc_test_resource.registry_key_exists?(test_registry_key)).to eq(true) + expect(dsc_test_resource.registry_value_exists?(test_registry_key, {:name => test_registry_value, :type => :string, :data => test_registry_data})).to eq(true) + end + end + end + shared_examples_for 'a dsc_script with configuration data' do context 'when using the configuration_data attribute' do let(:configuration_data_attribute) { 'configuration_data' } @@ -333,5 +385,6 @@ EOH it_behaves_like 'a dsc_script with configuration data' it_behaves_like 'a dsc_script with configuration data that uses environment variables' it_behaves_like 'a dsc_script with configuration data that takes parameters' + it_behaves_like 'a dsc_script without configuration data that takes parameters' end end |