diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-15 07:20:36 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-15 07:20:36 +0000 |
| commit | 20b65e7845d55cac408fa0d9eddb5209a996076a (patch) | |
| tree | 676cfe1891e9c9b0b015393a732b41a0e6af11ea /test | |
| parent | 6cfee76f94824157a28354c9d6838716cb2c5d47 (diff) | |
Some important bug fixes in the parsedtypes types; this all started from the submitted bug today, but I added :absent support to most params.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@910 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rwxr-xr-x | test/types/cron.rb | 20 | ||||
| -rwxr-xr-x | test/types/host.rb | 45 | ||||
| -rwxr-xr-x | test/types/port.rb | 69 | ||||
| -rwxr-xr-x | test/types/sshkey.rb | 47 |
4 files changed, 170 insertions, 11 deletions
diff --git a/test/types/cron.rb b/test/types/cron.rb index 5526215e7..f45eb5586 100755 --- a/test/types/cron.rb +++ b/test/types/cron.rb @@ -362,6 +362,26 @@ class TestCron < Test::Unit::TestCase cron.retrieve assert_events([], cron) end + + def test_fieldremoval + cron = nil + assert_nothing_raised { + cron = Puppet.type(:cron).create( + :command => "/bin/date > /dev/null", + :minute => [0, 30], + :name => "crontest" + ) + } + + assert_events([:cron_created], cron) + + cron[:minute] = :absent + assert_events([:cron_changed], cron) + assert_nothing_raised { + cron.retrieve + } + assert_equal(:absent, cron.is(:minute)) + end end # $Id$ diff --git a/test/types/host.rb b/test/types/host.rb index 343121d72..b842c1cfb 100755 --- a/test/types/host.rb +++ b/test/types/host.rb @@ -33,12 +33,17 @@ class TestHost < Test::Unit::TestCase end def mkhost + if defined? @hcount + @hcount += 1 + else + @hcount = 1 + end host = nil assert_nothing_raised { host = Puppet.type(:host).create( - :name => "culain", - :ip => "192.168.0.3", - :alias => "puppet" + :name => "fakehost%s" % @hcount, + :ip => "192.168.27.%s" % @hcount, + :alias => "alias%s" % @hcount ) } @@ -141,6 +146,40 @@ class TestHost < Test::Unit::TestCase host.retrieve assert_events([], host) end + + def test_modifyingfile + hostfile = tempfile() + Puppet.type(:host).path = hostfile + + hosts = [] + names = [] + 3.times { + h = mkhost() + #h[:ensure] = :present + #h.retrieve + hosts << h + names << h.name + } + assert_apply(*hosts) + hosts.clear + Puppet.type(:host).clear + newhost = mkhost() + #newhost[:ensure] = :present + names << newhost.name + assert_apply(newhost) + Puppet.type(:host).clear + # Verify we can retrieve that info + assert_nothing_raised("Could not retrieve after second write") { + newhost.retrieve + } + + # And verify that we have data for everything + names.each { |name| + host = Puppet.type(:host)[name] + assert(host) + assert(host[:ip]) + } + end end # $Id$ diff --git a/test/types/port.rb b/test/types/port.rb index 7e26a552c..c37f2dff0 100755 --- a/test/types/port.rb +++ b/test/types/port.rb @@ -29,19 +29,25 @@ class TestPort < Test::Unit::TestCase # Here we just create a fake host type that answers to all of the methods # but does not modify our actual system. def mkfaketype - @faketype = Puppet::FileType.filetype(:ram) - @porttype.filetype = @faketype + pfile = tempfile() + @porttype.path = pfile end def mkport port = nil + + if defined? @pcount + @pcount += 1 + else + @pcount = 1 + end assert_nothing_raised { port = Puppet.type(:port).create( - :name => "puppet", - :number => "8139", + :name => "puppet%s" % @pcount, + :number => "813%s" % @pcount, :protocols => "tcp", :description => "The port that Puppet runs on", - :alias => "coolness" + :alias => "coolness%s" % @pcount ) } @@ -134,6 +140,59 @@ class TestPort < Test::Unit::TestCase port.retrieve assert_events([], port) end + + def test_modifyingfile + mkfaketype() + + ports = [] + names = [] + 3.times { + k = mkport() + ports << k + names << k.name + } + assert_apply(*ports) + ports.clear + Puppet.type(:port).clear + newport = mkport() + #newport[:ensure] = :present + names << newport.name + assert_apply(newport) + Puppet.type(:port).clear + # Verify we can retrieve that info + assert_nothing_raised("Could not retrieve after second write") { + newport.retrieve + } + + # And verify that we have data for everything + names.each { |name| + port = Puppet.type(:port)[name] + assert(port) + port.retrieve + assert(port[:number], "port %s has no number" % name) + } + end + + def test_addingstates + mkfaketype + + port = mkport() + assert_events([:port_created], port) + + port.delete(:alias) + assert(! port.state(:alias)) + assert_events([:port_changed], port) + assert_nothing_raised { + port.retrieve + } + + assert(port.state(:alias).is == :absent) + + port[:alias] = "yaytest" + assert_events([:port_changed], port) + port.retrieve + assert(port.state(:alias).is == ["yaytest"]) + end end # $Id$ diff --git a/test/types/sshkey.rb b/test/types/sshkey.rb index 385b15a28..5186d06cc 100755 --- a/test/types/sshkey.rb +++ b/test/types/sshkey.rb @@ -35,12 +35,19 @@ class TestSSHKey < Test::Unit::TestCase def mkkey key = nil + + if defined? @kcount + @kcount += 1 + else + @kcount = 1 + end + assert_nothing_raised { key = @sshtype.create( - :name => "culain.madstop.com", - :key => "AAAAB3NzaC1kc3MAAACBAMnhSiku76y3EGkNCDsUlvpO8tRgS9wL4Eh54WZfQ2lkxqfd2uT/RTT9igJYDtm/+UHuBRdNGpJYW1Nw2i2JUQgQEEuitx4QKALJrBotejGOAWxxVk6xsh9xA0OW8Q3ZfuX2DDitfeC8ZTCl4xodUMD8feLtP+zEf8hxaNamLlt/AAAAFQDYJyf3vMCWRLjTWnlxLtOyj/bFpwAAAIEAmRxxXb4jjbbui9GYlZAHK00689DZuX0EabHNTl2yGO5KKxGC6Esm7AtjBd+onfu4Rduxut3jdI8GyQCIW8WypwpJofCIyDbTUY4ql0AQUr3JpyVytpnMijlEyr41FfIb4tnDqnRWEsh2H7N7peW+8DWZHDFnYopYZJ9Yu4/jHRYAAACAERG50e6aRRb43biDr7Ab9NUCgM9bC0SQscI/xdlFjac0B/kSWJYTGVARWBDWug705hTnlitY9cLC5Ey/t/OYOjylTavTEfd/bh/8FkAYO+pWdW3hx6p97TBffK0b6nrc6OORT2uKySbbKOn0681nNQh4a6ueR3JRppNkRPnTk5c=", + :name => "host%s.madstop.com" % @kcount, + :key => "%sAAAAB3NzaC1kc3MAAACBAMnhSiku76y3EGkNCDsUlvpO8tRgS9wL4Eh54WZfQ2lkxqfd2uT/RTT9igJYDtm/+UHuBRdNGpJYW1Nw2i2JUQgQEEuitx4QKALJrBotejGOAWxxVk6xsh9xA0OW8Q3ZfuX2DDitfeC8ZTCl4xodUMD8feLtP+zEf8hxaNamLlt/AAAAFQDYJyf3vMCWRLjTWnlxLtOyj/bFpwAAAIEAmRxxXb4jjbbui9GYlZAHK00689DZuX0EabHNTl2yGO5KKxGC6Esm7AtjBd+onfu4Rduxut3jdI8GyQCIW8WypwpJofCIyDbTUY4ql0AQUr3JpyVytpnMijlEyr41FfIb4tnDqnRWEsh2H7N7peW+8DWZHDFnYopYZJ9Yu4/jHRYAAACAERG50e6aRRb43biDr7Ab9NUCgM9bC0SQscI/xdlFjac0B/kSWJYTGVARWBDWug705hTnlitY9cLC5Ey/t/OYOjylTavTEfd/bh/8FkAYO+pWdW3hx6p97TBffK0b6nrc6OORT2uKySbbKOn0681nNQh4a6ueR3JRppNkRPnTk5c=" % @kcount, :type => "ssh-dss", - :alias => ["192.168.0.3"] + :alias => ["192.168.0.%s" % @kcount] ) } @@ -135,6 +142,40 @@ class TestSSHKey < Test::Unit::TestCase sshkey.retrieve assert_events([], sshkey) end + + def test_modifyingfile + keyfile = tempfile() + Puppet.type(:sshkey).path = keyfile + + keys = [] + names = [] + 3.times { + k = mkkey() + #h[:ensure] = :present + #h.retrieve + keys << k + names << k.name + } + assert_apply(*keys) + keys.clear + Puppet.type(:sshkey).clear + newkey = mkkey() + #newkey[:ensure] = :present + names << newkey.name + assert_apply(newkey) + Puppet.type(:sshkey).clear + # Verify we can retrieve that info + assert_nothing_raised("Could not retrieve after second write") { + newkey.retrieve + } + + # And verify that we have data for everything + names.each { |name| + key = Puppet.type(:sshkey)[name] + assert(key) + assert(key[:type]) + } + end end # $Id$ |
