summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/language/ast.rb2
-rwxr-xr-xtest/language/ast/resource.rb58
-rwxr-xr-xtest/language/ast/resource_reference.rb2
-rwxr-xr-xtest/language/ast/variable.rb3
-rwxr-xr-xtest/language/snippets.rb4
-rwxr-xr-xtest/lib/puppettest.rb3
-rwxr-xr-xtest/other/provider.rb15
-rwxr-xr-xtest/other/report.rb10
-rwxr-xr-xtest/other/transactions.rb319
-rwxr-xr-xtest/ral/type/host.rb35
-rwxr-xr-xtest/ral/type/resources.rb66
-rwxr-xr-xtest/ral/type/sshkey.rb41
-rwxr-xr-xtest/util/settings.rb20
13 files changed, 86 insertions, 492 deletions
diff --git a/test/language/ast.rb b/test/language/ast.rb
index 209bc9863..916c34d45 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -56,7 +56,7 @@ class TestAST < Test::Unit::TestCase
ref = resourceoverride("file", "/yayness", "owner" => "blah", "group" => "boo")
end
- Puppet::Parser::Resource.expects(:new).with { |o| o.is_a?(Hash) }.returns(:override)
+ Puppet::Parser::Resource.expects(:new).with { |type, title, o| o.is_a?(Hash) }.returns(:override)
scope.compiler.expects(:add_override).with(:override)
ret = nil
assert_nothing_raised do
diff --git a/test/language/ast/resource.rb b/test/language/ast/resource.rb
deleted file mode 100755
index 4124655ca..000000000
--- a/test/language/ast/resource.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke A. Kanies on 2007-07-8.
-# Copyright (c) 2007. All rights reserved.
-
-require File.dirname(__FILE__) + '/../../lib/puppettest'
-
-require 'puppettest'
-require 'puppettest/parsertesting'
-
-class TestASTResource< Test::Unit::TestCase
- include PuppetTest
- include PuppetTest::ParserTesting
- AST = Puppet::Parser::AST
-
- def setup
- super
- @scope = mkscope
- @parser = @scope.compiler.parser
- end
-
- def newdef(type, title, params = nil)
- params ||= AST::ASTArray.new(:children => [])
- AST::Resource.new(:type => type, :title => AST::String.new(:value => title), :params => params)
- end
-
- # Related to #806, make sure resources always look up the full path to the resource.
- def test_scoped_types
- @parser.newdefine "one"
- @parser.newdefine "one::two"
- @parser.newdefine "three"
- twoscope = @scope.newscope(:namespace => "one")
- twoscope.resource = @scope.resource
- assert(twoscope.find_definition("two"), "Could not find 'two' definition")
- title = "title"
-
- # First try a qualified type
- assert_equal("One::Two", newdef("two", title).evaluate(twoscope)[0].type,
- "Defined type was not made fully qualified")
-
- # Then try a type that does not need to be qualified
- assert_equal("One", newdef("one", title).evaluate(twoscope)[0].type,
- "Unqualified defined type was not handled correctly")
-
- # Then an unqualified type from within the one namespace
- assert_equal("Three", newdef("three", title).evaluate(twoscope)[0].type,
- "Defined type was not made fully qualified")
-
- # Then a builtin type
- assert_equal("File", newdef("file", title).evaluate(twoscope)[0].type,
- "Builtin type was not handled correctly")
-
- # Now try a type that does not exist, which should throw an error.
- assert_raise(Puppet::ParseError, "Did not fail on a missing type in a resource reference") do
- newdef("nosuchtype", title).evaluate(twoscope)
- end
- end
-end
diff --git a/test/language/ast/resource_reference.rb b/test/language/ast/resource_reference.rb
index 325dd2118..5abb0d6e5 100755
--- a/test/language/ast/resource_reference.rb
+++ b/test/language/ast/resource_reference.rb
@@ -20,7 +20,7 @@ class TestASTResourceReference < Test::Unit::TestCase
def setup
super
@scope = mkscope
- @parser = @scope.compiler.parser
+ @parser = Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
end
# Related to #706, make sure resource references correctly translate to qualified types.
diff --git a/test/language/ast/variable.rb b/test/language/ast/variable.rb
index 49b1dbbc2..6a8b028bd 100755
--- a/test/language/ast/variable.rb
+++ b/test/language/ast/variable.rb
@@ -15,8 +15,7 @@ class TestVariable < Test::Unit::TestCase
def setup
super
- @interp = mkinterp
- @scope = mkscope :interp => @interp
+ @scope = mkscope
@name = "myvar"
@var = AST::Variable.new(:value => @name)
end
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index bd0d34872..6aa202640 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -74,10 +74,6 @@ class TestSnippets < Test::Unit::TestCase
end
def ast2scope(ast)
- interp = Puppet::Parser::Interpreter.new(
- :ast => ast,
- :client => client()
- )
scope = Puppet::Parser::Scope.new()
ast.evaluate(scope)
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index 786c37074..32f57f394 100755
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -226,6 +226,9 @@ module PuppetTest
Puppet[:ignoreschedules] = true
#@start = Time.now
+
+ #Facter.stubs(:value).returns "stubbed_value"
+ #Facter.stubs(:to_hash).returns({})
end
def tempfile
diff --git a/test/other/provider.rb b/test/other/provider.rb
index b0860f634..e746a330a 100755
--- a/test/other/provider.rb
+++ b/test/other/provider.rb
@@ -33,21 +33,6 @@ class TestImpl < Test::Unit::TestCase
return provider
end
- # Just a quick run-through to see if the basics work
- def test_newprovider
- assert_nothing_raised do
- @provider.confine :operatingsystem => Facter["operatingsystem"].value
- @provider.defaultfor :operatingsystem => Facter["operatingsystem"].value
- end
-
- assert(@provider.suitable?, "Implementation was not considered suitable")
- assert(@provider.default?, "Implementation was not considered a default")
-
- assert_equal(@provider, @type.defaultprovider,
- "Did not correctly find default provider")
-
- end
-
def test_provider_default
nondef = nil
assert_nothing_raised {
diff --git a/test/other/report.rb b/test/other/report.rb
index 692ed54b6..147a0eae7 100755
--- a/test/other/report.rb
+++ b/test/other/report.rb
@@ -32,7 +32,10 @@ class TestReports < Test::Unit::TestCase
config.retrieval_duration = 0.001
trans = config.apply
- return trans.generate_report
+ report = Puppet::Transaction::Report.new
+ trans.add_metrics_to_report(report)
+
+ return report
end
# Make sure we can use reports as log destinations.
@@ -224,10 +227,7 @@ class TestReports < Test::Unit::TestCase
def test_summary
report = mkreport
- summary = nil
- assert_nothing_raised("Could not create report summary") do
- summary = report.summary
- end
+ summary = report.summary
%w{Changes Total Resources}.each do |main|
assert(summary.include?(main), "Summary did not include info for %s" % main)
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 6f4f5d913..9a3afbd7a 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -118,319 +118,6 @@ class TestTransactions < Test::Unit::TestCase
assert_equal({inst.title => inst}, $prefetched, "evaluate did not call prefetch")
end
- def test_refreshes_generate_events
- path = tempfile()
- firstpath = tempfile()
- secondpath = tempfile()
- file = Puppet::Type.type(:file).new(:title => "file", :path => path, :content => "yayness")
- first = Puppet::Type.type(:exec).new(:title => "first",
- :command => "/bin/echo first > #{firstpath}",
- :subscribe => Puppet::Resource.new(:file, path),
- :refreshonly => true
- )
- second = Puppet::Type.type(:exec).new(:title => "second",
- :command => "/bin/echo second > #{secondpath}",
- :subscribe => Puppet::Resource.new(:exec, "first"),
- :refreshonly => true
- )
-
- assert_apply(file, first, second)
-
- assert(FileTest.exists?(secondpath), "Refresh did not generate an event")
- end
-
- unless %x{groups}.chomp.split(/ /).length > 1
- $stderr.puts "You must be a member of more than one group to test transactions"
- else
- def ingroup(gid)
- require 'etc'
- begin
- group = Etc.getgrgid(gid)
- rescue => detail
- puts "Could not retrieve info for group %s: %s" % [gid, detail]
- return nil
- end
-
- return @groups.include?(group.name)
- end
-
- def setup
- super
- @groups = %x{groups}.chomp.split(/ /)
- unless @groups.length > 1
- p @groups
- raise "You must be a member of more than one group to test this"
- end
- end
-
- def newfile(hash = {})
- tmpfile = tempfile()
- File.open(tmpfile, "w") { |f| f.puts rand(100) }
-
- # XXX now, because os x apparently somehow allows me to make a file
- # owned by a group i'm not a member of, i have to verify that
- # the file i just created is owned by one of my groups
- # grrr
- unless ingroup(File.stat(tmpfile).gid)
- Puppet.info "Somehow created file in non-member group %s; fixing" %
- File.stat(tmpfile).gid
-
- require 'etc'
- firstgr = @groups[0]
- unless firstgr.is_a?(Integer)
- str = Etc.getgrnam(firstgr)
- firstgr = str.gid
- end
- File.chown(nil, firstgr, tmpfile)
- end
-
- hash[:name] = tmpfile
- assert_nothing_raised() {
- return Puppet::Type.type(:file).new(hash)
- }
- end
-
- def newexec(file)
- assert_nothing_raised() {
- return Puppet::Type.type(:exec).new(
- :name => "touch %s" % file,
- :path => "/bin:/usr/bin:/sbin:/usr/sbin",
- :returns => 0
- )
- }
- end
-
- # test that services are correctly restarted and that work is done
- # in the right order
- def test_refreshing
- transaction = nil
- file = newfile()
- execfile = File.join(tmpdir(), "exectestingness")
- exec = newexec(execfile)
- properties = {}
- check = [:group,:mode]
- file[:check] = check
- file[:group] = @groups[0]
-
- config = mk_catalog(file)
- config.apply
-
- @@tmpfiles << execfile
-
- # 'subscribe' expects an array of arrays
- exec[:subscribe] = Puppet::Resource.new(file.class.name,file.name)
- exec[:refreshonly] = true
-
- assert_nothing_raised() {
- file.retrieve
- exec.retrieve
- }
-
- check.each { |property|
- properties[property] = file.value(property)
- }
- assert_nothing_raised() {
- file[:mode] = "755"
- }
-
- # Make a new catalog so the resource relationships get
- # set up.
- config = mk_catalog(file, exec)
-
- trans = assert_events([:mode_changed, :restarted], config)
-
- assert(FileTest.exists?(execfile), "Execfile does not exist")
- File.unlink(execfile)
- assert_nothing_raised() {
- file[:group] = @groups[1]
- }
-
- trans = assert_events([:group_changed, :restarted], config)
- assert(FileTest.exists?(execfile), "Execfile does not exist")
- end
-
- # Verify that one component requiring another causes the contained
- # resources in the requiring component to get refreshed.
- def test_refresh_across_two_components
- transaction = nil
- file = newfile()
- execfile = File.join(tmpdir(), "exectestingness2")
- @@tmpfiles << execfile
- exec = newexec(execfile)
- properties = {}
- check = [:group,:mode]
- file[:check] = check
- file[:group] = @groups[0]
- assert_apply(file)
-
- config = Puppet::Resource::Catalog.new
- fcomp = Puppet::Type.type(:component).new(:name => "file")
- config.add_resource fcomp
- config.add_resource file
- config.add_edge(fcomp, file)
-
- ecomp = Puppet::Type.type(:component).new(:name => "exec")
- config.add_resource ecomp
- config.add_resource exec
- config.add_edge(ecomp, exec)
-
- # 'subscribe' expects an array of arrays
- #component[:require] = [[file.class.name,file.name]]
- ecomp[:subscribe] = fcomp.ref
- exec[:refreshonly] = true
-
- trans = assert_events([], config)
-
- assert_nothing_raised() {
- file[:group] = @groups[1]
- file[:mode] = "755"
- }
-
- trans = assert_events([:group_changed, :mode_changed, :restarted], config)
- end
-
- # Make sure that multiple subscriptions get triggered.
- def test_multisubs
- path = tempfile()
- file1 = tempfile()
- file2 = tempfile()
- file = Puppet::Type.type(:file).new(
- :path => path,
- :ensure => "file"
- )
- exec1 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch %s" % file1,
- :refreshonly => true,
- :subscribe => Puppet::Resource.new(:file, path)
- )
- exec2 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch %s" % file2,
- :refreshonly => true,
- :subscribe => Puppet::Resource.new(:file, path)
- )
-
- assert_apply(file, exec1, exec2)
- assert(FileTest.exists?(file1), "File 1 did not get created")
- assert(FileTest.exists?(file2), "File 2 did not get created")
- end
-
- # Make sure that a failed trigger doesn't result in other events not
- # getting triggered.
- def test_failedrefreshes
- path = tempfile()
- newfile = tempfile()
- file = Puppet::Type.type(:file).new(
- :path => path,
- :ensure => "file"
- )
- exec1 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch /this/cannot/possibly/exist",
- :logoutput => true,
- :refreshonly => true,
- :subscribe => file,
- :title => "one"
- )
- exec2 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch %s" % newfile,
- :logoutput => true,
- :refreshonly => true,
- :subscribe => [file, exec1],
- :title => "two"
- )
-
- assert_apply(file, exec1, exec2)
- assert(FileTest.exists?(newfile), "Refresh file did not get created")
- end
-
- # Make sure that unscheduled and untagged objects still respond to events
- def test_unscheduled_and_untagged_response
- Puppet::Type.type(:schedule).mkdefaultschedules
- Puppet[:ignoreschedules] = false
- file = Puppet::Type.type(:file).new(
- :name => tempfile(),
- :ensure => "file",
- :backup => false
- )
-
- fname = tempfile()
- exec = Puppet::Type.type(:exec).new(
- :name => "touch %s" % fname,
- :path => "/usr/bin:/bin",
- :schedule => "monthly",
- :subscribe => Puppet::Resource.new("file", file.name)
- )
-
- config = mk_catalog(file, exec)
-
- # Run it once
- assert_apply(config)
- assert(FileTest.exists?(fname), "File did not get created")
-
- assert(!exec.scheduled?, "Exec is somehow scheduled")
-
- # Now remove it, so it can get created again
- File.unlink(fname)
-
- file[:content] = "some content"
-
- assert_events([:content_changed, :restarted], config)
-
- assert(FileTest.exists?(fname), "File did not get recreated")
-
- # Now remove it, so it can get created again
- File.unlink(fname)
-
- # And tag our exec
- exec.tag("testrun")
-
- # And our file, so it runs
- file.tag("norun")
-
- Puppet[:tags] = "norun"
-
- file[:content] = "totally different content"
-
- assert(! file.insync?(file.retrieve), "Uh, file is in sync?")
-
- assert_events([:content_changed, :restarted], config)
- assert(FileTest.exists?(fname), "File did not get recreated")
- end
-
- def test_failed_reqs_mean_no_run
- exec = Puppet::Type.type(:exec).new(
- :command => "/bin/mkdir /this/path/cannot/possibly/exit",
- :title => "mkdir"
- )
-
- file1 = Puppet::Type.type(:file).new(
- :title => "file1",
- :path => tempfile(),
- :require => exec,
- :ensure => :file
- )
-
- file2 = Puppet::Type.type(:file).new(
- :title => "file2",
- :path => tempfile(),
- :require => file1,
- :ensure => :file
- )
-
- config = mk_catalog(exec, file1, file2)
-
- assert_apply(config)
-
- assert(! FileTest.exists?(file1[:path]),
- "File got created even tho its dependency failed")
- assert(! FileTest.exists?(file2[:path]),
- "File got created even tho its deep dependency failed")
- end
- end
-
# We need to generate resources before we prefetch them, else generated
# resources that require prefetching don't work.
def test_generate_before_prefetch
@@ -612,13 +299,7 @@ class TestTransactions < Test::Unit::TestCase
def test_explicit_dependencies_beat_automatic
# Create a couple of different resource sets that have automatic relationships and make sure the manual relationships win
rels = {}
- # First users and groups
- group = Puppet::Type.type(:group).new(:name => nonrootgroup.name, :ensure => :present)
- user = Puppet::Type.type(:user).new(:name => nonrootuser.name, :ensure => :present, :gid => group.title)
-
# Now add the explicit relationship
- group[:require] = user
- rels[group] = user
# Now files
d = tempfile()
f = File.join(d, "file")
diff --git a/test/ral/type/host.rb b/test/ral/type/host.rb
index c99beb9a3..308e84bc0 100755
--- a/test/ral/type/host.rb
+++ b/test/ral/type/host.rb
@@ -108,17 +108,6 @@ class TestHost < Test::Unit::TestCase
# This was a hard bug to track down.
assert_instance_of(String, current_values[host.property(:ip)])
- host[:host_aliases] = %w{madstop kirby yayness}
-
- assert_events([:host_aliases_changed], host)
-
- assert_nothing_raised {
- current_values = host.retrieve
- }
-
- assert_equal(%w{madstop kirby yayness},
- current_values[host.property(:host_aliases)])
-
host[:ensure] = :absent
assert_events([:host_removed], host)
end
@@ -182,28 +171,4 @@ class TestHost < Test::Unit::TestCase
host[:name] = "y"
}
end
-
- def test_aliasisproperty
- assert_equal(:property, @hosttype.attrtype(:host_aliases))
- end
-
- def test_multivalues
- host = mkhost
- assert_raise(Puppet::Error) {
- host[:host_aliases] = "puppetmasterd yayness"
- }
- end
-
- def test_puppetalias
- host = mkhost()
- catalog = mk_catalog(host)
-
- assert_nothing_raised {
- host[:alias] = "testing"
- }
-
- same = catalog.resource(:host, "testing")
- assert(same, "Could not retrieve by alias")
- end
end
-
diff --git a/test/ral/type/resources.rb b/test/ral/type/resources.rb
index 1bfc9d358..adc75cb71 100755
--- a/test/ral/type/resources.rb
+++ b/test/ral/type/resources.rb
@@ -59,6 +59,71 @@ class TestResources < Test::Unit::TestCase
@type = Puppet::Type.type(:resources)
end
+ def test_purge
+ # Create a purgeable type
+ mkpurgertype
+
+ purger = nil
+ assert_nothing_raised do
+ purger = @type.new :name => "purgetest", :noop => true, :loglevel => :warning
+ end
+ purger.catalog = Puppet::Resource::Catalog.new
+ assert(purger, "did not get purger manager")
+ add_purge_lister()
+
+ assert_equal($purgemembers.values.sort, @purgetype.instances.sort)
+
+ # and it should now succeed
+ assert_nothing_raised do
+ purger[:purge] = true
+ end
+ assert(purger.purge?, "purge boolean was not enabled")
+
+ # Okay, now let's try doing some purging, yo
+ managed = []
+ unmanned = []
+ 3.times { managed << mk_purger(true) } # 3 managed
+ 3.times { unmanned << mk_purger(false) } # 3 unmanaged
+
+ managed.each do |m|
+ assert(m.managed?, "managed resource was not considered managed")
+ end
+ unmanned.each do |u|
+ assert(! u.managed?, "unmanaged resource was considered managed")
+ end
+
+ # First make sure we get nothing back when purge is false
+ genned = nil
+ purger[:purge] = false
+ assert_nothing_raised do
+ genned = purger.generate
+ end
+ assert_equal([], genned, "Purged even when purge is false")
+
+ # Now make sure we can purge
+ purger[:purge] = true
+ assert_nothing_raised do
+ genned = purger.generate
+ end
+ assert(genned, "Did not get any generated resources")
+
+ genned.each do |res|
+ assert(res.purging, "did not mark resource for purging")
+ end
+ assert(! genned.empty?, "generated resource list was empty")
+
+ # Now make sure the generate method only finds the unmanaged resources
+ assert_equal(unmanned.collect { |r| r.title }.sort, genned.collect { |r| r.title },
+ "Did not return correct purge list")
+
+ # Now make sure our metaparams carried over
+ genned.each do |res|
+ [:noop, :loglevel].each do |param|
+ assert_equal(purger[param], res[param], "metaparam %s did not carry over" % param)
+ end
+ end
+ end
+
# Part of #408.
def test_check
# First check a non-user
@@ -108,6 +173,5 @@ class TestResources < Test::Unit::TestCase
assert(res.check(@user.create(:name => high)), "high user %s failed check" % high)
end
end
-
end
diff --git a/test/ral/type/sshkey.rb b/test/ral/type/sshkey.rb
index b528317a3..b68c14b34 100755
--- a/test/ral/type/sshkey.rb
+++ b/test/ral/type/sshkey.rb
@@ -98,47 +98,6 @@ class TestSSHKey < Test::Unit::TestCase
end
- def test_moddingkey
- key = mkkey()
-
- @catalog.apply
-
- key.retrieve
-
- aliases = %w{madstop kirby yayness}
- key[:alias] = aliases
-
- @catalog.apply
-
- aliases.each do |name|
- assert_equal(key.object_id, @catalog.resource(:sshkey, name).object_id, "alias %s was not set" % name)
- end
- end
-
- def test_aliasisproperty
- assert_equal(:property, @sshkeytype.attrtype(:host_aliases))
- end
-
- def test_multivalues
- key = mkkey
- assert_raise(Puppet::Error) {
- key[:host_aliases] = "puppetmasterd yayness"
- }
- end
-
- def test_puppetalias
- key = mkkey()
-
- assert_nothing_raised {
- key[:alias] = "testing"
- }
-
- key.finish
-
- same = @catalog.resource(:sshkey, "testing")
- assert(same, "Could not retrieve by alias")
- end
-
def test_removal
sshkey = mkkey()
assert_nothing_raised {
diff --git a/test/util/settings.rb b/test/util/settings.rb
index 1e8eb4864..a080ca03b 100755
--- a/test/util/settings.rb
+++ b/test/util/settings.rb
@@ -78,10 +78,8 @@ class TestSettings < Test::Unit::TestCase
end
def mkconfig
- c = nil
- assert_nothing_raised {
- c = Puppet::Util::Settings.new
- }
+ c = Puppet::Util::Settings.new
+ c.setdefaults :main, :noop => [false, "foo"]
return c
end
@@ -303,6 +301,8 @@ yay = /a/path
end
def test_addargs_functional
+ @config = Puppet::Util::Settings.new
+
@config.setdefaults("testing",
:onboolean => [true, "An on bool"],
:string => ["a string", "A string arg"]
@@ -666,15 +666,15 @@ yay = /a/path
end
# Test to make sure that we can set and get a short name
- def test_celement_short_name
- element = nil
- assert_nothing_raised("Could not create celement") do
- element = Setting.new :short => "n", :desc => "anything", :settings => Puppet::Util::Settings.new
+ def test_setting_short_name
+ setting= nil
+ assert_nothing_raised("Could not create setting") do
+ setting= Setting.new :short => "n", :desc => "anything", :settings => Puppet::Util::Settings.new
end
- assert_equal("n", element.short, "Short value is not retained")
+ assert_equal("n", setting.short, "Short value is not retained")
assert_raise(ArgumentError,"Allowed multicharactered short names.") do
- element = Setting.new :short => "no", :desc => "anything", :settings => Puppet::Util::Settings.new
+ setting= Setting.new :short => "no", :desc => "anything", :settings => Puppet::Util::Settings.new
end
end