summaryrefslogtreecommitdiffstats
path: root/test/ral/manager
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-11-12 22:08:44 -0600
committerLuke Kanies <luke@madstop.com>2007-11-12 22:08:44 -0600
commit72510bfaa65e97f4eaaf246ef8f1c155716967b6 (patch)
tree978aa0e92812f5854978048162c6e2ab752dad72 /test/ral/manager
parentdd7caa76e160ed51c8b0e123c18f7526b575bfec (diff)
downloadpuppet-72510bfaa65e97f4eaaf246ef8f1c155716967b6.tar.gz
puppet-72510bfaa65e97f4eaaf246ef8f1c155716967b6.tar.xz
puppet-72510bfaa65e97f4eaaf246ef8f1c155716967b6.zip
Fixing #800 by refactoring how configurations are retrieved
from the server. The real problem was getting all of the validation done before any caching, which required a good bit more refactoring than I expected. In actuality, this commit is relatively small even though it covers many files; most of the changes just make the code clearer or shorter.
Diffstat (limited to 'test/ral/manager')
-rwxr-xr-xtest/ral/manager/instances.rb3
-rwxr-xr-xtest/ral/manager/type.rb63
2 files changed, 50 insertions, 16 deletions
diff --git a/test/ral/manager/instances.rb b/test/ral/manager/instances.rb
index 6ac4322f5..88f766038 100755
--- a/test/ral/manager/instances.rb
+++ b/test/ral/manager/instances.rb
@@ -93,7 +93,8 @@ class TestTypeInstances < Test::Unit::TestCase
# Make sure resources are entirely deleted.
def test_delete
aliases = %w{one}
- obj = @type.create(:name => "testing", :alias => "two")
+ config = mk_configuration
+ obj = @type.create(:name => "testing", :alias => "two", :configuration => config)
aliases << "two"
@type.alias("two", obj)
diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb
index 57248159b..350d3dd15 100755
--- a/test/ral/manager/type.rb
+++ b/test/ral/manager/type.rb
@@ -131,27 +131,60 @@ class TestType < Test::Unit::TestCase
}
end
- # Verify that aliasing works
- def test_aliasing
- file = tempfile()
+ def test_aliases_to_self_are_not_failures
+ resource = Puppet.type(:file).create(
+ :name => "/path/to/some/missing/file",
+ :ensure => "file"
+ )
+ resource.stubs(:path).returns("")
- baseobj = nil
- assert_nothing_raised {
- baseobj = Puppet.type(:file).create(
- :name => file,
- :ensure => "file",
- :alias => ["funtest"]
- )
- }
+ configuration = stub 'configuration'
+ configuration.expects(:resource).with(:file, "/path/to/some/missing/file").returns(resource)
+ resource.configuration = configuration
# Verify our adding ourselves as an alias isn't an error.
- assert_nothing_raised {
- baseobj[:alias] = file
+ assert_nothing_raised("Could not add alias") {
+ resource[:alias] = "/path/to/some/missing/file"
+ }
+
+ assert_equal(resource.object_id, Puppet.type(:file)["/path/to/some/missing/file"].object_id, "Could not retrieve alias to self")
+ end
+
+ def test_aliases_are_added_to_class_and_configuration
+ resource = Puppet.type(:file).create(
+ :name => "/path/to/some/missing/file",
+ :ensure => "file"
+ )
+ resource.stubs(:path).returns("")
+
+ configuration = stub 'configuration'
+ configuration.stubs(:resource).returns(nil)
+ configuration.expects(:alias).with(resource, "funtest")
+ resource.configuration = configuration
+
+ assert_nothing_raised("Could not add alias") {
+ resource[:alias] = "funtest"
}
- assert_instance_of(Puppet.type(:file), Puppet.type(:file)["funtest"],
- "Could not retrieve alias")
+ assert_equal(resource.object_id, Puppet.type(:file)["funtest"].object_id, "Could not retrieve alias")
+ end
+
+ def test_aliasing_fails_without_a_configuration
+ resource = Puppet.type(:file).create(
+ :name => "/no/such/file",
+ :ensure => "file"
+ )
+
+ assert_raise(Puppet::Error, "Did not fail to alias when no configuration was available") {
+ resource[:alias] = "funtest"
+ }
+ end
+ def test_configurations_are_set_during_initialization_if_present_on_the_transobject
+ trans = Puppet::TransObject.new("/path/to/some/file", :file)
+ trans.configuration = :my_config
+ resource = trans.to_type
+ assert_equal(resource.configuration, trans.configuration, "Did not set configuration on initialization")
end
# Verify that requirements don't depend on file order