diff options
author | Luke Kanies <luke@puppetlabs.com> | 2010-04-28 21:52:06 -0700 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | d61a69a0e5a87a95846a4d39115eac80e4984cac (patch) | |
tree | 4d611b0b6280e8ccbb3702dcfe619f22d5e3ecd2 /test | |
parent | f66095d35bc5f9645eb19bbb8cefa342c0181d2d (diff) | |
download | puppet-d61a69a0e5a87a95846a4d39115eac80e4984cac.tar.gz puppet-d61a69a0e5a87a95846a4d39115eac80e4984cac.tar.xz puppet-d61a69a0e5a87a95846a4d39115eac80e4984cac.zip |
Fixing #3668 - fixed autoloading classes from modules
This involved essentially moving all of the importing and loading
code out of the Parser and into a new 'TypeLoader' class.
The parser and the ResourceTypeCollection classes now delegate
to that class for all file handling. Most of the code paths are
also now much cleaner, and a bit of redundancy was removed.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'test')
-rwxr-xr-x | test/language/parser.rb | 197 |
1 files changed, 0 insertions, 197 deletions
diff --git a/test/language/parser.rb b/test/language/parser.rb index db6177da6..18688aa40 100755 --- a/test/language/parser.rb +++ b/test/language/parser.rb @@ -655,65 +655,6 @@ file { "/tmp/yayness": } end - def test_module_import - basedir = File.join(tmpdir(), "module-import") - @@tmpfiles << basedir - Dir.mkdir(basedir) - modfiles = [ "init.pp", "mani1.pp", "mani2.pp", - "sub/smani1.pp", "sub/smani2.pp" ] - - modpath = File.join(basedir, "modules") - Puppet[:modulepath] = modpath - - modname = "amod" - manipath = File::join(modpath, modname, Puppet::Module::MANIFESTS) - FileUtils::mkdir_p(File::join(manipath, "sub")) - targets = [] - modfiles.each do |fname| - target = File::join(basedir, File::basename(fname, '.pp')) - targets << target - txt = %[ file { '#{target}': content => "#{fname}" } ] - if fname == "init.pp" - txt = %[import 'mani1' \nimport '#{modname}/mani2'\nimport '#{modname}/sub/*.pp'\n ] + txt - end - File::open(File::join(manipath, fname), "w") do |f| - f.puts txt - end - end - - manifest_texts = [ "import '#{modname}'", - "import '#{modname}/init'", - "import '#{modname}/init.pp'" ] - - manifest = File.join(modpath, "manifest.pp") - manifest_texts.each do |txt| - File.open(manifest, "w") { |f| f.puts txt } - - assert_nothing_raised { - parser = mkparser - parser.file = manifest - parser.parse - } - assert_creates(manifest, *targets) - end - end - - # #544 - def test_ignoreimports - parser = mkparser - - assert(! Puppet[:ignoreimport], ":ignoreimport defaulted to true") - assert_raise(Puppet::ParseError, "Did not fail on missing import") do - parser.parse("import 'nosuchfile'") - end - assert_nothing_raised("could not set :ignoreimport") do - Puppet[:ignoreimport] = true - end - assert_nothing_raised("Parser did not follow :ignoreimports") do - parser.parse("import 'nosuchfile'") - end - end - def test_multiple_imports_on_one_line one = tempfile two = tempfile @@ -744,22 +685,6 @@ file { "/tmp/yayness": end end - # #588 - def test_globbing_with_directories - dir = tempfile - Dir.mkdir(dir) - subdir = File.join(dir, "subdir") - Dir.mkdir(subdir) - file = File.join(dir, "file.pp") - maker = tempfile - File.open(file, "w") { |f| f.puts "file { '#{maker}': ensure => file }" } - - parser = mkparser - assert_nothing_raised("Globbing failed when it matched a directory") do - parser.import("%s/*" % dir) - end - end - # #629 - undef keyword def test_undef parser = mkparser @@ -805,128 +730,6 @@ file { "/tmp/yayness": end end - # Setup a module. - def mk_module(name, files = {}) - mdir = File.join(@dir, name) - mandir = File.join(mdir, "manifests") - FileUtils.mkdir_p mandir - - if defs = files[:define] - files.delete(:define) - end - Dir.chdir(mandir) do - files.each do |file, classes| - File.open("%s.pp" % file, "w") do |f| - classes.each { |klass| - if defs - f.puts "define %s {}" % klass - else - f.puts "class %s {}" % klass - end - } - end - end - end - end - - # #596 - make sure classes and definitions load automatically if they're in modules, so we don't have to manually load each one. - def test_module_autoloading - @dir = tempfile - Puppet[:modulepath] = @dir - - FileUtils.mkdir_p @dir - - parser = mkparser - - # Make sure we fail like normal for actually missing classes - assert_nil(parser.find_hostclass("", "nosuchclass"), "Did not return nil on missing classes") - - # test the simple case -- the module class itself - name = "simple" - mk_module(name, :init => [name]) - - # Try to load the module automatically now - klass = parser.find_hostclass("", name) - assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload class from module init file") - assert_equal(name, klass.name, "Incorrect class was returned") - - # Try loading the simple module when we're in something other than the base namespace. - parser = mkparser - klass = parser.find_hostclass("something::else", name) - assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload class from module init file") - assert_equal(name, klass.name, "Incorrect class was returned") - - # Now try it with a definition as the base file - name = "simpdef" - mk_module(name, :define => true, :init => [name]) - - klass = parser.find_definition("", name) - assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload class from module init file") - assert_equal(name, klass.name, "Incorrect class was returned") - - # Now try it with namespace classes where both classes are in the init file - parser = mkparser - modname = "both" - name = "sub" - mk_module(modname, :init => %w{both both::sub}) - - # First try it with a namespace - klass = parser.find_hostclass("both", name) - assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from module init file with a namespace") - assert_equal("both::sub", klass.name, "Incorrect class was returned") - - # Now try it using the fully qualified name - parser = mkparser - klass = parser.find_hostclass("", "both::sub") - assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from module init file with no namespace") - assert_equal("both::sub", klass.name, "Incorrect class was returned") - - - # Now try it with the class in a different file - parser = mkparser - modname = "separate" - name = "sub" - mk_module(modname, :init => %w{separate}, :sub => %w{separate::sub}) - - # First try it with a namespace - klass = parser.find_hostclass("separate", name) - assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from separate file with a namespace") - assert_equal("separate::sub", klass.name, "Incorrect class was returned") - - # Now try it using the fully qualified name - parser = mkparser - klass = parser.find_hostclass("", "separate::sub") - assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from separate file with no namespace") - assert_equal("separate::sub", klass.name, "Incorrect class was returned") - - # Now make sure we don't get a failure when there's no module file - parser = mkparser - modname = "alone" - name = "sub" - mk_module(modname, :sub => %w{alone::sub}) - - # First try it with a namespace - assert_nothing_raised("Could not autoload file when module file is missing") do - klass = parser.find_hostclass("alone", name) - end - assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from alone file with a namespace") - assert_equal("alone::sub", klass.name, "Incorrect class was returned") - - # Now try it using the fully qualified name - parser = mkparser - klass = parser.find_hostclass("", "alone::sub") - assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from alone file with no namespace") - assert_equal("alone::sub", klass.name, "Incorrect class was returned") - - # and with the definition in its own file - name = "mymod" - mk_module(name, :define => true, :mydefine => ["mymod::mydefine"]) - - klass = parser.find_definition("", "mymod::mydefine") - assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload definition from its own file") - assert_equal("mymod::mydefine", klass.name, "Incorrect definition was returned") - end - # Make sure class, node, and define methods are case-insensitive def test_structure_case_insensitivity parser = mkparser |