1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#!/usr/bin/env ruby
$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
require 'puppet'
require 'puppettest'
require 'puppettest/parsertesting'
require 'puppettest/resourcetesting'
class TestTagging < Test::Unit::TestCase
include PuppetTest
include PuppetTest::ParserTesting
include PuppetTest::ResourceTesting
# Make sure the scopes are getting the right tags
def test_scopetags
scope = nil
assert_nothing_raised {
scope = mkscope
scope.name = "yayness"
scope.type = "solaris"
}
assert_nothing_raised {
assert_equal(%w{solaris}, scope.tags, "Incorrect scope tags")
}
end
# Test deeper tags, where a scope gets all of its parent scopes' tags
def test_deepscopetags
scope = nil
assert_nothing_raised {
scope = mkscope
scope.name = "yayness"
scope.type = "solaris"
scope = scope.newscope
scope.name = "booness"
scope.type = "apache"
}
assert_nothing_raised {
# Scopes put their own tags first
assert_equal(%w{apache solaris}, scope.tags, "Incorrect scope tags")
}
end
# Verify that the tags make their way to the objects
def test_objecttags
scope = nil
assert_nothing_raised {
scope = mkscope
scope.name = "yayness"
scope.type = "solaris"
}
resource = mkresource :type => "file", :title => "/tmp/testing",
:params => {:owner => "root"}, :file => "/yay", :line => 1,
:scope => scope
assert_nothing_raised {
scope.setresource(resource)
}
assert_nothing_raised {
assert_equal(%w{solaris file}, resource.tags,
"Incorrect tags")
}
end
# Make sure that specifying tags results in only those objects getting
# run.
def test_tagspecs
a = tempfile()
b = tempfile()
afile = Puppet.type(:file).create(
:path => a,
:ensure => :file
)
afile.tag("a")
bfile = Puppet.type(:file).create(
:path => b,
:ensure => :file
)
bfile.tag(:b)
# First, make sure they get created when no spec'ed tags
assert_events([:file_created,:file_created], afile, bfile)
assert(FileTest.exists?(a), "A did not get created")
assert(FileTest.exists?(b), "B did not get created")
File.unlink(a)
File.unlink(b)
# Set the tags to a
assert_nothing_raised {
Puppet[:tags] = "a"
}
assert_events([:file_created], afile, bfile)
assert(FileTest.exists?(a), "A did not get created")
assert(!FileTest.exists?(b), "B got created")
File.unlink(a)
# Set the tags to b
assert_nothing_raised {
Puppet[:tags] = "b"
}
assert_events([:file_created], afile, bfile)
assert(!FileTest.exists?(a), "A got created")
assert(FileTest.exists?(b), "B did not get created")
File.unlink(b)
# Set the tags to something else
assert_nothing_raised {
Puppet[:tags] = "c"
}
assert_events([], afile, bfile)
assert(!FileTest.exists?(a), "A got created")
assert(!FileTest.exists?(b), "B got created")
# Now set both tags
assert_nothing_raised {
Puppet[:tags] = "b, a"
}
assert_events([:file_created, :file_created], afile, bfile)
assert(FileTest.exists?(a), "A did not get created")
assert(FileTest.exists?(b), "B did not get created")
File.unlink(a)
end
def test_metaparamtag
path = tempfile()
start = %w{some tags}
tags = %w{a list of tags}
obj = nil
assert_nothing_raised do
obj = Puppet.type(:file).create(
:path => path,
:ensure => "file",
:tag => start
)
end
assert(obj, "Did not make object")
start.each do |tag|
assert(obj.tagged?(tag), "Object was not tagged with %s" % tag)
end
tags.each do |tag|
assert_nothing_raised {
obj[:tag] = tag
}
end
tags.each do |tag|
assert(obj.tagged?(tag), "Object was not tagged with %s" % tag)
end
end
end
# $Id: tagging.rb 1793 2006-10-16 22:01:40Z luke $
|