diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
| commit | 3180b9d9b2c844dade1d361326600f7001ec66dd (patch) | |
| tree | 98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /test/ral/providers/host | |
| parent | 543225970225de5697734bfaf0a6eee996802c04 (diff) | |
| download | puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip | |
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with
The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people
who learned ruby in the 1900s) uses two-space indentation.
3 Examples:
The code:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
becomes:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
The code:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
becomes:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
The code:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
becomes:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
Diffstat (limited to 'test/ral/providers/host')
| -rwxr-xr-x | test/ral/providers/host/parsed.rb | 364 |
1 files changed, 182 insertions, 182 deletions
diff --git a/test/ral/providers/host/parsed.rb b/test/ral/providers/host/parsed.rb index 5b21abc6b..c2367d566 100755 --- a/test/ral/providers/host/parsed.rb +++ b/test/ral/providers/host/parsed.rb @@ -8,86 +8,86 @@ require 'puppettest/fileparsing' require 'test/unit' class TestParsedHostProvider < Test::Unit::TestCase - include PuppetTest - include PuppetTest::FileParsing - - def setup - super - @provider = Puppet::Type.type(:host).provider(:parsed) - - @oldfiletype = @provider.filetype + include PuppetTest + include PuppetTest::FileParsing + + def setup + super + @provider = Puppet::Type.type(:host).provider(:parsed) + + @oldfiletype = @provider.filetype + end + + def teardown + Puppet::Util::FileType.filetype(:ram).clear + @provider.filetype = @oldfiletype + @provider.clear + super + end + + def test_provider_existence + assert(@provider, "Could not retrieve provider") + end + + # Here we just create a fake host type that answers to all of the methods + # but does not modify our actual system. + def mkfaketype + @provider.filetype = Puppet::Util::FileType.filetype(:ram) + end + + def mkhosthash + if defined?(@hcount) + @hcount += 1 + else + @hcount = 1 end - def teardown - Puppet::Util::FileType.filetype(:ram).clear - @provider.filetype = @oldfiletype - @provider.clear - super - end + return { + :name => "fakehost#{@hcount}", + :ip => "192.168.27.#{@hcount}", + :host_aliases => ["alias#{@hcount}"], + :ensure => :present + } + end - def test_provider_existence - assert(@provider, "Could not retrieve provider") - end + def mkhost + hash = mkhosthash - # Here we just create a fake host type that answers to all of the methods - # but does not modify our actual system. - def mkfaketype - @provider.filetype = Puppet::Util::FileType.filetype(:ram) - end + fakeresource = fakeresource(:host, hash[:name]) - def mkhosthash - if defined?(@hcount) - @hcount += 1 - else - @hcount = 1 - end - - return { - :name => "fakehost#{@hcount}", - :ip => "192.168.27.#{@hcount}", - :host_aliases => ["alias#{@hcount}"], - :ensure => :present - } - end + host = @provider.new(fakeresource) - def mkhost - hash = mkhosthash - - fakeresource = fakeresource(:host, hash[:name]) - - host = @provider.new(fakeresource) - - assert(host, "Could not create provider host") - hash.each do |name, val| - host.send(name.to_s + "=", val) - end - - host + assert(host, "Could not create provider host") + hash.each do |name, val| + host.send(name.to_s + "=", val) end - # Make sure we convert both directlys correctly using a simple host. - def test_basic_isomorphism - hash = {:record_type => :parsed, :name => "myhost", :ip => "192.168.43.56", :host_aliases => %w{another host}} + host + end - str = nil - assert_nothing_raised do - str = @provider.to_line(hash) - end + # Make sure we convert both directlys correctly using a simple host. + def test_basic_isomorphism + hash = {:record_type => :parsed, :name => "myhost", :ip => "192.168.43.56", :host_aliases => %w{another host}} - assert_equal("192.168.43.56\tmyhost\tanother\thost", str) + str = nil + assert_nothing_raised do + str = @provider.to_line(hash) + end - newhash = nil - assert_nothing_raised do - newhash = @provider.parse(str).shift - end + assert_equal("192.168.43.56\tmyhost\tanother\thost", str) - assert_equal(hash, newhash) + newhash = nil + assert_nothing_raised do + newhash = @provider.parse(str).shift end - # Make sure parsing gets comments, blanks, and hosts - def test_blanks_and_comments - mkfaketype - text = %{# comment one + assert_equal(hash, newhash) + end + + # Make sure parsing gets comments, blanks, and hosts + def test_blanks_and_comments + mkfaketype + text = %{# comment one 192.168.43.56\tmyhost\tanother\thost @@ -95,140 +95,140 @@ class TestParsedHostProvider < Test::Unit::TestCase 192.168.43.57\tanotherhost } - instances = nil - assert_nothing_raised do - instances = @provider.parse(text) - end + instances = nil + assert_nothing_raised do + instances = @provider.parse(text) + end - assert_equal( - [ - {:record_type => :comment, :line => "# comment one"}, - {:record_type => :blank, :line => ""}, - {:record_type => :parsed, :name => "myhost", :ip => "192.168.43.56", :host_aliases => %w{another host}}, - {:record_type => :blank, :line => " "}, - {:record_type => :comment, :line => "# another comment"}, + assert_equal( + [ + {:record_type => :comment, :line => "# comment one"}, + {:record_type => :blank, :line => ""}, + {:record_type => :parsed, :name => "myhost", :ip => "192.168.43.56", :host_aliases => %w{another host}}, + {:record_type => :blank, :line => " "}, + {:record_type => :comment, :line => "# another comment"}, - {:record_type => :parsed, :name => "anotherhost", :ip => "192.168.43.57", :host_aliases => []} - ], instances) + {:record_type => :parsed, :name => "anotherhost", :ip => "192.168.43.57", :host_aliases => []} + ], instances) - newtext = nil - assert_nothing_raised do - newtext = @provider.to_file(instances).gsub(/^# HEADER.+\n/, '') - end + newtext = nil + assert_nothing_raised do + newtext = @provider.to_file(instances).gsub(/^# HEADER.+\n/, '') + end - assert_equal(text, newtext) + assert_equal(text, newtext) + end + + def test_simplehost + mkfaketype + @provider.default_target = :yayness + file = @provider.target_object(:yayness) + + # Start out with no content. + assert_nothing_raised { + assert_equal([], @provider.parse(file.read)) + } + + # Now create a provider + host = nil + assert_nothing_raised { + host = mkhost + } + + # Make sure we're still empty + assert_nothing_raised { + assert_equal([], @provider.parse(file.read)) + } + + # Try storing it + assert_nothing_raised do + host.flush end - def test_simplehost - mkfaketype - @provider.default_target = :yayness - file = @provider.target_object(:yayness) - - # Start out with no content. - assert_nothing_raised { - assert_equal([], @provider.parse(file.read)) - } - - # Now create a provider - host = nil - assert_nothing_raised { - host = mkhost - } - - # Make sure we're still empty - assert_nothing_raised { - assert_equal([], @provider.parse(file.read)) - } - - # Try storing it - assert_nothing_raised do - host.flush - end - - # Make sure we get the host back - assert_nothing_raised { - - assert( - file.read.include?(host.name), + # Make sure we get the host back + assert_nothing_raised { + + assert( + file.read.include?(host.name), - "Did not flush host to disk") - } + "Did not flush host to disk") + } - # Remove a single field and make sure it gets tossed - name = host.host_aliases - host.host_aliases = [:absent] + # Remove a single field and make sure it gets tossed + name = host.host_aliases + host.host_aliases = [:absent] - assert_nothing_raised { - host.flush + assert_nothing_raised { + host.flush - assert( - ! file.read.include?(name[0]), + assert( + ! file.read.include?(name[0]), - "Did not remove host_aliases from disk") - } - - # Make sure it throws up if we remove a required field - host.ip = :absent - - assert_raise(ArgumentError) { - host.flush - } - - # Now remove the whole object - host.ensure = :absent - assert_nothing_raised { - host.flush - assert_equal([], @provider.parse(file.read)) - } - end - - # Parse our sample data and make sure we regenerate it correctly. - def test_hostsparse - fakedata("data/types/hosts").each do |file| fakedataparse(file) end + "Did not remove host_aliases from disk") + } + + # Make sure it throws up if we remove a required field + host.ip = :absent + + assert_raise(ArgumentError) { + host.flush + } + + # Now remove the whole object + host.ensure = :absent + assert_nothing_raised { + host.flush + assert_equal([], @provider.parse(file.read)) + } + end + + # Parse our sample data and make sure we regenerate it correctly. + def test_hostsparse + fakedata("data/types/hosts").each do |file| fakedataparse(file) end + end + + # Make sure we can modify the file elsewhere and those modifications will + # get taken into account. + def test_modifyingfile + hostfile = tempfile + @provider.default_target = hostfile + + file = @provider.target_object(hostfile) + + hosts = [] + 3.times { + h = mkhost + hosts << h + } + + hosts.each do |host| + host.flush end - # Make sure we can modify the file elsewhere and those modifications will - # get taken into account. - def test_modifyingfile - hostfile = tempfile - @provider.default_target = hostfile + newhost = mkhost + hosts << newhost - file = @provider.target_object(hostfile) + # Now store our new host + newhost.flush - hosts = [] - 3.times { - h = mkhost - hosts << h - } + # Verify we can retrieve that info + assert_nothing_raised("Could not retrieve after second write") { + @provider.prefetch + } - hosts.each do |host| - host.flush - end + text = file.read - newhost = mkhost - hosts << newhost + instances = @provider.parse(text) - # Now store our new host - newhost.flush - - # Verify we can retrieve that info - assert_nothing_raised("Could not retrieve after second write") { - @provider.prefetch - } - - text = file.read - - instances = @provider.parse(text) - - # And verify that we have data for everything - hosts.each { |host| - name = host.resource[:name] - assert(text.include?(name), "Host #{name} is not in file") - hash = host.property_hash - assert(! hash.empty?, "Could not find host #{name}") - assert(hash[:ip], "Could not find ip for host #{name}") - } - end + # And verify that we have data for everything + hosts.each { |host| + name = host.resource[:name] + assert(text.include?(name), "Host #{name} is not in file") + hash = host.property_hash + assert(! hash.empty?, "Could not find host #{name}") + assert(hash[:ip], "Could not find ip for host #{name}") + } + end end |
