blob: f3c564d9df59dce81c408a2ca7db14888b892ec8 (
plain)
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
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../lib/puppettest'
require 'puppettest'
require 'puppettest/support/utils'
require 'puppettest/support/assertions'
require 'puppet/network/client/resource'
class TestResourceClient < Test::Unit::TestCase
include PuppetTest::ServerTest
include PuppetTest::Support::Utils
def mkresourceserver
Puppet::Network::Handler.resource.new
end
def mkclient
client = Puppet::Network::Client.resource.new(:Resource => mkresourceserver)
end
def test_resources
file = tempfile()
text = "yayness\n"
File.open(file, "w") { |f| f.print text }
mkresourceserver()
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
|