summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-17 19:47:32 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-17 19:47:32 +0000
commit86dae84dad4cd5688029c398109b15b6074cf3c4 (patch)
treea7aaa43746bc6b100618e8ecc1acb1a79acba6c9 /test
parent7e488b2dfb9e4c04a9be0c5f824947b55fd0226c (diff)
Fixing ports to now use a provider
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1800 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-xtest/providers/parsedport.rb57
-rwxr-xr-xtest/types/port.rb117
2 files changed, 87 insertions, 87 deletions
diff --git a/test/providers/parsedport.rb b/test/providers/parsedport.rb
new file mode 100755
index 000000000..ff3977dd5
--- /dev/null
+++ b/test/providers/parsedport.rb
@@ -0,0 +1,57 @@
+#!/usr/bin/env ruby
+
+$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppettest'
+require 'puppet'
+require 'puppet/type/port'
+require 'test/unit'
+require 'facter'
+
+class TestParsedPort < Test::Unit::TestCase
+ include PuppetTest
+
+ 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/types/port.rb b/test/types/port.rb
index 1537dc921..d80c242a8 100755
--- a/test/types/port.rb
+++ b/test/types/port.rb
@@ -2,32 +2,32 @@
$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
-# Test host job creation, modification, and destruction
-
require 'puppettest'
require 'puppet'
-require 'puppet/type/parsedtype/port'
+require 'test/unit'
require 'facter'
class TestPort < Test::Unit::TestCase
include PuppetTest
+
def setup
super
@porttype = Puppet.type(:port)
- @oldfiletype = @porttype.filetype
- end
- def teardown
- @porttype.filetype = @oldfiletype
- Puppet.type(:file).clear
- super
- end
+ @provider = @porttype.defaultprovider
- # 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
+ # 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
+
+ oldpath = @provider.path
+ cleanup do
+ @provider.path = oldpath
+ end
+ @provider.path = tempfile()
end
def mkport
@@ -52,51 +52,29 @@ class TestPort < Test::Unit::TestCase
end
def test_simpleport
- mkfaketype
host = nil
assert_nothing_raised {
- assert_nil(Puppet.type(:port).retrieve)
+ Puppet.type(:port).defaultprovider.retrieve
+
+ count = 0
+ @porttype.each do |h|
+ count += 1
+ end
+
+ assert_equal(0, count, "Found hosts in empty file somehow")
}
port = mkport
+ assert_apply(port)
assert_nothing_raised {
- Puppet.type(:port).store
+ port.retrieve
}
- assert_nothing_raised {
- assert(
- Puppet.type(:port).to_file.include?(
- Puppet.type(:port).fileobj.read
- ),
- "File does not include all of our objects"
- )
- }
- end
-
- 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
- }
+ assert(port.exists?, "Port did not get created")
end
def test_moddingport
- mkfaketype
port = nil
port = mkport
@@ -120,59 +98,24 @@ 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)
- port.retrieve
- assert(port.insync?)
+ assert(port.exists?, "port was not created")
assert_nothing_raised {
port[:ensure] = :absent
}
assert_events([:port_removed], port)
- port.retrieve
+ assert(! port.exists?, "port was not removed")
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)
@@ -186,7 +129,7 @@ class TestPort < Test::Unit::TestCase
assert_equal(:present, port.is(:ensure))
- assert(port.state(:alias).is == :absent)
+ assert_equal(:absent, port.is(:alias))
port[:alias] = "yaytest"
assert_events([:port_changed], port)