diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-03-15 15:05:42 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-03-20 14:38:49 -0700 |
commit | e203c7bef38e942432cdbc1af0cd08eba6dbf7db (patch) | |
tree | c6cc1177c808e913ed666399d432ca55028226d5 | |
parent | c71696269ea1865101b1857914f8afdd0a1e7e69 (diff) | |
download | chef-e203c7bef38e942432cdbc1af0cd08eba6dbf7db.tar.gz |
Added basic functional tests using File dsc resource
-rw-r--r-- | spec/functional/resource/dsc_resource_spec.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/functional/resource/dsc_resource_spec.rb b/spec/functional/resource/dsc_resource_spec.rb index a7c96e00d0..9b78cacd93 100644 --- a/spec/functional/resource/dsc_resource_spec.rb +++ b/spec/functional/resource/dsc_resource_spec.rb @@ -48,5 +48,41 @@ describe Chef::Resource::DscResource, :windows_powershell_dsc_only do end end + context 'with a valid dsc resource' do + let(:tmp_file_name) { Dir::Tmpname.create('tmpfile') {} } + let(:test_text) { "'\"!@#$%^&*)(}{][\u2713~n"} + + before do + new_resource.resource :File + new_resource.property :Contents, test_text + new_resource.property :DestinationPath, tmp_file_name + end + + after do + File.delete(tmp_file_name) if File.exists? tmp_file_name + end + + it 'converges the resource if it is not converged' do + new_resource.run_action(:run) + contents = File.open(tmp_file_name, 'rb:bom|UTF-16LE') do |f| + f.read.encode('UTF-8') + end + expect(contents).to eq(test_text) + expect(new_resource).to be_updated + end + + it 'does not converge the resource if it is already converged' do + new_resource.run_action(:run) + expect(new_resource).to be_updated + reresource = + Chef::Resource::DscResource.new("dsc_resource_retest", run_context) + reresource.resource :File + reresource.property :Contents, test_text + reresource.property :DestinationPath, tmp_file_name + reresource.run_action(:run) + expect(reresource).not_to be_updated + end + end + end end |