summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-05 01:51:23 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-05 01:51:23 +0000
commit617fe58626aa8a13af10071ca87f66d6363cf058 (patch)
treedb9974c675c3b73cae56a253386f716e83bc8b6f /test
parent8f39318ce46148c3bd483d790c965f277a4eb1c9 (diff)
downloadpuppet-617fe58626aa8a13af10071ca87f66d6363cf058.tar.gz
puppet-617fe58626aa8a13af10071ca87f66d6363cf058.tar.xz
puppet-617fe58626aa8a13af10071ca87f66d6363cf058.zip
Removing all of the changes I made towards refactoring in the last couple of days. They have all been moved into the sync-retrieve-refactor branch. This branch will soon become 0.19.0, and will not include that refactoring.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1555 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rw-r--r--test/data/types/mount/linux.fstab2
-rwxr-xr-xtest/providers/parsedcron.rb744
-rw-r--r--test/providers/parsedhost.rb242
-rwxr-xr-xtest/providers/parsedmount.rb220
-rwxr-xr-xtest/providers/parsedport.rb61
-rwxr-xr-xtest/providers/parsedsshkey.rb38
-rw-r--r--test/puppettest.rb57
-rwxr-xr-xtest/types/cron.rb2
-rw-r--r--test/types/file.rb14
-rwxr-xr-xtest/types/group.rb17
-rwxr-xr-xtest/types/host.rb103
-rwxr-xr-xtest/types/mount.rb272
-rw-r--r--test/types/package.rb2
-rwxr-xr-xtest/types/port.rb116
-rwxr-xr-xtest/types/sshkey.rb83
-rwxr-xr-xtest/types/user.rb2
16 files changed, 428 insertions, 1547 deletions
diff --git a/test/data/types/mount/linux.fstab b/test/data/types/mount/linux.fstab
index 978103b69..06afe1242 100644
--- a/test/data/types/mount/linux.fstab
+++ b/test/data/types/mount/linux.fstab
@@ -4,7 +4,7 @@ LABEL=/boot /boot ext3 defaults 1 2
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
LABEL=/home /home ext3 defaults 1 2
-/home /homes auto bind 0 2
+/home /homes auto bind
proc /proc proc defaults 0 0
/dev/vg00/lv01 /spare ext3 defaults 1 2
sysfs /sys sysfs defaults 0 0
diff --git a/test/providers/parsedcron.rb b/test/providers/parsedcron.rb
deleted file mode 100755
index fafb0ee92..000000000
--- a/test/providers/parsedcron.rb
+++ /dev/null
@@ -1,744 +0,0 @@
-# Test cron job creation, modification, and destruction
-
-if __FILE__ == $0
- $:.unshift '..'
- $:.unshift '../lib'
- $puppetbase = "../.."
-end
-
-require 'puppettest'
-require 'puppet'
-require 'test/unit'
-require 'facter'
-
-class TestParsedCron < Test::Unit::TestCase
- include TestPuppet
- def setup
- super
- @provider = Puppet.type(:cron).provider(:parsed)
-
- @oldfiletype = @provider.filetype
- end
-
- def teardown
- Puppet::FileType.filetype(:ram).clear
- @provider.filetype = @oldfiletype
- super
- end
-
- def test_provider_existence
- assert(@provider, "Could not retrieve provider")
- end
-
- # Here we just create a fake cron type that answers to all of the methods
- # but does not modify our actual system.
- def mkfaketype
- @provider.filetype = Puppet::FileType.filetype(:ram)
- end
-
- def mkcronhash
- if defined? @hcount
- @hcount += 1
- else
- @hcount = 1
- end
-
- return {
- :name => "fakecron%s" % @hcount,
- :ip => "192.168.27.%s" % @hcount,
- :alias => ["alias%s" % @hcount]
- }
- end
-
- def mkcron
- hash = mkcronhash()
-
- fakemodel = fakemodel(:cron, hash[:name])
-
- cron = @provider.new(fakemodel)
-
- hash.each do |name, val|
- fakemodel[name] = val
- end
- assert(cron, "Could not create provider cron")
-
- return cron
- end
-
- # Back up the user's existing cron tab if they have one.
- def cronback
- tab = nil
- assert_nothing_raised {
- tab = Puppet.type(:cron).filetype.read(@me)
- }
-
- if $? == 0
- @currenttab = tab
- else
- @currenttab = nil
- end
- end
-
- # Restore the cron tab to its original form.
- def cronrestore
- assert_nothing_raised {
- if @currenttab
- @crontype.filetype.new(@me).write(@currenttab)
- else
- @crontype.filetype.new(@me).remove
- end
- }
- end
-
- # Create a cron job with all fields filled in.
- def mkcron(name)
- cron = nil
- assert_nothing_raised {
- cron = @crontype.create(
- :command => "date > %s/crontest%s" % [tmpdir(), name],
- :name => name,
- :user => @me,
- :minute => rand(59),
- :month => "1",
- :monthday => "1",
- :hour => "1"
- )
- }
-
- return cron
- end
-
- # Run the cron through its paces -- install it then remove it.
- def cyclecron(cron)
- obj = Puppet::Type::Cron.cronobj(@me)
-
- text = obj.read
- name = cron.name
- comp = newcomp(name, cron)
-
- assert_events([:cron_created], comp)
- cron.retrieve
-
- assert(cron.insync?, "Cron is not in sync")
-
- assert_events([], comp)
-
- curtext = obj.read
- text.split("\n").each do |line|
- assert(curtext.include?(line), "Missing '%s'" % line)
- end
- obj = Puppet::Type::Cron.cronobj(@me)
-
- cron[:ensure] = :absent
-
- assert_events([:cron_deleted], comp)
-
- cron.retrieve
-
- assert(cron.insync?, "Cron is not in sync")
- assert_events([], comp)
- end
-
- # A simple test to see if we can load the cron from disk.
- def test_load
- assert_nothing_raised {
- @crontype.retrieve(@me)
- }
- end
-
- # Test that a cron job turns out as expected, by creating one and generating
- # it directly
- def test_simple_to_cron
- cron = nil
- # make the cron
- name = "yaytest"
- assert_nothing_raised {
- cron = @crontype.create(
- :name => name,
- :command => "date > /dev/null",
- :user => @me
- )
- }
- str = nil
- # generate the text
- assert_nothing_raised {
- str = cron.to_record
- }
-
- assert_equal(str, "# Puppet Name: #{name}\n* * * * * date > /dev/null",
- "Cron did not generate correctly")
- end
-
- def test_simpleparsing
- @fakefiletype = Puppet::FileType.filetype(:ram)
- @crontype.filetype = @fakefiletype
-
- @crontype.retrieve(@me)
- obj = Puppet::Type::Cron.cronobj(@me)
-
- text = "5 1,2 * 1 0 /bin/echo funtest"
-
- assert_nothing_raised {
- @crontype.parse(@me, text)
- }
-
- @crontype.each do |obj|
- assert_equal(["5"], obj.is(:minute), "Minute was not parsed correctly")
- assert_equal(["1", "2"], obj.is(:hour), "Hour was not parsed correctly")
- assert_equal([:absent], obj.is(:monthday), "Monthday was not parsed correctly")
- assert_equal(["1"], obj.is(:month), "Month was not parsed correctly")
- assert_equal(["0"], obj.is(:weekday), "Weekday was not parsed correctly")
- assert_equal(["/bin/echo funtest"], obj.is(:command), "Command was not parsed correctly")
- end
- end
-
- # Test that changing any field results in the cron tab being rewritten.
- # it directly
- def test_any_field_changes
- cron = nil
- # make the cron
- name = "yaytest"
- assert_nothing_raised {
- cron = @crontype.create(
- :name => name,
- :command => "date > /dev/null",
- :month => "May",
- :user => @me
- )
- }
- assert(cron, "Cron did not get created")
- comp = newcomp(cron)
- assert_events([:cron_created], comp)
-
- assert_nothing_raised {
- cron[:month] = "June"
- }
-
- cron.retrieve
-
- assert_events([:cron_changed], comp)
- end
-
- # Test that a cron job with spaces at the end doesn't get rewritten
- def test_trailingspaces
- cron = nil
- # make the cron
- name = "yaytest"
- assert_nothing_raised {
- cron = @crontype.create(
- :name => name,
- :command => "date > /dev/null ",
- :month => "May",
- :user => @me
- )
- }
- comp = newcomp(cron)
-
- assert_events([:cron_created], comp, "did not create cron job")
- cron.retrieve
- assert_events([], comp, "cron job got rewritten")
- end
-
- # Test that comments are correctly retained
- def test_retain_comments
- str = "# this is a comment\n#and another comment\n"
- user = "fakeuser"
- @crontype.retrieve(@me)
- assert_nothing_raised {
- @crontype.parse(@me, str)
- }
-
- assert_nothing_raised {
- newstr = @crontype.tab(@me)
- assert(newstr.include?(str), "Comments were lost")
- }
- end
-
- # Test that a specified cron job will be matched against an existing job
- # with no name, as long as all fields match
- def test_matchcron
- str = "0,30 * * * * date\n"
-
- assert_nothing_raised {
- cron = @crontype.create(
- :name => "yaycron",
- :minute => [0, 30],
- :command => "date",
- :user => @me
- )
- }
-
- assert_nothing_raised {
- @crontype.parse(@me, str)
- }
-
- count = @crontype.inject(0) do |c, obj|
- c + 1
- end
-
- assert_equal(1, count, "Did not match cron job")
-
- modstr = "# Puppet Name: yaycron\n%s" % str
-
- assert_nothing_raised {
- newstr = @crontype.tab(@me)
- assert(newstr.include?(modstr),
- "Cron was not correctly matched")
- }
- end
-
- # Test adding a cron when there is currently no file.
- def test_mkcronwithnotab
- tab = @fakefiletype.new(@me)
- tab.remove
-
- @crontype.retrieve(@me)
- cron = mkcron("testwithnotab")
- cyclecron(cron)
- end
-
- def test_mkcronwithtab
- @crontype.retrieve(@me)
- obj = Puppet::Type::Cron.cronobj(@me)
- obj.write(
-"1 1 1 1 * date > %s/crontesting\n" % tstdir()
- )
-
- cron = mkcron("testwithtab")
- cyclecron(cron)
- end
-
- def test_makeandretrievecron
- tab = @fakefiletype.new(@me)
- tab.remove
-
- %w{storeandretrieve a-name another-name more_naming SomeName}.each do |name|
- cron = mkcron(name)
- comp = newcomp(name, cron)
- trans = assert_events([:cron_created], comp, name)
-
- cron = nil
-
- Puppet.type(:cron).retrieve(@me)
-
- assert(cron = Puppet.type(:cron)[name], "Could not retrieve named cron")
- assert_instance_of(Puppet.type(:cron), cron)
- end
- end
-
- # Do input validation testing on all of the parameters.
- def test_arguments
- values = {
- :monthday => {
- :valid => [ 1, 13, "1" ],
- :invalid => [ -1, 0, 32 ]
- },
- :weekday => {
- :valid => [ 0, 3, 6, "1", "tue", "wed",
- "Wed", "MOnday", "SaTurday" ],
- :invalid => [ -1, 7, "13", "tues", "teusday", "thurs" ]
- },
- :hour => {
- :valid => [ 0, 21, 23 ],
- :invalid => [ -1, 24 ]
- },
- :minute => {
- :valid => [ 0, 34, 59 ],
- :invalid => [ -1, 60 ]
- },
- :month => {
- :valid => [ 1, 11, 12, "mar", "March", "apr", "October", "DeCeMbEr" ],
- :invalid => [ -1, 0, 13, "marc", "sept" ]
- }
- }
-
- cron = mkcron("valtesting")
- values.each { |param, hash|
- # We have to test the valid ones first, because otherwise the
- # state will fail to create at all.
- [:valid, :invalid].each { |type|
- hash[type].each { |value|
- case type
- when :valid:
- assert_nothing_raised {
- cron[param] = value
- }
-
- if value.is_a?(Integer)
- assert_equal(value.to_s, cron.should(param),
- "Cron value was not set correctly")
- end
- when :invalid:
- assert_raise(Puppet::Error, "%s is incorrectly a valid %s" %
- [value, param]) {
- cron[param] = value
- }
- end
-
- if value.is_a?(Integer)
- value = value.to_s
- redo
- end
- }
- }
- }
- end
-
- # Test that we can read and write cron tabs
- def test_crontab
- Puppet.type(:cron).filetype = Puppet.type(:cron).defaulttype
- type = nil
- unless type = Puppet.type(:cron).filetype
- $stderr.puts "No crontab type; skipping test"
- end
-
- obj = nil
- assert_nothing_raised {
- obj = type.new(Process.uid)
- }
-
- txt = nil
- assert_nothing_raised {
- txt = obj.read
- }
-
- assert_nothing_raised {
- obj.write(txt)
- }
- end
-
- # Verify that comma-separated numbers are not resulting in rewrites
- def test_norewrite
- 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.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
-
- def test_listing
- @crontype.filetype = @oldfiletype
-
- crons = []
- assert_nothing_raised {
- Puppet::Type.type(:cron).list.each do |cron|
- crons << cron
- end
- }
-
- crons.each do |cron|
- assert(cron, "Did not receive a real cron object")
- assert_instance_of(String, cron[:user],
- "Cron user is not a string")
- end
- end
-
- def verify_failonnouser
- assert_raise(Puppet::Error) do
- @crontype.retrieve("nosuchuser")
- end
- end
-
- def test_names
- cron = mkcron("nametest")
-
- ["bad name", "bad.name"].each do |name|
- assert_raise(ArgumentError) do
- cron[:name] = name
- end
- end
-
- ["good-name", "good-name", "AGoodName"].each do |name|
- assert_nothing_raised do
- cron[:name] = name
- end
- end
- end
-
- # Make sure we don't puke on env settings
- def test_envsettings
- cron = mkcron("envtst")
-
- assert_apply(cron)
-
- obj = Puppet::Type::Cron.cronobj(@me)
-
- assert(obj)
-
- text = obj.read
-
- text = "SHELL = /path/to/some/thing\n" + text
-
- obj.write(text)
-
- assert_nothing_raised {
- cron.retrieve
- }
-
- cron[:command] = "/some/other/command"
-
- assert_apply(cron)
-
- assert(obj.read =~ /SHELL/, "lost env setting")
-
- env1 = "TEST = /bin/true"
- env2 = "YAY = fooness"
- assert_nothing_raised {
- cron[:environment] = [env1, env2]
- }
-
- assert_apply(cron)
- cron.retrieve
-
- vals = cron.is(:environment)
- assert(vals, "Did not get environment settings")
- assert(vals != :absent, "Env is incorrectly absent")
- assert_instance_of(Array, vals)
-
- assert(vals.include?(env1), "Missing first env setting")
- assert(vals.include?(env2), "Missing second env setting")
-
- end
-
- def test_divisionnumbers
- cron = mkcron("divtest")
- cron[:minute] = "*/5"
-
- assert_apply(cron)
-
- cron.retrieve
-
- assert_equal(["*/5"], cron.is(:minute))
- end
-
- def test_ranges
- cron = mkcron("rangetest")
- cron[:minute] = "2-4"
-
- assert_apply(cron)
-
- cron.retrieve
-
- assert_equal(["2-4"], cron.is(:minute))
- end
-
- def test_data
- @fakefiletype = Puppet::FileType.filetype(:ram)
- @crontype.filetype = @fakefiletype
-
- @crontype.retrieve(@me)
- obj = Puppet::Type::Cron.cronobj(@me)
-
- fakedata("data/types/cron").each do |file|
- names = []
- text = File.read(file)
- obj.write(File.read(file))
-
- @crontype.retrieve(@me)
-
- @crontype.each do |cron|
- names << cron.name
- end
-
- name = File.basename(file)
- cron = mkcron("filetest-#{name}")
-
- assert_apply(cron)
-
- @crontype.retrieve(@me)
-
- names.each do |name|
- assert(@crontype[name], "Could not retrieve %s" % name)
- end
-
- tablines = @crontype.tab(@me).split("\n")
-
- text.split("\n").each do |line|
- assert(tablines.include?(line),
- "Did not get %s back out" % line.inspect)
- end
- end
- end
-
- def test_value
- cron = mkcron("valuetesting")
-
- # First, test the normal states
- [:minute, :hour, :month].each do |param|
- state = cron.state(param)
-
- assert(state, "Did not get %s state" % param)
-
- assert_nothing_raised {
- state.should = :absent
- state.is = :absent
- }
-
- # Make sure our minute default is 0, not *
- val = if param == :minute
- "*" # the "0" thing is disabled for now
- else
- "*"
- end
- assert_equal(val, cron.value(param))
-
- # Make sure we correctly get the "is" value if that's all there is
- cron.is = [param, "1"]
- assert_equal("1", cron.value(param))
-
- # Make sure arrays work, too
- cron.is = [param, ["1"]]
- assert_equal("1", cron.value(param))
-
- # Make sure values get comma-joined
- cron.is = [param, ["2", "3"]]
- assert_equal("2,3", cron.value(param))
-
- # Make sure "should" values work, too
- cron[param] = "4"
- assert_equal("4", cron.value(param))
-
- cron[param] = ["4"]
- assert_equal("4", cron.value(param))
-
- cron[param] = ["4", "5"]
- assert_equal("4,5", cron.value(param))
-
- cron.is = [param, :absent]
- assert_equal("4,5", cron.value(param))
- end
-
- # Now make sure that :command works correctly
- state = cron.state(:command)
-
- assert_nothing_raised {
- state.should = :absent
- state.is = :absent
- }
-
- assert(state, "Did not get command state")
- assert_raise(Puppet::DevError) do
- cron.value(:command)
- end
-
- param = :command
- # Make sure we correctly get the "is" value if that's all there is
- cron.is = [param, "1"]
- assert_equal("1", cron.value(param))
-
- # Make sure arrays work, too
- cron.is = [param, ["1"]]
- assert_equal("1", cron.value(param))
-
- # Make sure values are not comma-joined
- cron.is = [param, ["2", "3"]]
- assert_equal("2", cron.value(param))
-
- # Make sure "should" values work, too
- cron[param] = "4"
- assert_equal("4", cron.value(param))
-
- cron[param] = ["4"]
- assert_equal("4", cron.value(param))
-
- cron[param] = ["4", "5"]
- assert_equal("4", cron.value(param))
-
- cron.is = [param, :absent]
- assert_equal("4", cron.value(param))
- end
-
- # Make sure we can successfully list all cron jobs on all users
- def test_cron_listing
- crons = []
- %w{fake1 fake2 fake3 fake4 fake5}.each do |user|
- crons << @crontype.create(
- :name => "#{user}-1",
- :command => "/usr/bin/#{user}",
- :minute => "0",
- :user => user,
- :hour => user.sub("fake",'')
- )
-
- crons << @crontype.create(
- :name => "#{user}-2",
- :command => "/usr/sbin/#{user}",
- :minute => "0",
- :user => user,
- :weekday => user.sub("fake",'')
- )
-
- assert_apply(*crons)
- end
-
- list = @crontype.list.collect { |c| c.name }
-
- crons.each do |cron|
- assert(list.include?(cron.name), "Did not match cron %s" % name)
- end
- end
-
- # Make sure we can create a cron in an empty tab
- def test_mkcron_if_empty
- @crontype.filetype = @oldfiletype
-
- @crontype.retrieve(@me)
-
- # Backup our tab
- text = @crontype.tabobj(@me).read
-
- cleanup do
- if text == ""
- @crontype.tabobj(@me).remove
- else
- @crontype.tabobj(@me).write(text)
- end
- end
-
- # Now get rid of it
- @crontype.tabobj(@me).remove
- @crontype.clear
-
- cron = mkcron("emptycron")
-
- assert_apply(cron)
-
- # Clear the type, but don't clear the filetype
- @crontype.clear
-
- # Get the stuff again
- @crontype.retrieve(@me)
-
- assert(@crontype["emptycron"],
- "Did not retrieve cron")
- end
-end
-
-# $Id$
diff --git a/test/providers/parsedhost.rb b/test/providers/parsedhost.rb
deleted file mode 100644
index bb122129a..000000000
--- a/test/providers/parsedhost.rb
+++ /dev/null
@@ -1,242 +0,0 @@
-if __FILE__ == $0
- $:.unshift '..'
- $:.unshift '../../lib'
- $puppetbase = "../.."
-end
-
-require 'etc'
-require 'puppet/type'
-require 'puppettest'
-require 'test/unit'
-
-class TestParsedHostProvider < Test::Unit::TestCase
- include TestPuppet
-
- def setup
- super
- @provider = Puppet.type(:host).provider(:parsed)
-
- @oldfiletype = @provider.filetype
- end
-
- def teardown
- Puppet::FileType.filetype(:ram).clear
- @provider.filetype = @oldfiletype
- 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::FileType.filetype(:ram)
- end
-
- def mkhosthash
- if defined? @hcount
- @hcount += 1
- else
- @hcount = 1
- end
-
- return {
- :name => "fakehost%s" % @hcount,
- :ip => "192.168.27.%s" % @hcount,
- :alias => ["alias%s" % @hcount]
- }
- end
-
- def mkhost
- hash = mkhosthash()
-
- fakemodel = fakemodel(:host, hash[:name])
-
- host = @provider.new(fakemodel)
-
- hash.each do |name, val|
- fakemodel[name] = val
- end
- assert(host, "Could not create provider host")
-
- return host
- end
-
- # Make sure we convert both directlys correctly using a simple host.
- def test_basic_isomorphism
- hash = {:name => "myhost", :ip => "192.168.43.56", :alias => %w{another host}}
-
- str = nil
- assert_nothing_raised do
- str = @provider.to_record(hash)
- end
-
- assert_equal("192.168.43.56\tmyhost\tanother\thost", str)
-
- newhash = nil
- assert_nothing_raised do
- newhash = @provider.parse(str).shift
- end
-
- 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
-
-# another comment
-192.168.43.57\tanotherhost
-}
-
- instances = nil
- assert_nothing_raised do
- instances = @provider.parse(text)
- end
-
- assert_equal([
- "# comment one",
- "",
- {:name => "myhost", :ip => "192.168.43.56", :alias => %w{another host}},
- " ",
- "# another comment",
- {:name => "anotherhost", :ip => "192.168.43.57"}
- ], instances)
-
- assert_nothing_raised do
- @provider.store(instances)
- end
- newtext = nil
- assert_nothing_raised do
- newtext = @provider.fileobj.read
- end
-
- assert_equal(text, newtext)
- end
-
- def test_empty_and_absent_hashes_are_not_written
- mkfaketype()
-
- instances = [
- {:name => "myhost", :ip => "192.168.43.56", :alias => %w{another host}},
- {},
- {:ensure => :absent, :name => "anotherhost", :ip => "192.168.43.57"}
- ]
-
- assert_nothing_raised do
- newtext = @provider.store(instances)
- end
- newtext = nil
- assert_nothing_raised do
- newtext = @provider.fileobj.read
- end
- text = "192.168.43.56\tmyhost\tanother\thost\n"
-
- assert_equal(text, newtext)
- end
-
- def test_simplehost
- mkfaketype
- # Start out with no content.
- assert_nothing_raised {
- assert_equal([], @provider.retrieve)
- }
-
- # Now create a provider
- host = nil
- assert_nothing_raised {
- host = mkhost
- }
-
- # Make sure we're still empty
- assert_nothing_raised {
- assert_equal([], @provider.retrieve)
- }
-
- hash = host.model.to_hash
-
- # Try storing it
- assert_nothing_raised do
- host.store(hash)
- end
-
- # Make sure we get the host back
- assert_nothing_raised {
- assert_equal([hash], @provider.retrieve)
- }
-
- # Remove a single field and make sure it gets tossed
- hash.delete(:alias)
-
- assert_nothing_raised {
- host.store(hash)
- assert_equal([hash], @provider.retrieve)
- }
-
- # Make sure it throws up if we remove a required field
- hash.delete(:ip)
-
- assert_raise(ArgumentError) {
- host.store(hash)
- }
-
- # Now remove the whole object
- assert_nothing_raised {
- host.store({})
- assert_equal([], @provider.retrieve)
- }
- 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.path = hostfile
-
- hosts = []
- 3.times {
- h = mkhost()
- hosts << h
- }
-
- hosts.each do |host|
- host.store
- end
-
- newhost = mkhost()
- hosts << newhost
-
- # Now store our new host
- newhost.store()
-
- # Verify we can retrieve that info
- assert_nothing_raised("Could not retrieve after second write") {
- newhost.hash
- }
-
- text = @provider.fileobj.read
-
- instances = @provider.retrieve
-
- # And verify that we have data for everything
- hosts.each { |host|
- name = host.model[:name]
- assert(text.include?(name), "Host %s is not in file" % name)
- hash = host.hash
- assert(! hash.empty?, "Could not find host %s" % name)
- assert(hash[:ip], "Could not find ip for host %s" % name)
- }
- end
-end
-
-# $Id$
diff --git a/test/providers/parsedmount.rb b/test/providers/parsedmount.rb
deleted file mode 100755
index a1630f7be..000000000
--- a/test/providers/parsedmount.rb
+++ /dev/null
@@ -1,220 +0,0 @@
-if __FILE__ == $0
- $:.unshift '..'
- $:.unshift '../../lib'
- $puppetbase = "../.."
-end
-
-require 'puppettest'
-require 'puppet'
-require 'test/unit'
-require 'facter'
-
-class TestParsedMounts < Test::Unit::TestCase
- include TestPuppet
-
- def setup
- super
- @provider = Puppet.type(:mount).provider(:parsed)
-
- @oldfiletype = @provider.filetype
- end
-
- def teardown
- Puppet::FileType.filetype(:ram).clear
- @provider.filetype = @oldfiletype
- super
- end
-
- def mkmountargs
- mount = nil
-
- if defined? @pcount
- @pcount += 1
- else
- @pcount = 1
- end
- args = {
- :path => "/fspuppet%s" % @pcount,
- :device => "/dev/dsk%s" % @pcount,
- }
-
- @provider.fields.each do |field|
- unless args.include? field
- args[field] = "fake%s" % @pcount
- end
- end
-
- return args
- end
-
- def mkmount
- hash = mkmountargs()
- #hash[:provider] = @provider.name
-
- fakemodel = fakemodel(:mount, hash[:name])
-
- mount = @provider.new(fakemodel)
- #mount = Puppet.type(:mount).create(hash)
-
- hash.each do |name, val|
- fakemodel[name] = val
- end
- assert(mount, "Could not create provider mount")
-
- return mount
- 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::FileType.filetype(:ram)
- end
-
- def test_simplemount
- mkfaketype
- assert_nothing_raised {
- assert_equal([], @provider.retrieve)
- }
-
- # Now create a provider
- mount = nil
- assert_nothing_raised {
- mount = mkmount
- }
-
- # Make sure we're still empty
- assert_nothing_raised {
- assert_equal([], @provider.retrieve)
- }
-
- hash = mount.model.to_hash
-
- if hash.has_key? :name
- hash.delete :name
- end
-
- # Try storing it
- assert_nothing_raised do
- mount.store(hash)
- end
-
- # Make sure we get the mount back
- assert_nothing_raised {
- assert_equal([hash], @provider.retrieve)
- }
-
- # Now remove the whole object
- assert_nothing_raised {
- mount.store({})
- assert_equal([], @provider.retrieve)
- }
- end
-
- unless Facter["operatingsystem"].value == "Darwin"
- def test_mountsparse
- fakedataparse(fake_fstab) do
- # Now just make we've got some mounts we know will be there
- hashes = @provider.retrieve.find_all { |i| i.is_a? Hash }
- assert(hashes.length > 0, "Did not create any hashes")
- root = hashes.find { |i| i[:path] == "/" }
- assert(root, "Could not retrieve root mount")
- end
- end
-
- def test_rootfs
- fs = nil
- @provider.path = fake_fstab()
- fakemodel = fakemodel(:mount, "/")
- mount = @provider.new(fakemodel)
- mount.model[:path] = "/"
- assert(mount.hash, "Could not retrieve root fs")
-
- assert_nothing_raised {
- assert(mount.mounted?, "Root is considered not mounted")
- }
- end
- end
-
- if Process.uid == 0
- def test_mountfs
- fs = nil
- case Facter["hostname"].value
- when "culain": fs = "/ubuntu"
- when "atalanta": fs = "/mnt"
- when "figurehead": fs = "/cg4/net/depts"
- else
- $stderr.puts "No mount for mount testing; skipping"
- return
- end
-
- oldtext = @provider.fileobj.read
-
- ftype = @provider.filetype
-
- # Make sure the original gets reinstalled.
- if ftype == Puppet::FileType.filetype(:netinfo)
- cleanup do
- IO.popen("niload -r /mounts .", "w") do |file|
- file.puts oldtext
- end
- end
- else
- cleanup do
- @provider.fileobj.write(oldtext)
- end
- end
-
- fakemodel = fakemodel(:mount, "/")
- obj = @provider.new(fakemodel)
- obj.model[:path] = fs
-
- current = nil
-
- assert_nothing_raised {
- current = obj.mounted?
- }
-
- if current
- # Make sure the original gets reinstalled.
- cleanup do
- unless obj.mounted?
- obj.mount
- end
- end
- end
-
- unless current
- assert_nothing_raised {
- obj.mount
- }
- end
-
- assert_nothing_raised {
- obj.unmount
- }
- assert(! obj.mounted?, "FS still mounted")
- assert_nothing_raised {
- obj.mount
- }
- assert(obj.mounted?, "FS not mounted")
-
- end
- end
-
- def fake_fstab
- os = Facter['operatingsystem']
- if os == "Solaris"
- name = "solaris.fstab"
- elsif os == "FreeBSD"
- name = "freebsd.fstab"
- else
- # Catchall for other fstabs
- name = "linux.fstab"
- end
- oldpath = @provider.path
- cleanup do @provider.path = oldpath end
- return fakefile(File::join("data/types/mount", name))
- end
-end
-
-# $Id$
diff --git a/test/providers/parsedport.rb b/test/providers/parsedport.rb
deleted file mode 100755
index 51901f7f4..000000000
--- a/test/providers/parsedport.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-# Test host job creation, modification, and destruction
-
-if __FILE__ == $0
- $:.unshift '..'
- $:.unshift '../../lib'
- $puppetbase = "../.."
-end
-
-require 'puppettest'
-require 'puppet'
-require 'puppet/type/parsedtype/port'
-require 'test/unit'
-require 'facter'
-
-class TestParsedPort < Test::Unit::TestCase
- include TestPuppet
-
- def setup
- super
- @provider = Puppet.type(:port).provider(:parsed)
-
- @oldfiletype = @provider.filetype
- end
-
- def teardown
- Puppet::FileType.filetype(:ram).clear
- @provider.filetype = @oldfiletype
- super
- end
-
- # Parse our sample data and make sure we regenerate it correctly.
- def test_portsparse
- fakedata("data/types/ports").each do |file|
- @provider.path = file
- instances = nil
- assert_nothing_raised {
- instances = @provider.retrieve
- }
-
- text = @provider.fileobj.read.gsub(/\s+/, ' ')
- text.gsub!(/ #.+$/, '')
-
- dest = tempfile()
- @provider.path = dest
-
- # Now write it back out
- assert_nothing_raised {
- @provider.store(instances)
- }
-
- newtext = @provider.fileobj.read.gsub(/\s+/, ' ')
-
- newtext.gsub!(/ #.+$/, '')
-
- # Don't worry about difference in whitespace
- assert_equal(text.gsub(/\s+/, ' '), newtext.gsub(/\s+/, ' '))
- end
- end
-end
-
-# $Id$
diff --git a/test/providers/parsedsshkey.rb b/test/providers/parsedsshkey.rb
deleted file mode 100755
index 7f21a58b4..000000000
--- a/test/providers/parsedsshkey.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# Test key job creation, modification, and destruction
-
-if __FILE__ == $0
- $:.unshift '..'
- $:.unshift '../../lib'
- $puppetbase = "../.."
-end
-
-require 'puppettest'
-require 'puppet'
-require 'puppet/type/parsedtype/sshkey'
-require 'test/unit'
-require 'facter'
-
-class TestParsedSSHKey < Test::Unit::TestCase
- include TestPuppet
-
- def setup
- super
- @provider = Puppet.type(:sshkey).provider(:parsed)
-
- @oldfiletype = @provider.filetype
- end
-
- def teardown
- Puppet::FileType.filetype(:ram).clear
- @provider.filetype = @oldfiletype
- super
- end
-
- def test_keysparse
- fakedata("data/types/sshkey").each { |file|
- fakedataparse(file)
- }
- end
-end
-
-# $Id$
diff --git a/test/puppettest.rb b/test/puppettest.rb
index 2506f9fc3..f094045cd 100644
--- a/test/puppettest.rb
+++ b/test/puppettest.rb
@@ -35,10 +35,6 @@ module TestPuppet
def name
self[:name]
end
-
- def to_hash
- self
- end
end
class FakeProvider
@@ -80,33 +76,6 @@ module TestPuppet
def initialize(model)
@model = model
end
-
- # Called in Type#remove
- def remove(var = true)
- end
- end
-
- class FakeParsedProvider < FakeProvider
- def hash
- ret = {}
- instance_variables.each do |v|
- v = v.sub("@", '')
- if val = self.send(v)
- ret[v.intern] = val
- end
- end
-
- return ret
- end
-
- def store(hash)
- hash.each do |n, v|
- method = n.to_s + "="
- if respond_to? method
- send(method, v)
- end
- end
- end
end
@@fakemodels = {}
@@ -467,32 +436,6 @@ module TestPuppet
return file
end
- # Run an isomorphism test on our parsing process.
- def fakedataparse(file)
- @provider.path = file
- instances = nil
- assert_nothing_raised {
- instances = @provider.retrieve
- }
-
- text = @provider.fileobj.read
-
- yield if block_given?
-
- dest = tempfile()
- @provider.path = dest
-
- # Now write it back out
- assert_nothing_raised {
- @provider.store(instances)
- }
-
- newtext = @provider.fileobj.read
-
- # Don't worry about difference in whitespace
- assert_equal(text.gsub(/\s+/, ' '), newtext.gsub(/\s+/, ' '))
- end
-
# wrap how to retrieve the masked mode
def filemode(file)
File.stat(file).mode & 007777
diff --git a/test/types/cron.rb b/test/types/cron.rb
index 94e490e40..caada9f91 100755
--- a/test/types/cron.rb
+++ b/test/types/cron.rb
@@ -97,7 +97,7 @@ class TestCron < Test::Unit::TestCase
cron[:ensure] = :absent
- assert_events([:cron_deleted], comp)
+ assert_events([:cron_removed], comp)
cron.retrieve
diff --git a/test/types/file.rb b/test/types/file.rb
index 194d00958..3dc296cc0 100644
--- a/test/types/file.rb
+++ b/test/types/file.rb
@@ -704,6 +704,8 @@ class TestFile < Test::Unit::TestCase
assert_events([:file_created], obj)
+ obj.retrieve
+
assert(obj.insync?, "Object is not in sync")
text = File.read(file)
@@ -793,17 +795,18 @@ class TestFile < Test::Unit::TestCase
dest = tempfile()
file = nil
- str = "some content, ok?"
assert_nothing_raised {
file = Puppet.type(:file).create(
:name => dest,
:ensure => "file",
- :content => str
+ :content => "this is some content, yo"
)
}
+ file.retrieve
+
assert_events([:file_created], file)
- assert_equal(str, File.read(dest))
+ file.retrieve
assert_events([], file)
assert_events([], file)
end
@@ -1197,7 +1200,7 @@ class TestFile < Test::Unit::TestCase
}
# First run through without :force
- assert_events([], file, "Link replaced directory without force enabled")
+ assert_events([], file)
assert(FileTest.directory?(link), "Link replaced dir without force")
@@ -1373,12 +1376,11 @@ class TestFile < Test::Unit::TestCase
lfobj = Puppet::Type.newfile(:path => localfile, :content => "rahtest")
- assert(! lfobj.implicit?, "object incorrectly implicit")
-
destobj = Puppet::Type.newfile(:path => destdir,
:source => sourcedir,
:recurse => true)
+
assert_apply(lfobj, destobj)
assert(FileTest.exists?(dsourcefile), "File did not get copied")
diff --git a/test/types/group.rb b/test/types/group.rb
index 2b47f14d4..508b8436c 100755
--- a/test/types/group.rb
+++ b/test/types/group.rb
@@ -18,9 +18,6 @@ class TestGroup < Test::Unit::TestCase
def create
@ensure = :present
-
- # Just set a fake gid
- self.gid = 10
end
def delete
@@ -79,7 +76,7 @@ class TestGroup < Test::Unit::TestCase
assert_events([:group_created], comp)
assert_equal(:present, group.provider.ensure, "Group is absent")
group[:ensure] = :absent
- trans = assert_events([:group_deleted], comp)
+ trans = assert_events([:group_removed], comp)
assert_equal(:absent, group.provider.ensure, "Group is present")
assert_rollback_events(trans, [:group_created], "group")
@@ -89,6 +86,7 @@ class TestGroup < Test::Unit::TestCase
# This is a bit odd, since we're not actually doing anything on the machine.
# Just make sure we can set the gid and that it will work correctly.
def attrtest_gid(group)
+
# Check the validation.
assert_nothing_raised {
group[:gid] = "15"
@@ -98,8 +96,7 @@ class TestGroup < Test::Unit::TestCase
"Did not convert gid to number")
comp = newcomp(group)
-
- trans = assert_events([:group_changed], comp, "group")
+ trans = assert_events([:group_modified], comp, "group")
assert_equal(15, group.provider.gid, "GID was not changed")
assert_nothing_raised {
@@ -110,12 +107,12 @@ class TestGroup < Test::Unit::TestCase
"Did not keep gid as number")
# Now switch to 16
- trans = assert_events([:group_changed], comp, "group")
+ trans = assert_events([:group_modified], comp, "group")
assert_equal(16, group.provider.gid, "GID was not changed")
# And then rollback
- assert_rollback_events(trans, [:group_changed], "group")
- assert_equal(15, group.provider.gid, "GID was not reverted")
+ assert_rollback_events(trans, [:group_modified], "group")
+ assert_equal(15, group.provider.gid, "GID was not changed")
end
def test_owngroups
@@ -170,7 +167,7 @@ class TestGroup < Test::Unit::TestCase
end
}
- assert_rollback_events(trans, [:group_deleted], "group")
+ assert_rollback_events(trans, [:group_removed], "group")
assert(! gobj.provider.exists?,
"Did not delete group")
diff --git a/test/types/host.rb b/test/types/host.rb
index 54596aa7f..8af9e3e4a 100755
--- a/test/types/host.rb
+++ b/test/types/host.rb
@@ -13,25 +13,24 @@ require 'facter'
class TestHost < Test::Unit::TestCase
include TestPuppet
-
def setup
super
+ # god i'm lazy
@hosttype = Puppet.type(:host)
+ @oldhosttype = @hosttype.filetype
+ end
- @provider = @hosttype.defaultprovider
-
- # Make sure they aren't using something funky like netinfo
- unless @provider.name == :parsed
- @hosttype.defaultprovider = @hosttype.provider(:parsed)
- end
-
- cleanup do @hosttype.defaultprovider = nil end
+ def teardown
+ Puppet::FileType.filetype(:ram).clear
+ @hosttype.filetype = @oldhosttype
+ Puppet.type(:file).clear
+ super
+ end
- oldpath = @provider.path
- cleanup do
- @provider.path = oldpath
- end
- @provider.path = tempfile()
+ # Here we just create a fake host type that answers to all of the methods
+ # but does not modify our actual system.
+ def mkfaketype
+ @hosttype.filetype = Puppet::FileType.filetype(:ram)
end
def mkhost
@@ -53,16 +52,10 @@ class TestHost < Test::Unit::TestCase
end
def test_simplehost
+ mkfaketype
host = nil
assert_nothing_raised {
- Puppet.type(:host).defaultprovider.retrieve
-
- count = 0
- @hosttype.each do |h|
- count += 1
- end
-
- assert_equal(0, count, "Found hosts in empty file somehow")
+ assert_nil(Puppet.type(:host).retrieve)
}
assert_nothing_raised {
@@ -72,14 +65,49 @@ class TestHost < Test::Unit::TestCase
)
}
- assert_apply(host)
+ assert_nothing_raised {
+ Puppet.type(:host).store
+ }
+
+ assert_nothing_raised {
+ assert(
+ Puppet.type(:host).to_file.include?(
+ Puppet.type(:host).fileobj.read
+ ),
+ "File does not include all of our objects"
+ )
+ }
+ end
+
+ def test_hostsparse
+ fakedata("data/types/hosts").each { |file|
+ @hosttype.path = file
+ Puppet.info "Parsing %s" % file
+ assert_nothing_raised {
+ Puppet.type(:host).retrieve
+ }
+
+ text = Puppet.type(:host).fileobj.read
- assert_nothing_raised { host.retrieve }
+ dest = tempfile()
+ @hosttype.path = dest
- assert_equal(:present, host.is(:ensure))
+ # Now write it back out
+ assert_nothing_raised {
+ Puppet.type(:host).store
+ }
+
+ newtext = Puppet.type(:host).fileobj.read
+
+ # Don't worry about difference in whitespace
+ assert_equal(text.gsub(/\s+/, ' '), newtext.gsub(/\s+/, ' '))
+
+ @hosttype.clear
+ }
end
def test_moddinghost
+ mkfaketype
host = mkhost()
assert_events([:host_created], host)
@@ -117,33 +145,34 @@ class TestHost < Test::Unit::TestCase
end
def test_removal
+ mkfaketype
host = mkhost()
assert_nothing_raised {
host[:ensure] = :present
}
assert_events([:host_created], host)
- assert(host.exists?, "Host is not considered in sync")
-
- assert_equal(:present, host.is(:ensure))
-
+ host.retrieve
+ assert(host.insync?)
assert_nothing_raised {
host[:ensure] = :absent
}
- assert_events([:host_deleted], host)
-
- text = host.provider.class.fileobj.read
- assert(! text.include?(host[:name]), "Host is still in text")
+ assert_events([:host_removed], host)
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
}
@@ -151,18 +180,20 @@ class TestHost < Test::Unit::TestCase
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
}
- text = newhost.provider.class.fileobj.read
-
# And verify that we have data for everything
names.each { |name|
- assert(text.include?(name), "Host is not in file")
+ host = Puppet.type(:host)[name]
+ assert(host)
+ assert(host[:ip])
}
end
end
diff --git a/test/types/mount.rb b/test/types/mount.rb
index c7bd378a9..70170289e 100755
--- a/test/types/mount.rb
+++ b/test/types/mount.rb
@@ -8,63 +8,40 @@ end
require 'puppettest'
require 'puppet'
+require 'puppet/type/parsedtype/mount'
require 'test/unit'
+require 'facter'
class TestMounts < Test::Unit::TestCase
include TestPuppet
-
- p = Puppet::Type.type(:mount).provide :fake, :parent => TestPuppet::FakeParsedProvider do
- @name = :fake
- apimethods :ensure
-
- attr_accessor :mounted
-
- def create
- @ensure = :present
- end
-
- def delete
- @ensure = :absent
- @mounted = false
- end
-
- def exists?
- if defined? @ensure and @ensure == :present
- true
- else
- false
- end
- end
-
- def mounted?
- self.mounted
- end
-
- def mount
- self.mounted = true
- end
-
- def unmount
- self.mounted = false
- end
- end
-
- FakeMountProvider = p
-
- @@fakeproviders[:mount] = p
-
def setup
super
- @realprovider = Puppet::Type.type(:mount).defaultprovider
- Puppet::Type.type(:mount).defaultprovider = FakeMountProvider
+ @mounttype = Puppet.type(:mount)
+ @oldfiletype = @mounttype.filetype
end
def teardown
- Puppet.type(:mount).clear
- Puppet::Type.type(:mount).defaultprovider = nil
+ @mounttype.filetype = @oldfiletype
+ Puppet.type(:file).clear
super
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
+ pfile = tempfile()
+ old = @mounttype.filetype
+ @mounttype.filetype = Puppet::FileType.filetype(:ram)
+
+ cleanup do
+ @mounttype.filetype = old
+ @mounttype.fileobj = nil
+ end
+
+ # Reset this, just in case
+ @mounttype.fileobj = nil
+ end
+
def mkmount
mount = nil
@@ -78,7 +55,7 @@ class TestMounts < Test::Unit::TestCase
:device => "/dev/dsk%s" % @pcount,
}
- @realprovider.fields.each do |field|
+ Puppet.type(:mount).fields.each do |field|
unless args.include? field
args[field] = "fake%s" % @pcount
end
@@ -92,47 +69,178 @@ class TestMounts < Test::Unit::TestCase
end
def test_simplemount
- mount = nil
- oldprv = Puppet.type(:mount).defaultprovider
- Puppet.type(:mount).defaultprovider = nil
+ mkfaketype
+ host = nil
assert_nothing_raised {
- Puppet.type(:mount).defaultprovider.retrieve
+ assert_nil(Puppet.type(:mount).retrieve)
+ }
- count = 0
- Puppet.type(:mount).each do |h|
- count += 1
- end
+ mount = mkmount
- assert_equal(0, count, "Found mounts in empty file somehow")
+ assert_nothing_raised {
+ Puppet.type(:mount).store
}
- Puppet.type(:mount).defaultprovider = oldprv
- mount = mkmount
+ assert_nothing_raised {
+ assert(
+ Puppet.type(:mount).to_file.include?(
+ Puppet.type(:mount).fileobj.read
+ ),
+ "File does not include all of our objects"
+ )
+ }
+ end
+
+ unless Facter["operatingsystem"].value == "Darwin"
+ def test_mountsparse
+ use_fake_fstab
+ assert_nothing_raised {
+ @mounttype.retrieve
+ }
+
+ # Now just make we've got some mounts we know will be there
+ root = @mounttype["/"]
+ assert(root, "Could not retrieve root mount")
+ end
+
+ def test_rootfs
+ fs = nil
+ use_fake_fstab
+ assert_nothing_raised {
+ Puppet.type(:mount).retrieve
+ }
+
+ assert_nothing_raised {
+ fs = Puppet.type(:mount)["/"]
+ }
+ assert(fs, "Could not retrieve root fs")
+
+ assert_nothing_raised {
+ assert(fs.mounted?, "Root is considered not mounted")
+ }
+ end
+ end
+
+ # Make sure it reads and writes correctly.
+ def test_readwrite
+ use_fake_fstab
+ assert_nothing_raised {
+ Puppet::Type.type(:mount).retrieve
+ }
+
+ oldtype = Puppet::Type.type(:mount).filetype
+
+ # Now switch to storing in ram
+ mkfaketype
+
+ fs = mkmount
- assert_apply(mount)
+ assert(Puppet::Type.type(:mount).filetype != oldtype)
- assert_nothing_raised { mount.retrieve }
+ assert_events([:mount_created], fs)
- assert_equal(:mounted, mount.is(:ensure))
+ text = Puppet::Type.type(:mount).fileobj.read
+
+ assert(text =~ /#{fs[:path]}/, "Text did not include new fs")
+
+ fs[:ensure] = :absent
+
+ assert_events([:mount_removed], fs)
+ text = Puppet::Type.type(:mount).fileobj.read
+
+ assert(text !~ /#{fs[:path]}/, "Text still includes new fs")
+
+ fs[:ensure] = :present
+
+ assert_events([:mount_created], fs)
+
+ text = Puppet::Type.type(:mount).fileobj.read
+
+ assert(text =~ /#{fs[:path]}/, "Text did not include new fs")
+
+ fs[:options] = "rw,noauto"
+
+ assert_events([:mount_changed], fs)
end
- # Make sure fs mounting behaves appropriately. This is more a test of
- # whether things get mounted and unmounted based on the value of 'ensure'.
+ if Process.uid == 0
def test_mountfs
- obj = mkmount
+ fs = nil
+ case Facter["hostname"].value
+ when "culain": fs = "/ubuntu"
+ when "atalanta": fs = "/mnt"
+ when "figurehead": fs = "/cg4/net/depts"
+ else
+ $stderr.puts "No mount for mount testing; skipping"
+ return
+ end
+
+ assert_nothing_raised {
+ Puppet.type(:mount).retrieve
+ }
+
+ oldtext = Puppet::Type.type(:mount).fileobj.read
+
+ ftype = Puppet::Type.type(:mount).filetype
+
+ # Make sure the original gets reinstalled.
+ if ftype == Puppet::FileType.filetype(:netinfo)
+ cleanup do
+ IO.popen("niload -r /mounts .", "w") do |file|
+ file.puts oldtext
+ end
+ end
+ else
+ cleanup do
+ Puppet::Type.type(:mount).fileobj.write(oldtext)
+ end
+ end
+
+ obj = Puppet.type(:mount)[fs]
- assert_apply(obj)
+ assert(obj, "Could not retrieve %s object" % fs)
+
+ current = nil
+
+ assert_nothing_raised {
+ current = obj.mounted?
+ }
+
+ if current
+ # Make sure the original gets reinstalled.
+ cleanup do
+ unless obj.mounted?
+ obj.mount
+ end
+ end
+ end
+
+ unless current
+ assert_nothing_raised {
+ obj.mount
+ }
+ end
+
+ # Now copy all of the states' "is" values to the "should" values
+ obj.each do |state|
+ state.should = state.is
+ end
# Verify we can remove the mount
assert_nothing_raised {
obj[:ensure] = :absent
}
- assert_events([:mount_deleted], obj)
+ assert_events([:mount_removed], obj)
assert_events([], obj)
# And verify it's gone
- assert(!obj.provider.mounted?, "Object is mounted after being removed")
+ assert(!obj.mounted?, "Object is mounted after being removed")
+
+ text = Puppet.type(:mount).fileobj.read
+
+ assert(text !~ /#{fs}/,
+ "Fstab still contains %s" % fs)
assert_nothing_raised {
obj[:ensure] = :present
@@ -141,7 +249,10 @@ class TestMounts < Test::Unit::TestCase
assert_events([:mount_created], obj)
assert_events([], obj)
- assert(! obj.provider.mounted?, "Object is mounted incorrectly")
+ text = Puppet::Type.type(:mount).fileobj.read
+ assert(text =~ /#{fs}/, "Fstab does not contain %s" % fs)
+
+ assert(! obj.mounted?, "Object is mounted incorrectly")
assert_nothing_raised {
obj[:ensure] = :mounted
@@ -150,8 +261,33 @@ class TestMounts < Test::Unit::TestCase
assert_events([:mount_mounted], obj)
assert_events([], obj)
+ text = Puppet::Type.type(:mount).fileobj.read
+ assert(text =~ /#{fs}/,
+ "Fstab does not contain %s" % fs)
+
obj.retrieve
- assert(obj.provider.mounted?, "Object is not mounted")
+ assert(obj.mounted?, "Object is not mounted")
+
+ unless current
+ assert_nothing_raised {
+ obj.unmount
+ }
+ end
+ end
+ end
+
+ def use_fake_fstab
+ os = Facter['operatingsystem']
+ if os == "Solaris"
+ name = "solaris.fstab"
+ elsif os == "FreeBSD"
+ name = "freebsd.fstab"
+ else
+ # Catchall for other fstabs
+ name = "linux.fstab"
+ end
+ fstab = fakefile(File::join("data/types/mount", name))
+ Puppet::Type.type(:mount).path = fstab
end
end
diff --git a/test/types/package.rb b/test/types/package.rb
index 9ffd846ef..779c693fe 100644
--- a/test/types/package.rb
+++ b/test/types/package.rb
@@ -167,7 +167,7 @@ class TestPackages < Test::Unit::TestCase
obj[:source] = file
assert_raise(Puppet::PackageError,
"Successfully installed nonexistent package") {
- state.sync(state.should)
+ state.sync
}
end
diff --git a/test/types/port.rb b/test/types/port.rb
index f02825431..debd7ed89 100755
--- a/test/types/port.rb
+++ b/test/types/port.rb
@@ -8,30 +8,29 @@ end
require 'puppettest'
require 'puppet'
+require 'puppet/type/parsedtype/port'
require 'test/unit'
require 'facter'
class TestPort < Test::Unit::TestCase
include TestPuppet
-
def setup
super
@porttype = Puppet.type(:port)
+ @oldfiletype = @porttype.filetype
+ end
- @provider = @porttype.defaultprovider
-
- # Make sure they aren't using something funky like netinfo
- unless @provider.name == :parsed
- @porttype.defaultprovider = @porttype.provider(:parsed)
- end
-
- cleanup do @porttype.defaultprovider = nil end
+ def teardown
+ @porttype.filetype = @oldfiletype
+ Puppet.type(:file).clear
+ super
+ end
- oldpath = @provider.path
- cleanup do
- @provider.path = oldpath
- end
- @provider.path = tempfile()
+ # Here we just create a fake host type that answers to all of the methods
+ # but does not modify our actual system.
+ def mkfaketype
+ pfile = tempfile()
+ @porttype.path = pfile
end
def mkport
@@ -56,29 +55,51 @@ class TestPort < Test::Unit::TestCase
end
def test_simpleport
+ mkfaketype
host = nil
assert_nothing_raised {
- Puppet.type(:port).defaultprovider.retrieve
-
- count = 0
- @porttype.each do |h|
- count += 1
- end
-
- assert_equal(0, count, "Found hosts in empty file somehow")
+ assert_nil(Puppet.type(:port).retrieve)
}
port = mkport
- assert_apply(port)
assert_nothing_raised {
- port.retrieve
+ Puppet.type(:port).store
+ }
+
+ assert_nothing_raised {
+ assert(
+ Puppet.type(:port).to_file.include?(
+ Puppet.type(:port).fileobj.read
+ ),
+ "File does not include all of our objects"
+ )
}
+ end
- assert(port.exists?, "Port did not get created")
+ def test_portsparse
+ fakedata("data/types/ports").each { |file|
+ @porttype.path = file
+ Puppet.info "Parsing %s" % file
+ assert_nothing_raised {
+ @porttype.retrieve
+ }
+
+ # Now just make we've got some ports we know will be there
+ dns = @porttype["domain"]
+ assert(dns, "Could not retrieve DNS port")
+
+ assert_equal("53", dns.is(:number), "DNS number was wrong")
+ %w{udp tcp}.each { |v|
+ assert(dns.is(:protocols).include?(v), "DNS did not include proto %s" % v)
+ }
+
+ @porttype.clear
+ }
end
def test_moddingport
+ mkfaketype
port = nil
port = mkport
@@ -102,24 +123,59 @@ class TestPort < Test::Unit::TestCase
end
def test_removal
+ mkfaketype
port = mkport()
assert_nothing_raised {
port[:ensure] = :present
}
assert_events([:port_created], port)
- assert_events([], port)
- assert(port.exists?, "port was not created")
+ port.retrieve
+ assert(port.insync?)
assert_nothing_raised {
port[:ensure] = :absent
}
- assert_events([:port_deleted], port)
- assert(! port.exists?, "port was not removed")
+ assert_events([:port_removed], port)
+ 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)
@@ -133,7 +189,7 @@ class TestPort < Test::Unit::TestCase
assert_equal(:present, port.is(:ensure))
- assert_equal(:absent, port.retrieve[:alias])
+ assert(port.state(:alias).is == :absent)
port[:alias] = "yaytest"
assert_events([:port_changed], port)
diff --git a/test/types/sshkey.rb b/test/types/sshkey.rb
index cf8313654..ff9adc336 100755
--- a/test/types/sshkey.rb
+++ b/test/types/sshkey.rb
@@ -17,22 +17,21 @@ class TestSSHKey < Test::Unit::TestCase
def setup
super
# god i'm lazy
- @sshkeytype = Puppet.type(:sshkey)
-
- @provider = @sshkeytype.defaultprovider
-
- # Make sure they aren't using something funky like netinfo
- unless @provider.name == :parsed
- @sshkeytype.defaultprovider = @sshkeytype.provider(:parsed)
- end
+ @sshtype = Puppet.type(:sshkey)
+ @oldfiletype = @sshtype.filetype
+ end
- cleanup do @sshkeytype.defaultprovider = nil end
+ def teardown
+ Puppet::FileType.filetype(:ram).clear
+ @sshtype.filetype = @oldfiletype
+ Puppet.type(:file).clear
+ super
+ end
- oldpath = @provider.path
- cleanup do
- @provider.path = oldpath
- end
- @provider.path = tempfile()
+ # Here we just create a fake key type that answers to all of the methods
+ # but does not modify our actual system.
+ def mkfaketype
+ @sshtype.filetype = Puppet::FileType.filetype(:ram)
end
def mkkey
@@ -45,7 +44,7 @@ class TestSSHKey < Test::Unit::TestCase
end
assert_nothing_raised {
- key = @sshkeytype.create(
+ key = @sshtype.create(
: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",
@@ -57,25 +56,41 @@ class TestSSHKey < Test::Unit::TestCase
end
def test_simplekey
+ mkfaketype
assert_nothing_raised {
- Puppet.type(:sshkey).defaultprovider.retrieve
-
- count = 0
- @sshkeytype.each do |h|
- count += 1
- end
-
- assert_equal(0, count, "Found sshkeys in empty file somehow")
+ assert_nil(Puppet.type(:sshkey).retrieve)
}
key = mkkey
assert_apply(key)
- assert(key.exists?, "Key did not get created")
+ assert_nothing_raised {
+ Puppet.type(:sshkey).store
+ }
+
+ assert_nothing_raised {
+ assert(
+ Puppet.type(:sshkey).to_file.include?(
+ Puppet.type(:sshkey).fileobj.read
+ ),
+ "File does not include all of our objects"
+ )
+ }
+ end
+
+ def test_keysparse
+ fakedata("data/types/sshkey").each { |file|
+ @sshtype.path = file
+ assert_nothing_raised {
+ @sshtype.retrieve
+ }
+ @sshtype.clear
+ }
end
def test_moddingkey
+ mkfaketype
key = mkkey()
assert_events([:sshkey_created], key)
@@ -84,11 +99,12 @@ class TestSSHKey < Test::Unit::TestCase
key[:alias] = %w{madstop kirby yayness}
+ Puppet.err :mark
assert_events([:sshkey_changed], key)
end
def test_aliasisstate
- assert_equal(:state, @sshkeytype.attrtype(:alias))
+ assert_equal(:state, @sshtype.attrtype(:alias))
end
def test_multivalues
@@ -110,23 +126,28 @@ class TestSSHKey < Test::Unit::TestCase
end
def test_removal
+ mkfaketype
sshkey = mkkey()
assert_nothing_raised {
sshkey[:ensure] = :present
}
assert_events([:sshkey_created], sshkey)
- assert(sshkey.exists?, "key was not created")
+ sshkey.retrieve
+ assert(sshkey.insync?)
assert_nothing_raised {
sshkey[:ensure] = :absent
}
- assert_events([:sshkey_deleted], sshkey)
- assert(! sshkey.exists?, "Key was not deleted")
+ assert_events([:sshkey_removed], sshkey)
+ sshkey.retrieve
assert_events([], sshkey)
end
def test_modifyingfile
+ keyfile = tempfile()
+ Puppet.type(:sshkey).path = keyfile
+
keys = []
names = []
3.times {
@@ -143,7 +164,7 @@ class TestSSHKey < Test::Unit::TestCase
#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
@@ -151,9 +172,9 @@ class TestSSHKey < Test::Unit::TestCase
# And verify that we have data for everything
names.each { |name|
- key = Puppet.type(:sshkey)[name] || Puppet.type(:sshkey).create(:name => name)
+ key = Puppet.type(:sshkey)[name]
assert(key)
- assert(key.exists?, "key %s is missing" % name)
+ assert(key[:type])
}
end
end
diff --git a/test/types/user.rb b/test/types/user.rb
index 7522a041b..008f39272 100755
--- a/test/types/user.rb
+++ b/test/types/user.rb
@@ -19,7 +19,7 @@ class TestUser < Test::Unit::TestCase
@ensure = :present
@model.eachstate do |state|
next if state.name == :ensure
- state.commit
+ state.sync
end
end