Skip to content

Commit

Permalink
(#9272) Refactor puppet-lvm (auto)testing
Browse files Browse the repository at this point in the history
Testing needed refactoring due to recent merges and tests and
autotesting was written for rspec 1.29. This has been refreshed
for rspec 2 and autotest. There is still a little tweaking to do
to get autotest runnning out of the box.

Added .rspec and .autotest files while removing the autotesti
directory as it was needed for previous autotest. Current autotest
uses .autotest for simple configurations.

Signed-off-by: Matthaus Litteken <matthaus@puppetlabs.com>
  • Loading branch information
haus committed Aug 30, 2011
1 parent 84fa069 commit 55c0a47
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 154 deletions.
53 changes: 53 additions & 0 deletions .autotest
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Autotest.add_hook :initialize do |at|
at.clear_mappings
# watch out: Ruby bug (1.8.6):
# %r(/) != /\//
at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
filename
}

at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
["spec/#{m[1]}_spec.rb"]
}

at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
at.files_matching %r{^spec/.*_spec\.rb$}
}
# the libraries under lib/puppet

at.add_mapping(%r%^lib/(.*)\.rb$%) { |filename, m|
at.files_matching %r!spec/(unit|integration)/#{m[1]}.rb!
}

# the actual spec files themselves
at.add_mapping(%r%^spec/(unit|integration)/.*\.rb$%) { |filename, _|
filename
}

# force a complete re-run for all of these:

# main puppet lib
at.add_mapping(%r!^lib/puppet\.rb$!) { |filename, _|
at.files_matching %r!spec/(unit|integration)/.*\.rb!
}

# the spec_helper
at.add_mapping(%r!^spec/spec_helper\.rb$!) { |filename, _|
at.files_matching %r!spec/(unit|integration)/.*\.rb!
}

# the puppet test libraries
at.add_mapping(%r!^test/lib/puppettest/.*!) { |filename, _|
at.files_matching %r!spec/(unit|integration)/.*\.rb!
}

# the puppet spec libraries
at.add_mapping(%r!^spec/lib/spec.*!) { |filename, _|
at.files_matching %r!spec/(unit|integration)/.*\.rb!
}

# the monkey patches for rspec
at.add_mapping(%r!^spec/lib/monkey_patches/.*!) { |filename, _|
at.files_matching %r!spec/(unit|integration)/.*\.rb!
}
end
4 changes: 4 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--format
s

--color
9 changes: 0 additions & 9 deletions autotest/discover.rb

This file was deleted.

51 changes: 0 additions & 51 deletions autotest/puppet_lvm_rspec.rb

This file was deleted.

74 changes: 0 additions & 74 deletions autotest/rspec.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/puppet/provider/logical_volume/lvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:resize2fs => 'resize2fs',
:umount => 'umount',
:mount => 'mount',
:dmsetup => 'dmsetup'
:dmsetup => 'dmsetup'

def create
args = ['-n', @resource[:name]]
Expand All @@ -22,7 +22,7 @@ def create
end

def destroy
dmsetup('remove', "#{@resource[:volume_group]}-#{@resource[:name]}")
dmsetup('remove', "#{@resource[:volume_group]}-#{@resource[:name]}")
lvremove('-f', path)
end

Expand Down
6 changes: 0 additions & 6 deletions spec/spec.opts

This file was deleted.

6 changes: 2 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

require 'mocha'
require 'puppet'
gem 'rspec', '=1.2.9'
require 'spec/autorun'

require 'rspec'
require 'helpers'
require 'matchers'

Spec::Runner.configure do |config|
RSpec.configure do |config|
config.mock_with :mocha
config.include Helpers
config.include Matchers
Expand Down
19 changes: 17 additions & 2 deletions spec/unit/puppet/provider/filesystem/lvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,23 @@
describe 'when creating' do
it "should execute the correct filesystem command" do
@resource.expects(:[]).with(:name).returns('/dev/myvg/mylv')
@resource.expects(:[]).with(:ensure).returns('ext3')
@provider.expects(:execute).with(['mkfs.ext3', '/dev/myvg/mylv'])
@resource.expects(:[]).with(:fs_type).returns('ext4')
@resource.expects(:[]).with(:options)
@provider.expects(:execute).with(['mkfs.ext4', '/dev/myvg/mylv'])
@provider.create
end
it "should include the supplied filesystem options" do
@resource.expects(:[]).with(:name).returns('/dev/myvg/mylv')
@resource.expects(:[]).with(:fs_type).returns('ext4')
@resource.expects(:[]).with(:options).returns('-b 4096 -E stride=32,stripe-width=64').twice
@provider.expects(:execute).with(['mkfs.ext4', '/dev/myvg/mylv', ['-b', '4096', '-E', 'stride=32,stripe-width=64']])
@provider.create
end
it "should include -q for reiserfs" do
@resource.expects(:[]).with(:name).returns('/dev/myvg/mylv')
@resource.expects(:[]).with(:fs_type).returns('reiserfs')
@resource.expects(:[]).with(:options).returns('-b 4096 -E stride=32,stripe-width=64').twice
@provider.expects(:execute).with(['mkfs.reiserfs', '/dev/myvg/mylv', '-q', ['-b', '4096', '-E', 'stride=32,stripe-width=64']])
@provider.create
end
end
Expand Down
11 changes: 7 additions & 4 deletions spec/unit/puppet/provider/logical_volume/lvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@resource.expects(:[]).with(:name).returns('mylv')
@resource.expects(:[]).with(:volume_group).returns('myvg')
@resource.expects(:[]).with(:size).returns(nil).at_least_once
@resource.expects(:[]).with(:initial_size)
@provider.expects(:lvcreate).with('-n', 'mylv', 'myvg')
@provider.create
end
Expand All @@ -40,7 +41,8 @@
@provider.create
@provider.expects(:lvs).with('--noheading', '--unit', 'g', '/dev/myvg/mylv').returns(' 1.00g').at_least_once
@provider.expects(:lvs).with('--noheading', '-o', 'vg_extent_size', '--units', 'k', '/dev/myvg/mylv').returns(' 1000.00k')
@provider.expects(:lvextend)
@provider.expects(:lvextend).with('-L', '2000000k', '/dev/myvg/mylv').returns(true)
@provider.expects(:mount).with('-f', '--guess-fstype', '/dev/myvg/mylv')
@provider.size = '2000000k'
end
end
Expand Down Expand Up @@ -72,9 +74,10 @@
end

describe 'when destroying' do
it "should execute 'lvremove'" do
@resource.expects(:[]).with(:volume_group).returns('myvg')
@resource.expects(:[]).with(:name).returns('mylv')
it "should execute 'dmsetup' and 'lvremove'" do
@resource.expects(:[]).with(:volume_group).returns('myvg').twice
@resource.expects(:[]).with(:name).returns('mylv').twice
@provider.expects(:dmsetup).with('remove', 'myvg-mylv')
@provider.expects(:lvremove).with('-f', '/dev/myvg/mylv')
@provider.destroy
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/puppet/type/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@type = Puppet::Type.type(:filesystem)
@valid_params = {
:name => '/dev/myvg/mylv',
:ensure => 'ext3'
:ensure => 'present'
}
stub_default_provider!
end
Expand Down Expand Up @@ -33,7 +33,7 @@
@type.attrclass(:ensure).should_not be_nil
end
it "should support a filesystem type as a value" do
with(valid_params)[:ensure].should == 'ext3'
with(valid_params)[:ensure].should == :present
end
end

Expand Down

0 comments on commit 55c0a47

Please sign in to comment.