summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-15 03:22:50 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-15 03:22:50 +0000
commit6bb4814ec66f2cb09381a1bc0fa30f9c85d47443 (patch)
treeeae4168b4117caee7bc451a69274995a4440b792 /test
parente5aa761d3b45a722d9644776755572447161bba3 (diff)
downloadpuppet-6bb4814ec66f2cb09381a1bc0fa30f9c85d47443.tar.gz
puppet-6bb4814ec66f2cb09381a1bc0fa30f9c85d47443.tar.xz
puppet-6bb4814ec66f2cb09381a1bc0fa30f9c85d47443.zip
Fixing #267. The problem was that the user provider was retrieving the @is value instead of the @should value, because it was using [] instead of the should method. I fixed the FakeModel to behave a bit more like real types, so that it keeps track of the is/should values, and also to keep track of which attributes are valid, since I immediately ran into another problem stemming from the use of the fakemodel.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1599 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rw-r--r--test/providers/user.rb2
-rw-r--r--test/puppettest.rb39
2 files changed, 39 insertions, 2 deletions
diff --git a/test/providers/user.rb b/test/providers/user.rb
index 15b453780..e400ff3ad 100644
--- a/test/providers/user.rb
+++ b/test/providers/user.rb
@@ -108,7 +108,6 @@ class TestUserProvider < Test::Unit::TestCase
def eachstate
Puppet::Type.type(:user).validstates.each do |state|
- next if state == :ensure
yield state
end
end
@@ -128,6 +127,7 @@ class TestUserProvider < Test::Unit::TestCase
def fakedata(name, param)
case param
when :name: name
+ when :ensure: :present
when :comment: "Puppet Testing User %s" % name
when :gid: Process.gid()
when :shell: findshell()
diff --git a/test/puppettest.rb b/test/puppettest.rb
index f67b2dc96..a2c3d186c 100644
--- a/test/puppettest.rb
+++ b/test/puppettest.rb
@@ -10,7 +10,7 @@ module TestPuppet
include ObjectSpace
# A baseclass for the faketypes.
- class FakeModel < Hash
+ class FakeModel
class << self
attr_accessor :name
@name = :fakemodel
@@ -24,7 +24,36 @@ module TestPuppet
Puppet::Type.type(@name).validstate?(name)
end
+ def self.to_s
+ "Fake%s" % @name.to_s.capitalize
+ end
+
+ def [](param)
+ if @realmodel.attrtype(param) == :state
+ @is[param]
+ else
+ @params[param]
+ end
+ end
+
+ def []=(param, value)
+ unless @realmodel.attrtype(param)
+ raise Puppet::DevError, "Invalid attribute %s for %s" %
+ [param, @realmodel.name]
+ end
+ if @realmodel.attrtype(param) == :state
+ @should[param] = value
+ else
+ @params[param] = value
+ end
+ end
+
def initialize(name)
+ @realmodel = Puppet::Type.type(self.class.name)
+ raise "Could not find type #{self.class.name}" unless @realmodel
+ @is = {}
+ @should = {}
+ @params = {}
self[:name] = name
end
@@ -32,6 +61,14 @@ module TestPuppet
"%s(%s)" % [self.class.to_s.sub(/.+::/, ''), super()]
end
+ def is(param)
+ @is[param]
+ end
+
+ def should(param)
+ @should[param]
+ end
+
def name
self[:name]
end