summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-11 20:44:38 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-11 20:44:38 +0000
commite287d1e1f1f4ff912ad8c049f8abe44d085011fa (patch)
tree65f7cc668024b3da308732e4bec95dfb71695372 /test
parent37a059be9538bc90e09a17a45573fc44da6861b4 (diff)
Almost all tests now pass. I have basically reached the point where I was before I integrated graphing, except that all of the relationship handling is now inside the transaction, and any kind of recursion (including file) is *tons* easier to model and manage.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1905 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-xtest/client/master.rb103
-rwxr-xr-xtest/language/interpreter.rb2
-rwxr-xr-xtest/other/dsl.rb1
-rw-r--r--test/other/pgraph.rb12
-rwxr-xr-xtest/server/pelement.rb11
5 files changed, 116 insertions, 13 deletions
diff --git a/test/client/master.rb b/test/client/master.rb
index f89d2cae8..9318fdcd6 100755
--- a/test/client/master.rb
+++ b/test/client/master.rb
@@ -9,6 +9,30 @@ require 'puppettest'
class TestMasterClient < Test::Unit::TestCase
include PuppetTest::ServerTest
+
+ class FakeTrans
+ def initialize
+ @counters = Hash.new { |h,k| h[k] = 0 }
+ end
+ [:evaluate, :report, :cleanup, :addtimes, :tags, :ignoreschedules].each do |m|
+ define_method(m.to_s + "=") do |*args|
+ @counters[m] += 1
+ end
+ define_method(m) do |*args|
+ @counters[m] += 1
+ end
+ define_method(m.to_s + "?") do
+ @counters[m]
+ end
+ end
+ end
+ class FakeComponent
+ attr_accessor :trans
+ def evaluate
+ @trans = FakeTrans.new
+ @trans
+ end
+ end
def mkmaster(file = nil)
master = nil
@@ -37,6 +61,73 @@ class TestMasterClient < Test::Unit::TestCase
return client
end
+
+ def mk_fake_client
+ server = Puppet::Server::Master.new :Code => ""
+ master = Puppet::Client::MasterClient.new :Server => server, :Local => true
+
+ # Now create some objects
+ objects = FakeComponent.new
+
+ master.send(:instance_variable_set, "@objects", objects)
+
+ class << master
+ def report(r)
+ @reported ||= 0
+ @reported += 1
+ end
+ def reported
+ @reported ||= 0
+ @reported
+ end
+ end
+ return master, objects
+ end
+
+ def test_apply
+ master, objects = mk_fake_client
+
+ check = Proc.new do |hash|
+ assert(objects.trans, "transaction was not created")
+ trans = objects.trans
+ hash[:yes].each do |m|
+ assert_equal(1, trans.send(m.to_s + "?"), "did not call #{m} enough times")
+ end
+ hash[:no].each do |m|
+ assert_equal(0, trans.send(m.to_s + "?"), "called #{m} too many times")
+ end
+ end
+
+ # First try it with no arguments
+ assert_nothing_raised do
+ master.apply
+ end
+ check.call :yes => %w{evaluate cleanup addtimes}, :no => %w{report tags ignoreschedules}
+ assert_equal(0, master.reported, "master sent report with reports disabled")
+
+
+ # Now enable reporting and make sure the report method gets called
+ Puppet[:report] = true
+ assert_nothing_raised do
+ master.apply
+ end
+ check.call :yes => %w{evaluate cleanup addtimes}, :no => %w{tags ignoreschedules}
+ assert_equal(1, master.reported, "master did not send report")
+
+ # Now try it with tags enabled
+ assert_nothing_raised do
+ master.apply("tags")
+ end
+ check.call :yes => %w{evaluate cleanup tags addtimes}, :no => %w{ignoreschedules}
+ assert_equal(2, master.reported, "master did not send report")
+
+ # and ignoreschedules
+ assert_nothing_raised do
+ master.apply("tags", true)
+ end
+ check.call :yes => %w{evaluate cleanup tags ignoreschedules addtimes}, :no => %w{}
+ assert_equal(3, master.reported, "master did not send report")
+ end
def test_disable
manifest = mktestmanifest
@@ -129,20 +220,24 @@ class TestMasterClient < Test::Unit::TestCase
}
end
+ # This method is supposed
def test_download
source = tempfile()
dest = tempfile()
sfile = File.join(source, "file")
+ dfile = File.join(dest, "file")
Dir.mkdir(source)
File.open(sfile, "w") {|f| f.puts "yay"}
files = []
assert_nothing_raised do
-
- Puppet::Client::Master.download(:dest => dest, :source => source, :name => "testing") do |path|
- files << path
- end
+ files = Puppet::Client::MasterClient.download(:dest => dest, :source => source, :name => "testing")
end
+
+ assert(FileTest.directory?(dest), "dest dir was not created")
+ assert(FileTest.file?(dfile), "dest file was not created")
+ assert_equal(File.read(sfile), File.read(dfile), "Dest file had incorrect contents")
+ assert_equal([dest, dfile].sort, files.sort, "Changed files were not returned correctly")
end
def test_getplugins
diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb
index 28c6d41a1..2fe9cc601 100755
--- a/test/language/interpreter.rb
+++ b/test/language/interpreter.rb
@@ -564,7 +564,7 @@ class TestInterpreter < Test::Unit::TestCase
assert(other, "Could not find class")
assert(interp.findclass("", "other::myclass"), "Could not find class")
assert_equal("other::myclass", other.fqname)
- assert_equal("other", other.namespace)
+ assert_equal("other::myclass", other.namespace)
assert_equal("myclass", other.type)
assert_equal(%w{something diff},
interp.findclass("other", "myclass").code.evaluate(:scope => scope))
diff --git a/test/other/dsl.rb b/test/other/dsl.rb
index bb7fc86cf..50eac4781 100755
--- a/test/other/dsl.rb
+++ b/test/other/dsl.rb
@@ -193,6 +193,7 @@ class TestDSL < Test::Unit::TestCase
end
def test_typemethods
+ Puppet::Type.loadall
filetype = Puppet::Type.type(:file)
path = tempfile()
diff --git a/test/other/pgraph.rb b/test/other/pgraph.rb
index 3dc232670..88f753131 100644
--- a/test/other/pgraph.rb
+++ b/test/other/pgraph.rb
@@ -14,6 +14,18 @@ class TestPGraph < Test::Unit::TestCase
Edge = Puppet::Relationship
+ def test_clear
+ graph = Puppet::PGraph.new
+ graph.add_edge!("a", "b")
+ graph.add_vertex! "c"
+ assert_nothing_raised do
+ graph.clear
+ end
+ assert(graph.vertices.empty?, "Still have vertices after clear")
+ assert(graph.edges.empty?, "still have edges after clear")
+ end
+
+
def test_matching_edges
graph = Puppet::PGraph.new
diff --git a/test/server/pelement.rb b/test/server/pelement.rb
index 24836e66c..c86dadc11 100755
--- a/test/server/pelement.rb
+++ b/test/server/pelement.rb
@@ -254,23 +254,16 @@ class TestPElementServer < Test::Unit::TestCase
Puppet::Type.type(:file).clear
- Puppet.err filetrans[:parent].inspect
-
- #p filetrans
-
bucket = Puppet::TransBucket.new
bucket.type = "file"
bucket.push filetrans
- #p bucket
-
oldbucket = bucket.dup
File.unlink(file)
assert_nothing_raised {
server.apply(bucket)
}
-
assert(FileTest.exists?(file), "File did not get recreated")
# Now try it as a "nonlocal" server
@@ -287,11 +280,13 @@ class TestPElementServer < Test::Unit::TestCase
Puppet.warning "YAML is broken on this machine"
return
end
- #puts Base64.decode64(yaml)
+ # puts Base64.decode64(yaml)
+ objects = nil
assert_nothing_raised("Could not reload yaml") {
YAML::load(Base64.decode64(yaml))
}
+ # The server is supposed to accept yaml and execute it.
assert_nothing_raised {
server.apply(yaml)
}