diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2010-10-01 11:35:35 -0700 |
|---|---|---|
| committer | Jesse Wolfe <jes5199@gmail.com> | 2010-10-01 11:35:35 -0700 |
| commit | da84c03a7d1fe33c660c3e4c3a069ef1aed23bae (patch) | |
| tree | a75697d977d90b7754e0a14dcfc13b33aff893d1 /spec/integration | |
| parent | 0077379e528037d875a92575a994d01ca5233cc0 (diff) | |
| parent | 917c520f1abc0c72d7065531cffcef88259e32e0 (diff) | |
Merge commit '2.6.2rc1'
Diffstat (limited to 'spec/integration')
| -rw-r--r-- | spec/integration/application/doc_spec.rb | 55 | ||||
| -rwxr-xr-x | spec/integration/defaults_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/integration/parser/compiler_spec.rb | 21 | ||||
| -rw-r--r-- | spec/integration/parser/ruby_manifest_spec.rb | 128 |
4 files changed, 205 insertions, 1 deletions
diff --git a/spec/integration/application/doc_spec.rb b/spec/integration/application/doc_spec.rb new file mode 100644 index 000000000..eaf5442a0 --- /dev/null +++ b/spec/integration/application/doc_spec.rb @@ -0,0 +1,55 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet_spec/files' + +describe Puppet::Application::Doc do + include PuppetSpec::Files + + it "should not generate an error when module dir overlaps parent of site.pp (#4798)" do + begin + # Note: the directory structure below is more complex than it + # needs to be, but it's representative of the directory structure + # used in bug #4798. + old_dir = Dir.getwd # Note: can't use chdir with a block because it will generate bogus warnings + tmpdir = tmpfile('doc_spec') + Dir.mkdir(tmpdir) + Dir.chdir(tmpdir) + site_file = 'site.pp' + File.open(site_file, 'w') do |f| + f.puts '# A comment' + end + modules_dir = 'modules' + Dir.mkdir(modules_dir) + rt_dir = File.join(modules_dir, 'rt') + Dir.mkdir(rt_dir) + manifests_dir = File.join(rt_dir, 'manifests') + Dir.mkdir(manifests_dir) + rt_file = File.join(manifests_dir, 'rt.pp') + File.open(rt_file, 'w') do |f| + f.puts '# A class' + f.puts 'class foo { }' + f.puts '# A definition' + f.puts 'define bar { }' + end + + puppet = Puppet::Application[:doc] + Puppet[:modulepath] = modules_dir + Puppet[:manifest] = site_file + puppet.options[:mode] = :rdoc + puppet.expects(:exit).with(0) + puppet.run_command + + File.should be_exist('doc') + ensure + Dir.chdir(old_dir) + end + end + + it "should respect the -o option" do + puppetdoc = Puppet::Application[:doc] + puppetdoc.command_line.stubs(:args).returns(['foo', '-o', 'bar']) + puppetdoc.parse_options + puppetdoc.options[:outputdir].should == 'bar' + end +end diff --git a/spec/integration/defaults_spec.rb b/spec/integration/defaults_spec.rb index 4ae2983f4..1f90c7cbc 100755 --- a/spec/integration/defaults_spec.rb +++ b/spec/integration/defaults_spec.rb @@ -227,7 +227,7 @@ describe "Puppet defaults" do it "should have a :caname setting that defaults to the cert name" do Puppet.settings[:certname] = "foo" - Puppet.settings[:ca_name].should == "foo" + Puppet.settings[:ca_name].should == "Puppet CA: foo" end it "should have a 'prerun_command' that defaults to the empty string" do diff --git a/spec/integration/parser/compiler_spec.rb b/spec/integration/parser/compiler_spec.rb index 9158ad1c2..f80221e3d 100755 --- a/spec/integration/parser/compiler_spec.rb +++ b/spec/integration/parser/compiler_spec.rb @@ -27,6 +27,27 @@ describe Puppet::Parser::Compiler do @compiler.catalog.version.should == version end + it "should not create duplicate resources when a class is referenced both directly and indirectly by the node classifier (4792)" do + Puppet[:code] = <<-PP + class foo + { + notify { foo_notify: } + include bar + } + class bar + { + notify { bar_notify: } + } + PP + + @node.stubs(:classes).returns(['foo', 'bar']) + + catalog = Puppet::Parser::Compiler.compile(@node) + + catalog.resource("Notify[foo_notify]").should_not be_nil + catalog.resource("Notify[bar_notify]").should_not be_nil + end + describe "when resolving class references" do it "should favor local scope, even if there's an included class in topscope" do Puppet[:code] = <<-PP diff --git a/spec/integration/parser/ruby_manifest_spec.rb b/spec/integration/parser/ruby_manifest_spec.rb new file mode 100644 index 000000000..af110d3b3 --- /dev/null +++ b/spec/integration/parser/ruby_manifest_spec.rb @@ -0,0 +1,128 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'tempfile' +require 'puppet_spec/files' + +describe "Pure ruby manifests" do + include PuppetSpec::Files + + before do + @node = Puppet::Node.new "testnode" + + @scope_resource = stub 'scope_resource', :builtin? => true, :finish => nil, :ref => 'Class[main]' + @scope = stub 'scope', :resource => @scope_resource, :source => mock("source") + @test_dir = tmpdir('ruby_manifest_test') + end + + after do + Puppet.settings.clear + end + + def write_file(name, contents) + path = File.join(@test_dir, name) + File.open(path, "w") { |f| f.write(contents) } + path + end + + def compile(contents) + Puppet[:code] = contents + Dir.chdir(@test_dir) do + Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) + end + end + + it "should allow classes" do + write_file('foo.rb', ["hostclass 'one' do notify('one_notify') end", + "hostclass 'two' do notify('two_notify') end"].join("\n")) + catalog = compile("import 'foo'\ninclude one") + catalog.resource("Notify[one_notify]").should_not be_nil + catalog.resource("Notify[two_notify]").should be_nil + end + + it "should allow defines" do + write_file('foo.rb', 'define "bar", :arg do notify("bar_#{@name}_#{@arg}") end') + catalog = compile("import 'foo'\nbar { instance: arg => 'xyz' }") + catalog.resource("Notify[bar_instance_xyz]").should_not be_nil + catalog.resource("Bar[instance]").should_not be_nil + end + + it "should allow node declarations" do + write_file('foo.rb', "node 'mynode' do notify('mynode') end") + catalog = compile("import 'foo'") + node_declaration = catalog.resource("Notify[mynode]") + node_declaration.should_not be_nil + node_declaration.title.should == 'mynode' + end + + it "should allow access to the environment" do + write_file('foo.rb', ["hostclass 'bar' do", + " if environment.is_a? Puppet::Node::Environment", + " notify('success')", + " end", + "end"].join("\n")) + compile("import 'foo'\ninclude bar").resource("Notify[success]").should_not be_nil + end + + it "should allow creation of resources of built-in types" do + write_file('foo.rb', "hostclass 'bar' do file 'test_file', :owner => 'root', :mode => '644' end") + catalog = compile("import 'foo'\ninclude bar") + file = catalog.resource("File[test_file]") + file.should be_a Puppet::Resource + file.type.should == 'File' + file.title.should == 'test_file' + file.exported.should_not be + file.virtual.should_not be + file[:owner].should == 'root' + file[:mode].should == '644' + file[:stage].should be_nil # TODO: is this correct behavior? + end + + it "should allow calling user-defined functions" do + write_file('foo.rb', "hostclass 'bar' do user_func 'name', :arg => 'xyz' end") + catalog = compile(['define user_func($arg) { notify {"n_$arg": } }', + 'import "foo"', + 'include bar'].join("\n")) + catalog.resource("Notify[n_xyz]").should_not be_nil + catalog.resource("User_func[name]").should_not be_nil + end + + it "should be properly cached for multiple compiles" do + # Note: we can't test this by calling compile() twice, because + # that sets Puppet[:code], which clears out all cached + # environments. + Puppet[:filetimeout] = 1000 + write_file('foo.rb', "hostclass 'bar' do notify('success') end") + Puppet[:code] = "import 'foo'\ninclude bar" + + # Compile the catalog and check it + catalog = Dir.chdir(@test_dir) do + Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) + end + catalog.resource("Notify[success]").should_not be_nil + + # Secretly change the file to make it invalid. This change + # shouldn't be noticed because the we've set a high + # Puppet[:filetimeout]. + write_file('foo.rb', "raise 'should not be executed'") + + # Compile the catalog a second time and make sure it's still ok. + catalog = Dir.chdir(@test_dir) do + Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) + end + catalog.resource("Notify[success]").should_not be_nil + end + + it "should be properly reloaded when stale" do + Puppet[:filetimeout] = -1 # force stale check to happen all the time + write_file('foo.rb', "hostclass 'bar' do notify('version1') end") + catalog = compile("import 'foo'\ninclude bar") + catalog.resource("Notify[version1]").should_not be_nil + sleep 1 # so that timestamp will change forcing file reload + write_file('foo.rb', "hostclass 'bar' do notify('version2') end") + catalog = compile("import 'foo'\ninclude bar") + catalog.resource("Notify[version1]").should be_nil + catalog.resource("Notify[version2]").should_not be_nil + end +end |
