summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/facter.rb20
-rw-r--r--tests/tc_simple.rb43
2 files changed, 60 insertions, 3 deletions
diff --git a/lib/facter.rb b/lib/facter.rb
index ce99ba7..985b0d2 100644
--- a/lib/facter.rb
+++ b/lib/facter.rb
@@ -415,8 +415,15 @@ class Facter
end
# Add a new tag to the resolution mechanism.
- def tag(fact,*values)
- @tags.push Tag.new(fact,*values)
+ def tag(*args)
+ if args[0].is_a? Hash
+ args[0].each do |fact, values|
+ @tags.push Tag.new(fact,*values)
+ end
+ else
+ fact = args.shift
+ @tags.push Tag.new(fact,*args)
+ end
end
def to_s
@@ -457,8 +464,15 @@ class Facter
# Add the tag. Requires the fact name, an operator, and the value
# we're comparing to.
def initialize(fact, *values)
+ fact = fact.to_s if fact.is_a? Symbol
@fact = fact
- @values = values
+ @values = values.collect do |value|
+ if value.is_a? String
+ value
+ else
+ value.to_s
+ end
+ end
end
def to_s
diff --git a/tests/tc_simple.rb b/tests/tc_simple.rb
index 8efdbd7..66abf23 100644
--- a/tests/tc_simple.rb
+++ b/tests/tc_simple.rb
@@ -404,6 +404,49 @@ some random stuff
end
end
+ def test_tag_as_array_and_hash
+ assert_nothing_raised {
+ Facter.add("myfact") do
+ tag "kernel", Facter.kernel
+ setcode do "yep" end
+ end
+ }
+
+ assert_equal("yep", Facter.myfact, "Did not get tagged goal")
+
+ # now try it as a hash
+ assert_nothing_raised {
+ Facter.add("hashfact") do
+ tag "kernel" => Facter.kernel
+ setcode do "hashness" end
+ end
+ }
+
+ assert_equal("hashness", Facter.hashfact, "Did not get tagged goal")
+
+ # now with multiple values
+ assert_nothing_raised {
+ Facter.add("hashfact2") do
+ tag :kernel => ["nosuchkernel", Facter.kernel]
+ setcode do "multihash" end
+ end
+ }
+
+ assert_equal("multihash", Facter.hashfact2, "Did not get multivalue tag")
+
+ end
+
+ def test_strings_or_symbols
+ assert_nothing_raised {
+ Facter.add("symbol1") do
+ tag :kernel => Facter.kernel
+ setcode do "yep1" end
+ end
+ }
+
+ assert_equal("yep1", Facter.symbol1, "Did not get symbol fact")
+ end
+
if Facter.kernel == "Linux"
def test_memoryonlinux
assert_nothing_raised {