summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorluke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a>2006-05-23 15:14:11 +0000
committerluke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a>2006-05-23 15:14:11 +0000
commit22bd24b2a2d29431320f67ebbb93d36fbae1c9ba (patch)
treef67d901857a16afb36c245b63095d3b953b5fb34 /tests
parentfe782b9596ee8b727f0b91e08318f27a99ab5250 (diff)
downloadfacter-22bd24b2a2d29431320f67ebbb93d36fbae1c9ba.tar.gz
facter-22bd24b2a2d29431320f67ebbb93d36fbae1c9ba.tar.xz
facter-22bd24b2a2d29431320f67ebbb93d36fbae1c9ba.zip
Added "architecture" fact, added the ability to autoload facts from separate files, and added the ability to retrieve fact values via a method for each fact.
git-svn-id: http://reductivelabs.com/svn/facter/trunk@101 1f5c1d6a-bddf-0310-8f58-fc49e503516a
Diffstat (limited to 'tests')
-rw-r--r--tests/tc_simple.rb68
1 files changed, 65 insertions, 3 deletions
diff --git a/tests/tc_simple.rb b/tests/tc_simple.rb
index efc7d21..8510fcf 100644
--- a/tests/tc_simple.rb
+++ b/tests/tc_simple.rb
@@ -15,6 +15,8 @@ end
class TestFacter < Test::Unit::TestCase
def setup
Facter.load
+
+ @tmpfiles = []
end
def teardown
@@ -22,9 +24,11 @@ class TestFacter < Test::Unit::TestCase
Facter.reset
Facter.flush
- #if ! @oldhandles.empty?
- # $stdin, $stdout, $stderr = @oldhandles
- #end
+ @tmpfiles.each do |file|
+ if FileTest.exists?(file)
+ system("rm -rf %s" % file)
+ end
+ end
end
def test_version
@@ -262,4 +266,62 @@ class TestFacter < Test::Unit::TestCase
assert(fact.ldapname, "Fact %s has no ldapname" % name)
}
end
+
+ def test_hash
+ hash = nil
+ assert_nothing_raised {
+ hash = Facter.to_hash
+ }
+
+ assert_instance_of(Hash, hash)
+
+ hash.each do |name, value|
+ assert_instance_of(String, name)
+ assert_instance_of(String, value)
+ end
+ end
+
+ # Verify we can call retrieve facts as methods
+ def test_factfunction
+ val = nil
+ assert_nothing_raised {
+ val = Facter.operatingsystem
+ }
+
+ assert_equal(Facter["operatingsystem"].value, val)
+
+ assert_raise(NoMethodError) { Facter.nosuchfact }
+ end
+
+ # Verify we can autoload facts.
+ def test_autoloading
+ dir = "/tmp/facterloading"
+ @tmpfiles << dir
+ Dir.mkdir(dir)
+ Dir.mkdir(File.join(dir, "facter"))
+ $: << dir
+
+ # Make sure we don't have a value right now.
+ assert_raise(NoMethodError) do
+ Facter.autoloadfact
+ end
+ assert_nil(Facter["autoloadfact"])
+
+ val = "autoloadedness"
+ File.open(File.join(dir, "facter", "autoloadfact.rb"), "w") do |file|
+ file.puts %{
+Facter.add("AutoloadFact") do
+ setcode { "#{val}" }
+end
+}
+ end
+
+ ret = nil
+ assert_nothing_raised do
+ ret = Facter.autoloadfact
+ end
+ assert_equal(val, ret, "Got incorrect value for autoloaded fact")
+ assert_equal(val, Facter["autoloadfact"].value,
+ "Got incorrect value for autoloaded fact")
+ end
end