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
|
#!/usr/bin/env ruby
$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
require 'puppet'
require 'puppet/client/pelement'
require 'puppet/server'
require 'puppettest'
# $Id: pelement.rb 1793 2006-10-16 22:01:40Z luke $
class TestPElementClient < Test::Unit::TestCase
include PuppetTest::ServerTest
def mkpelementserver
handlers = {
:CA => {}, # so that certs autogenerate
:PElement => {},
}
return mkserver(handlers)
end
def mkclient
client = nil
assert_nothing_raised {
client = Puppet::Client::PElement.new(:Server => "localhost",
:Port => @@port)
}
return client
end
def test_pelements
file = tempfile()
text = "yayness\n"
File.open(file, "w") { |f| f.print text }
mkpelementserver()
client = mkclient()
# Test describing
tobj = nil
assert_nothing_raised {
tobj = client.describe("file", file)
}
assert(tobj, "Did not get response")
assert_instance_of(Puppet::TransObject, tobj)
obj = nil
assert_nothing_raised {
obj = tobj.to_type
}
assert_events([], obj)
File.unlink(file)
assert_events([:file_created], obj)
File.unlink(file)
# Now test applying
result = nil
assert_nothing_raised {
result = client.apply(tobj)
}
assert(FileTest.exists?(file), "File was not created on apply")
# Lastly, test "list"
list = nil
assert_nothing_raised {
list = client.list("user")
}
assert_instance_of(Puppet::TransBucket, list)
count = 0
list.each do |tobj|
break if count > 3
assert_instance_of(Puppet::TransObject, tobj)
tobj2 = nil
assert_nothing_raised {
tobj2 = client.describe(tobj.type, tobj.name)
}
obj = nil
assert_nothing_raised {
obj = tobj2.to_type
}
assert_events([], obj)
count += 1
end
end
end
|