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 <m...@puppetlabs.com> Signed-off-by: Paul Berry <p...@puppetlabs.com> --- spec/integration/provider/mount_spec.rb | 93 +++++++++++++++++++++++++++++++ 1 files changed, 93 insertions(+), 0 deletions(-) create mode 100644 spec/integration/provider/mount_spec.rb diff --git a/spec/integration/provider/mount_spec.rb b/spec/integration/provider/mount_spec.rb new file mode 100644 index 0000000..69a9eeb --- /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 -- 1.7.2 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-dev@googlegroups.com. To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.