summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2011-03-01 14:06:42 -0800
committerPaul Berry <paul@puppetlabs.com>2011-03-07 16:54:10 -0800
commit9d2fceb7141e4cc7a6215aa2529239eb2eb6c8fd (patch)
tree484f90733371cc3e8fcdd9f417de17a8b7763d4a /spec
parent8dbdcb057115bb2abdca22230d819303ff18ed6d (diff)
downloadpuppet-9d2fceb7141e4cc7a6215aa2529239eb2eb6c8fd.tar.gz
puppet-9d2fceb7141e4cc7a6215aa2529239eb2eb6c8fd.tar.xz
puppet-9d2fceb7141e4cc7a6215aa2529239eb2eb6c8fd.zip
Maint: Begin adding integration tests for the mount provider
These tests form a starting point for integration testing the mount provider, using the new Puppet::Util::ExecutionStub mechanism to simulate the state of the machine in response to the execution of "mount" and "umount" commands. The tests currently work around some known bugs (6628, 6632, and 6633). Reviewed-by: Max Martin <max@puppetlabs.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/provider/mount_spec.rb93
1 files changed, 93 insertions, 0 deletions
diff --git a/spec/integration/provider/mount_spec.rb b/spec/integration/provider/mount_spec.rb
new file mode 100644
index 000000000..69a9eeb56
--- /dev/null
+++ b/spec/integration/provider/mount_spec.rb
@@ -0,0 +1,93 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/file_bucket/dipper'
+
+describe "mount provider (integration)" do
+ include PuppetSpec::Files
+
+ before :each do
+ @fake_fstab = tmpfile('fstab')
+ File.open(@fake_fstab, 'w') do |f|
+ # leave file empty
+ end
+ Puppet::Type.type(:mount).defaultprovider.stubs(:default_target).returns(@fake_fstab)
+ Facter.stubs(:value).with(:operatingsystem).returns('Darwin')
+ Puppet::Util::ExecutionStub.set do |command, options|
+ case command[0]
+ when '/sbin/mount'
+ if command.length == 1
+ if @mounted
+ "/dev/disk1s1 on /Volumes/foo_disk (msdos, local)\n"
+ else
+ ''
+ end
+ else
+ command.length.should == 4
+ command[1].should == '-o'
+ command[2].should == 'local'
+ command[3].should == '/Volumes/foo_disk'
+ @mounted.should == false # verify that we don't try to call "mount" redundantly
+ check_fstab
+ @mounted = true
+ ''
+ end
+ when '/sbin/umount'
+ fail "unexpected umount" unless @umount_permitted
+ command.length.should == 2
+ command[1].should == '/Volumes/foo_disk'
+ @mounted = false
+ ''
+ else
+ fail "Unexpected command #{command.inspect} executed"
+ end
+ end
+ end
+
+ after :each do
+ Puppet::Type::Mount::ProviderParsed.clear # Work around bug #6628
+ end
+
+ def check_fstab
+ # Verify that the fake fstab has the expected data in it
+ File.read(@fake_fstab).lines.reject { |x| x =~ /^#/ }.should == ["/dev/disk1s1\t/Volumes/foo_disk\tmsdos\tlocal\t0\t0\n"]
+ end
+
+ def run_in_catalog(ensure_setting)
+ resource = Puppet::Type.type(:mount).new(:name => "/Volumes/foo_disk", :ensure => ensure_setting,
+ :device => "/dev/disk1s1", :options => "local", :fstype => "msdos")
+ Puppet::FileBucket::Dipper.any_instance.stubs(:backup) # Don't backup to the filebucket
+ resource.expects(:err).never
+ catalog = Puppet::Resource::Catalog.new
+ catalog.host_config = false # Stop Puppet from doing a bunch of magic
+ catalog.add_resource resource
+ catalog.apply
+ end
+
+ [:defined, :present].each do |ensure_setting|
+ describe "When setting ensure => #{ensure_setting}" do
+ it "should create an fstab entry if none exists" do
+ @mounted = false
+ @umount_permitted = false
+ run_in_catalog(ensure_setting)
+ @mounted.should == false
+ check_fstab
+ end
+ end
+ end
+
+ it "should be able to create and mount a brand new mount point" do
+ @mounted = false
+ @umount_permitted = true # Work around bug #6632
+ run_in_catalog(:mounted)
+ @mounted.should == true
+ check_fstab
+ end
+
+ it "should be able to create an fstab entry for an already-mounted device" do
+ @mounted = true
+ @umount_permitted = true # Work around bug #6633
+ run_in_catalog(:mounted)
+ @mounted.should == true
+ check_fstab
+ end
+end