diff options
-rwxr-xr-x | spec/integration/application/apply_spec.rb | 43 | ||||
-rwxr-xr-x | spec/lib/puppet_spec/files.rb | 1 |
2 files changed, 13 insertions, 31 deletions
diff --git a/spec/integration/application/apply_spec.rb b/spec/integration/application/apply_spec.rb index 7342c212f..3ce1277d3 100755 --- a/spec/integration/application/apply_spec.rb +++ b/spec/integration/application/apply_spec.rb @@ -1,7 +1,5 @@ -#! /usr/bin/env ruby require 'spec_helper' require 'puppet_spec/files' -require 'puppet/application/apply' describe "apply" do include PuppetSpec::Files @@ -10,14 +8,6 @@ describe "apply" do Puppet[:reports] = "none" end - def tmpfile_with_content(name, content) - result = tmpfile(name) - File.open(result, "w") do |f| - f.puts [ content ].flatten * "\n" - end - result - end - describe "when applying provided catalogs" do it "can apply catalogs provided in a file in pson" do file_to_create = tmpfile("pson_catalog") @@ -25,9 +15,8 @@ describe "apply" do resource = Puppet::Resource.new(:file, file_to_create, :parameters => {:content => "my stuff"}) catalog.add_resource resource - manifest = tmpfile("manifest") + manifest = file_containing("manifest", catalog.to_pson) - File.open(manifest, "w") { |f| f.print catalog.to_pson } puppet = Puppet::Application[:apply] puppet.options[:catalog] = manifest @@ -39,7 +28,7 @@ describe "apply" do end it "applies a given file even when a directory environment is specified" do - manifest = tmpfile_with_content("manifest.pp", "notice('it was applied')") + manifest = file_containing("manifest.pp", "notice('it was applied')") special = Puppet::Node::Environment.create(:special, []) Puppet.override(:current_environment => special) do @@ -53,11 +42,9 @@ describe "apply" do end it "applies a given file even when an ENC is configured", :if => !Puppet.features.microsoft_windows? do - manifest = tmpfile_with_content("manifest.pp", "notice('specific manifest applied')") - - site_manifest = tmpfile_with_content("site_manifest.pp", "notice('the site manifest was applied instead')") - - enc = tmpfile_with_content("enc_script", ["#!/bin/sh", "echo 'classes: []'"]) + manifest = file_containing("manifest.pp", "notice('specific manifest applied')") + site_manifest = file_containing("site_manifest.pp", "notice('the site manifest was applied instead')") + enc = file_containing("enc_script", "#!/bin/sh\necho 'classes: []'") File.chmod(0755, enc) special = Puppet::Node::Environment.create(:special, []) @@ -80,21 +67,15 @@ describe "apply" do let(:args) { ['-e', execute, '--modulepath', modulepath] } before(:each) do - Puppet::FileSystem.mkpath("#{modulepath}/amod/manifests") - File.open("#{modulepath}/amod/manifests/init.pp", "w") do |f| - f.puts <<-EOF - class amod{ - notice('amod class included') + dir_contained_in(modulepath, { + "amod" => { + "manifests" => { + "init.pp" => "class amod{ notice('amod class included') }" + } } - EOF - end - environmentdir = Dir.mktmpdir('environments') - Puppet[:environmentpath] = environmentdir - create_default_directory_environment - end + }) - def create_default_directory_environment - Puppet::FileSystem.mkpath("#{Puppet[:environmentpath]}/#{Puppet[:environment]}") + Puppet[:environmentpath] = dir_containing("environments", { Puppet[:environment] => {} }) end def init_cli_args_and_apply_app(args, execute) diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb index 312c4fc95..2d0d95275 100755 --- a/spec/lib/puppet_spec/files.rb +++ b/spec/lib/puppet_spec/files.rb @@ -57,6 +57,7 @@ module PuppetSpec::Files dir_contained_in(tmpdir(name), contents_hash) end + def dir_contained_in(dir, contents_hash) PuppetSpec::Files.dir_contained_in(dir, contents_hash) end def self.dir_contained_in(dir, contents_hash) contents_hash.each do |k,v| if v.is_a?(Hash) |