~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to test/language/scope.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
                     "botscope values shadow parent scope values")
84
84
    end
85
85
 
86
 
    def test_lookupvar
87
 
        parser = mkparser
88
 
        scope = mkscope :parser => parser
89
 
 
90
 
        # first do the plain lookups
91
 
        assert_equal("", scope.lookupvar("var"), "scope did not default to string")
92
 
        assert_equal("", scope.lookupvar("var", true), "scope ignored usestring setting")
93
 
        assert_equal(:undefined, scope.lookupvar("var", false), "scope ignored usestring setting when false")
94
 
 
95
 
        # Now set the var
96
 
        scope.setvar("var", "yep")
97
 
        assert_equal("yep", scope.lookupvar("var"), "did not retrieve value correctly")
98
 
 
99
 
        # Now test the parent lookups 
100
 
        subscope = mkscope :parser => parser
101
 
        subscope.parent = scope
102
 
        assert_equal("", subscope.lookupvar("nope"), "scope did not default to string with parent")
103
 
        assert_equal("", subscope.lookupvar("nope", true), "scope ignored usestring setting with parent")
104
 
        assert_equal(:undefined, subscope.lookupvar("nope", false), "scope ignored usestring setting when false with parent")
105
 
 
106
 
        assert_equal("yep", subscope.lookupvar("var"), "did not retrieve value correctly from parent")
107
 
 
108
 
        # Now override the value in the subscope
109
 
        subscope.setvar("var", "sub")
110
 
        assert_equal("sub", subscope.lookupvar("var"), "did not retrieve overridden value correctly")
111
 
 
112
 
        # Make sure we punt when the var is qualified.  Specify the usestring value, so we know it propagates.
113
 
        scope.expects(:lookup_qualified_var).with("one::two", false).returns(:punted)
114
 
        assert_equal(:punted, scope.lookupvar("one::two", false), "did not return the value of lookup_qualified_var")
115
 
    end
116
 
 
117
 
    def test_lookup_qualified_var
118
 
        parser = mkparser
119
 
        scope = mkscope :parser => parser
120
 
 
121
 
        scopes = {}
122
 
        classes = ["", "one", "one::two", "one::two::three"].each do |name|
123
 
            klass = parser.newclass(name)
124
 
            Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => scope, :source => mock('source')).evaluate
125
 
            scopes[name] = scope.compiler.class_scope(klass)
126
 
        end
127
 
 
128
 
        classes.each do |name|
129
 
            var = [name, "var"].join("::")
130
 
            scopes[name].expects(:lookupvar).with("var", false).returns(name)
131
 
 
132
 
            assert_equal(name, scope.send(:lookup_qualified_var, var, false), "did not get correct value from lookupvar")
133
 
        end
134
 
    end
135
 
 
136
86
    def test_declarative
137
87
        # set to declarative
138
88
        top = mkscope
216
166
        assert_equal(top, sub.parent, "Did not find parent scope correctly")
217
167
        assert_equal(top, sub.parent, "Did not find parent scope on second call")
218
168
    end
219
 
    
 
169
 
220
170
    def test_strinterp
221
171
        # Make and evaluate our classes so the qualified lookups work
222
172
        parser = mkparser
288
238
    end
289
239
 
290
240
    def test_tagfunction
 
241
        Puppet::Parser::Functions.function(:tag)
291
242
        scope = mkscope
292
243
        resource = mock 'resource'
293
244
        scope.resource = resource
324
275
    end
325
276
 
326
277
    def test_definedfunction
 
278
        Puppet::Parser::Functions.function(:defined)
327
279
        parser = mkparser
328
280
        %w{one two}.each do |name|
329
281
            parser.newdefine name
402
354
        end
403
355
    end
404
356
 
405
 
    if defined? ActiveRecord
 
357
    if defined? ::ActiveRecord
406
358
    # Verify that we can both store and collect an object in the same
407
359
    # run, whether it's in the same scope as a collection or a different
408
360
    # scope.
409
361
    def test_storeandcollect
 
362
        catalog_cache_class = Puppet::Resource::Catalog.indirection.cache_class
 
363
        facts_cache_class = Puppet::Node::Facts.indirection.cache_class
 
364
        node_cache_class = Puppet::Node.indirection.cache_class
410
365
        Puppet[:storeconfigs] = true
411
366
        Puppet::Rails.init
412
367
        sleep 1
440
395
                assert(flat.find{|o| o.name == name }, "Did not find #{name}")
441
396
            end
442
397
        }
 
398
        Puppet[:storeconfigs] = false
 
399
        Puppet::Resource::Catalog.cache_class =  catalog_cache_class
 
400
        Puppet::Node::Facts.cache_class = facts_cache_class
 
401
        Puppet::Node.cache_class = node_cache_class
443
402
    end
444
403
    else
445
404
        $stderr.puts "No ActiveRecord -- skipping collection tests"
458
417
            "Did not add extra namespace correctly")
459
418
    end
460
419
 
461
 
    def test_findclass_and_finddefine
 
420
    def test_find_hostclass_and_find_definition
462
421
        parser = mkparser
463
422
 
464
 
        # Make sure our scope calls the parser findclass method with
 
423
        # Make sure our scope calls the parser find_hostclass method with
465
424
        # the right namespaces
466
425
        scope = mkscope :parser => parser
467
426
 
468
427
        parser.metaclass.send(:attr_accessor, :last)
469
428
 
470
 
        methods = [:findclass, :finddefine]
 
429
        methods = [:find_hostclass, :find_definition]
471
430
        methods.each do |m|
472
431
            parser.meta_def(m) do |namespace, name|
473
432
                @checked ||= []