summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-10-01 11:35:35 -0700
committerJesse Wolfe <jes5199@gmail.com>2010-10-01 11:35:35 -0700
commitda84c03a7d1fe33c660c3e4c3a069ef1aed23bae (patch)
treea75697d977d90b7754e0a14dcfc13b33aff893d1 /spec
parent0077379e528037d875a92575a994d01ca5233cc0 (diff)
parent917c520f1abc0c72d7065531cffcef88259e32e0 (diff)
Merge commit '2.6.2rc1'
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/yaml/report0.25.x.yaml64
-rw-r--r--spec/fixtures/yaml/report2.6.x.yaml190
-rw-r--r--spec/integration/application/doc_spec.rb55
-rwxr-xr-xspec/integration/defaults_spec.rb2
-rwxr-xr-xspec/integration/parser/compiler_spec.rb21
-rw-r--r--spec/integration/parser/ruby_manifest_spec.rb128
-rw-r--r--spec/lib/puppet_spec/files.rb1
-rw-r--r--spec/spec_helper.rb1
-rwxr-xr-xspec/unit/application_spec.rb41
-rwxr-xr-xspec/unit/dsl/resource_type_api_spec.rb44
-rwxr-xr-xspec/unit/indirector/node/active_record_spec.rb1
-rw-r--r--spec/unit/parser/ast/function_spec.rb18
-rwxr-xr-xspec/unit/parser/lexer_spec.rb8
-rwxr-xr-xspec/unit/parser/parser_spec.rb9
-rw-r--r--spec/unit/parser/type_loader_spec.rb19
-rwxr-xr-xspec/unit/provider/service/launchd_spec.rb13
-rw-r--r--spec/unit/provider/user/user_role_add_spec.rb19
-rwxr-xr-xspec/unit/provider/user/useradd_spec.rb19
-rwxr-xr-xspec/unit/rails_spec.rb14
-rw-r--r--spec/unit/reports/rrdgraph_spec.rb31
-rwxr-xr-xspec/unit/reports/tagmail_spec.rb1
-rw-r--r--spec/unit/sslcertificates/ca_spec.rb110
-rwxr-xr-xspec/unit/type/user_spec.rb20
-rw-r--r--spec/unit/type/whit_spec.rb11
-rwxr-xr-xspec/unit/type_spec.rb7
-rwxr-xr-xspec/unit/util/rdoc/parser_spec.rb32
-rwxr-xr-x[-rw-r--r--]spec/unit/util/zaml_spec.rb3
27 files changed, 788 insertions, 94 deletions
diff --git a/spec/fixtures/yaml/report0.25.x.yaml b/spec/fixtures/yaml/report0.25.x.yaml
new file mode 100644
index 000000000..ce6a64286
--- /dev/null
+++ b/spec/fixtures/yaml/report0.25.x.yaml
@@ -0,0 +1,64 @@
+--- !ruby/object:Puppet::Transaction::Report
+ host: mattmac.local
+ logs:
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym info
+ message: Applying configuration version '1285283846'
+ source: Puppet
+ tags:
+ - info
+ time: 2010-09-23 16:17:26.977750 -07:00
+ metrics:
+ time: !ruby/object:Puppet::Util::Metric
+ label: Time
+ name: time
+ values:
+ - - !ruby/sym config_retrieval
+ - Config retrieval
+ - 0.955046892166138
+ - - !ruby/sym schedule
+ - Schedule
+ - 0.00123691558837891
+ - - !ruby/sym total
+ - Total
+ - 0.956486701965332
+ - - !ruby/sym filebucket
+ - Filebucket
+ - 0.00020289421081543
+ resources: !ruby/object:Puppet::Util::Metric
+ label: Resources
+ name: resources
+ values:
+ - - !ruby/sym skipped
+ - Skipped
+ - 0
+ - - !ruby/sym scheduled
+ - Scheduled
+ - 7
+ - - !ruby/sym applied
+ - Applied
+ - 0
+ - - !ruby/sym restarted
+ - Restarted
+ - 0
+ - - !ruby/sym total
+ - Total
+ - 10
+ - - !ruby/sym failed_restarts
+ - Failed restarts
+ - 0
+ - - !ruby/sym out_of_sync
+ - Out of sync
+ - 0
+ - - !ruby/sym failed
+ - Failed
+ - 0
+ changes: !ruby/object:Puppet::Util::Metric
+ label: Changes
+ name: changes
+ values:
+ - - !ruby/sym total
+ - Total
+ - 0
+ records: {}
+ time: 2010-09-23 16:17:26.987789 -07:00 \ No newline at end of file
diff --git a/spec/fixtures/yaml/report2.6.x.yaml b/spec/fixtures/yaml/report2.6.x.yaml
new file mode 100644
index 000000000..dd4c3814e
--- /dev/null
+++ b/spec/fixtures/yaml/report2.6.x.yaml
@@ -0,0 +1,190 @@
+--- !ruby/object:Puppet::Transaction::Report
+ external_times:
+ !ruby/sym config_retrieval: 0.170313835144043
+ host: ubuntu1004desktop.localdomain
+ logs:
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: Using cached certificate for ca
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.244173 -07:00
+ version: &id001 2.6.1
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: Using cached certificate for ubuntu1004desktop.localdomain
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.244764 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: Using cached certificate_revocation_list for ca
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.245677 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: "catalog supports formats: b64_zlib_yaml dot marshal pson raw yaml; using pson"
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.247069 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym info
+ message: Caching catalog for ubuntu1004desktop.localdomain
+ source: Puppet
+ tags:
+ - info
+ time: 2010-09-23 15:44:06.409109 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: Creating default schedules
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.418755 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: Loaded state in 0.00 seconds
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.427441 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym info
+ message: Applying configuration version '1285281846'
+ source: Puppet
+ tags:
+ - info
+ time: 2010-09-23 15:44:06.429532 -07:00
+ version: *id001
+ metrics:
+ time: !ruby/object:Puppet::Util::Metric
+ label: Time
+ name: time
+ values:
+ - - config_retrieval
+ - Config retrieval
+ - 0.170313835144043
+ - - schedule
+ - Schedule
+ - 0.00077
+ - - filebucket
+ - Filebucket
+ - 0.000166
+ resources: !ruby/object:Puppet::Util::Metric
+ label: Resources
+ name: resources
+ values:
+ - - !ruby/sym total
+ - Total
+ - 7
+ events: !ruby/object:Puppet::Util::Metric
+ label: Events
+ name: events
+ values:
+ - - !ruby/sym total
+ - Total
+ - 0
+ changes: !ruby/object:Puppet::Util::Metric
+ label: Changes
+ name: changes
+ values:
+ - - !ruby/sym total
+ - Total
+ - 0
+ resource_statuses:
+ "Schedule[monthly]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000121
+ events: []
+ file:
+ line:
+ resource: "Schedule[monthly]"
+ source_description: "/Schedule[monthly]"
+ tags:
+ - schedule
+ - monthly
+ time: 2010-09-23 15:44:06.430577 -07:00
+ version: 1285281846
+ "Filebucket[puppet]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000166
+ events: []
+ file:
+ line:
+ resource: "Filebucket[puppet]"
+ source_description: "/Filebucket[puppet]"
+ tags:
+ - filebucket
+ - puppet
+ time: 2010-09-23 15:44:06.430998 -07:00
+ version: 1285281846
+ "Schedule[never]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000119
+ events: []
+ file:
+ line:
+ resource: "Schedule[never]"
+ source_description: "/Schedule[never]"
+ tags:
+ - schedule
+ - never
+ time: 2010-09-23 15:44:06.433034 -07:00
+ version: 1285281846
+ "Schedule[weekly]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000118
+ events: []
+ file:
+ line:
+ resource: "Schedule[weekly]"
+ source_description: "/Schedule[weekly]"
+ tags:
+ - schedule
+ - weekly
+ time: 2010-09-23 15:44:06.431443 -07:00
+ version: 1285281846
+ "Schedule[puppet]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000129
+ events: []
+ file:
+ line:
+ resource: "Schedule[puppet]"
+ source_description: "/Schedule[puppet]"
+ tags:
+ - schedule
+ - puppet
+ time: 2010-09-23 15:44:06.432626 -07:00
+ version: 1285281846
+ "Schedule[daily]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000154
+ events: []
+ file:
+ line:
+ resource: "Schedule[daily]"
+ source_description: "/Schedule[daily]"
+ tags:
+ - schedule
+ - daily
+ time: 2010-09-23 15:44:06.430130 -07:00
+ version: 1285281846
+ "Schedule[hourly]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000129
+ events: []
+ file:
+ line:
+ resource: "Schedule[hourly]"
+ source_description: "/Schedule[hourly]"
+ tags:
+ - schedule
+ - hourly
+ time: 2010-09-23 15:44:06.432185 -07:00
+ version: 1285281846
+ time: 2010-09-23 15:44:05.894401 -07:00 \ No newline at end of file
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
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
index cab4a1e47..52ed903ec 100644
--- a/spec/lib/puppet_spec/files.rb
+++ b/spec/lib/puppet_spec/files.rb
@@ -1,4 +1,5 @@
require 'fileutils'
+require 'tempfile'
# A support module for testing files.
module PuppetSpec::Files
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2fe0c36a3..b5b273857 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -20,6 +20,7 @@ module PuppetSpec
FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR)
end
+require 'spec/lib/puppet_spec/files'
require 'monkey_patches/alias_should_to_must'
require 'monkey_patches/add_confine_and_runnable_to_rspec_dsl'
require 'monkey_patches/publicize_methods'
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index 433809172..be7cda340 100755
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -191,24 +191,17 @@ describe Puppet::Application do
Puppet.settings.stubs(:optparse_addargs).returns([])
end
- it "should create a new option parser when needed" do
- option_parser = stub "option parser"
- option_parser.stubs(:on)
- OptionParser.expects(:new).returns(option_parser).once
- @app.option_parser.should == option_parser
- @app.option_parser.should == option_parser
- end
-
it "should pass the banner to the option parser" do
option_parser = stub "option parser"
option_parser.stubs(:on)
+ option_parser.stubs(:parse!)
@app.class.instance_eval do
banner "banner"
end
OptionParser.expects(:new).with("banner").returns(option_parser)
- @app.option_parser
+ @app.parse_options
end
it "should get options from Puppet.settings.optparse_addargs" do
@@ -219,15 +212,14 @@ describe Puppet::Application do
it "should add Puppet.settings options to OptionParser" do
Puppet.settings.stubs(:optparse_addargs).returns( [["--option","-o", "Funny Option"]])
-
- @app.option_parser.expects(:on).with { |*arg| arg == ["--option","-o", "Funny Option"] }
-
+ Puppet.settings.expects(:handlearg).with("--option", 'true')
+ @app.command_line.stubs(:args).returns(["--option"])
@app.parse_options
end
it "should ask OptionParser to parse the command-line argument" do
@app.command_line.stubs(:args).returns(%w{ fake args })
- @app.option_parser.expects(:parse!).with(%w{ fake args })
+ OptionParser.any_instance.expects(:parse!).with(%w{ fake args })
@app.parse_options
end
@@ -258,31 +250,30 @@ describe Puppet::Application do
describe "when dealing with an argument not declared directly by the application" do
it "should pass it to handle_unknown if this method exists" do
- Puppet.settings.stubs(:optparse_addargs).returns([["--not-handled"]])
- @app.option_parser.stubs(:on).yields("value")
+ Puppet.settings.stubs(:optparse_addargs).returns([["--not-handled", :REQUIRED]])
@app.expects(:handle_unknown).with("--not-handled", "value").returns(true)
-
+ @app.command_line.stubs(:args).returns(["--not-handled", "value"])
@app.parse_options
end
it "should pass it to Puppet.settings if handle_unknown says so" do
- Puppet.settings.stubs(:optparse_addargs).returns([["--topuppet"]])
- @app.option_parser.stubs(:on).yields("value")
+ Puppet.settings.stubs(:optparse_addargs).returns([["--topuppet", :REQUIRED]])
@app.stubs(:handle_unknown).with("--topuppet", "value").returns(false)
Puppet.settings.expects(:handlearg).with("--topuppet", "value")
+ @app.command_line.stubs(:args).returns(["--topuppet", "value"])
@app.parse_options
end
it "should pass it to Puppet.settings if there is no handle_unknown method" do
- Puppet.settings.stubs(:optparse_addargs).returns([["--topuppet"]])
- @app.option_parser.stubs(:on).yields("value")
+ Puppet.settings.stubs(:optparse_addargs).returns([["--topuppet", :REQUIRED]])
@app.stubs(:respond_to?).returns(false)
Puppet.settings.expects(:handlearg).with("--topuppet", "value")
+ @app.command_line.stubs(:args).returns(["--topuppet", "value"])
@app.parse_options
end
@@ -310,7 +301,7 @@ describe Puppet::Application do
it "should exit if OptionParser raises an error" do
$stderr.stubs(:puts)
- @app.option_parser.stubs(:parse!).raises(OptionParser::ParseError.new("blah blah"))
+ OptionParser.any_instance.stubs(:parse!).raises(OptionParser::ParseError.new("blah blah"))
@app.expects(:exit)
@@ -478,7 +469,7 @@ describe Puppet::Application do
@app.class.option("--[no-]test3","-t") do
end
- @app.option_parser
+ @app.parse_options
end
it "should pass a block that calls our defined method" do
@@ -490,7 +481,7 @@ describe Puppet::Application do
@app.class.option("--test4","-t") do
end
- @app.option_parser
+ @app.parse_options
end
end
@@ -501,7 +492,7 @@ describe Puppet::Application do
@app.class.option("--test4","-t")
- @app.option_parser
+ @app.parse_options
end
it "should give to OptionParser a block that adds the the value to the options array" do
@@ -512,7 +503,7 @@ describe Puppet::Application do
@app.class.option("--test4","-t")
- @app.option_parser
+ @app.parse_options
end
end
end
diff --git a/spec/unit/dsl/resource_type_api_spec.rb b/spec/unit/dsl/resource_type_api_spec.rb
index 5abe79ea7..4f4eb7e01 100755
--- a/spec/unit/dsl/resource_type_api_spec.rb
+++ b/spec/unit/dsl/resource_type_api_spec.rb
@@ -4,13 +4,14 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/dsl/resource_type_api'
-class DSLAPITester
- include Puppet::DSL::ResourceTypeAPI
-end
-
describe Puppet::DSL::ResourceTypeAPI do
- before do
- @api = DSLAPITester.new
+ # Run the given block in the context of a new ResourceTypeAPI
+ # object.
+ def test_api_call(&block)
+ Thread.current[:known_resource_types] = Puppet::Resource::TypeCollection.new(:env)
+ Puppet::DSL::ResourceTypeAPI.new.instance_eval(&block)
+ ensure
+ Thread.current[:known_resource_types] = nil
end
[:definition, :node, :hostclass].each do |type|
@@ -18,29 +19,48 @@ describe Puppet::DSL::ResourceTypeAPI do
it "should be able to create a #{type}" do
newtype = Puppet::Resource::Type.new(:hostclass, "foo")
Puppet::Resource::Type.expects(:new).with { |t, n, args| t == type }.returns newtype
- @api.send(method, "myname")
+ test_api_call { send(method, "myname") }
end
it "should use the provided name when creating a #{type}" do
type = Puppet::Resource::Type.new(:hostclass, "foo")
Puppet::Resource::Type.expects(:new).with { |t, n, args| n == "myname" }.returns type
- @api.send(method, "myname")
+ test_api_call { send(method, "myname") }
end
unless type == :definition
it "should pass in any provided options" do
type = Puppet::Resource::Type.new(:hostclass, "foo")
Puppet::Resource::Type.expects(:new).with { |t, n, args| args == {:myarg => :myvalue} }.returns type
- @api.send(method, "myname", :myarg => :myvalue)
+ test_api_call { send(method, "myname", :myarg => :myvalue) }
end
end
- it "should set any provided block as the type's ruby code"
+ it "should set any provided block as the type's ruby code" do
+ Puppet::Resource::Type.any_instance.expects(:ruby_code=).with { |blk| blk.call == 'foo' }
+ test_api_call { send(method, "myname") { 'foo' } }
+ end
- it "should add the type to the current environment's known resource types"
+ it "should add the type to the current environment's known resource types" do
+ begin
+ newtype = Puppet::Resource::Type.new(:hostclass, "foo")
+ Puppet::Resource::Type.expects(:new).returns newtype
+ known_resource_types = Puppet::Resource::TypeCollection.new(:env)
+ Thread.current[:known_resource_types] = known_resource_types
+ known_resource_types.expects(:add).with(newtype)
+ Puppet::DSL::ResourceTypeAPI.new.instance_eval { hostclass "myname" }
+ ensure
+ Thread.current[:known_resource_types] = nil
+ end
+ end
end
describe "when creating a definition" do
- it "should use the provided options to define valid arguments for the resource type"
+ it "should use the provided options to define valid arguments for the resource type" do
+ newtype = Puppet::Resource::Type.new(:definition, "foo")
+ Puppet::Resource::Type.expects(:new).returns newtype
+ test_api_call { define("myname", :arg1, :arg2) }
+ newtype.instance_eval { @arguments }.should == { 'arg1' => nil, 'arg2' => nil }
+ end
end
end
diff --git a/spec/unit/indirector/node/active_record_spec.rb b/spec/unit/indirector/node/active_record_spec.rb
index 6cc3f5132..3540ef738 100755
--- a/spec/unit/indirector/node/active_record_spec.rb
+++ b/spec/unit/indirector/node/active_record_spec.rb
@@ -3,7 +3,6 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/node'
-require 'spec/lib/puppet_spec/files.rb'
describe "Puppet::Node::ActiveRecord" do
include PuppetSpec::Files
diff --git a/spec/unit/parser/ast/function_spec.rb b/spec/unit/parser/ast/function_spec.rb
index c57c7f098..38e344157 100644
--- a/spec/unit/parser/ast/function_spec.rb
+++ b/spec/unit/parser/ast/function_spec.rb
@@ -61,20 +61,30 @@ describe Puppet::Parser::AST::Function do
end
it "should call the underlying ruby function" do
- argument = stub 'arg', :safeevaluate => "nothing"
+ argument = stub 'arg', :safeevaluate => ["nothing"]
Puppet::Parser::Functions.stubs(:function).with("exist").returns(true)
func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument
- @scope.expects(:function_exist).with("nothing")
+ @scope.expects(:function_exist).with(["nothing"])
+
+ func.evaluate(@scope)
+ end
+
+ it "should convert :undef to '' in arguments" do
+ argument = stub 'arg', :safeevaluate => ["foo", :undef, "bar"]
+ Puppet::Parser::Functions.stubs(:function).with("exist").returns(true)
+ func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument
+
+ @scope.expects(:function_exist).with(["foo", "", "bar"])
func.evaluate(@scope)
end
it "should return the ruby function return for rvalue functions" do
- argument = stub 'arg', :safeevaluate => "nothing"
+ argument = stub 'arg', :safeevaluate => ["nothing"]
Puppet::Parser::Functions.stubs(:function).with("exist").returns(true)
func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument
- @scope.stubs(:function_exist).with("nothing").returns("returning")
+ @scope.stubs(:function_exist).with(["nothing"]).returns("returning")
func.evaluate(@scope).should == "returning"
end
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index b27980bf2..2d67bf357 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -30,6 +30,14 @@ describe Puppet::Parser::Lexer do
@lexer.line.should == 10
end
+
+ it "should not think the terminator is escaped, when preceeded by an even number of backslashes" do
+ @lexer.line = 10
+ @lexer.string = "here\nis\nthe\nstring\\\\'with\nextra\njunk"
+ @lexer.slurpstring("'")
+
+ @lexer.line.should == 13
+ end
end
end
diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb
index 0657ab37a..f73e07a5c 100755
--- a/spec/unit/parser/parser_spec.rb
+++ b/spec/unit/parser/parser_spec.rb
@@ -52,15 +52,6 @@ describe Puppet::Parser do
@parser.file = "/my/file.rb"
@parser.parse
end
-
- describe "in ruby" do
- it "should use the ruby interpreter to load the file" do
- @parser.file = "/my/file.rb"
- @parser.expects(:require).with "/my/file.rb"
-
- @parser.parse_ruby_file
- end
- end
end
describe "when parsing append operator" do
diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb
index 83006b37b..02d543b02 100644
--- a/spec/unit/parser/type_loader_spec.rb
+++ b/spec/unit/parser/type_loader_spec.rb
@@ -77,13 +77,6 @@ describe Puppet::Parser::TypeLoader do
@loader.load_until(["foo"], "bar") { |f| false }.should be_nil
end
- it "should know when a given name has been loaded" do
- @loader.expects(:name2files).returns %w{file}
- @loader.expects(:import).with("file",nil)
- @loader.load_until(["foo"], "bar") { |f| true }
- @loader.should be_loaded("file")
- end
-
it "should set the module name on any created resource types" do
type = Puppet::Resource::Type.new(:hostclass, "mytype")
@@ -113,7 +106,8 @@ describe Puppet::Parser::TypeLoader do
describe "when importing" do
before do
Puppet::Parser::Files.stubs(:find_manifests).returns ["modname", %w{file}]
- @loader.stubs(:parse_file)
+ Puppet::Parser::Parser.any_instance.stubs(:parse)
+ Puppet::Parser::Parser.any_instance.stubs(:file=)
end
it "should return immediately when imports are being ignored" do
@@ -154,16 +148,9 @@ describe Puppet::Parser::TypeLoader do
@loader.import("myfile", "/current/file")
end
- it "should know when a given file has been imported" do
- Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}]
- @loader.import("myfile")
-
- @loader.should be_imported("/one")
- end
-
it "should not attempt to import files that have already been imported" do
Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}]
- @loader.expects(:parse_file).once
+ Puppet::Parser::Parser.any_instance.expects(:parse).once
@loader.import("myfile")
# This will fail if it tries to reimport the file.
diff --git a/spec/unit/provider/service/launchd_spec.rb b/spec/unit/provider/service/launchd_spec.rb
index 320ee3ace..43e4cba8e 100755
--- a/spec/unit/provider/service/launchd_spec.rb
+++ b/spec/unit/provider/service/launchd_spec.rb
@@ -98,19 +98,22 @@ describe provider_class do
it "should return true if the job plist says disabled is true and the global overrides says disabled is false" do
provider_class.stubs(:get_macosx_version_major).returns("10.6")
@provider.stubs(:plist_from_label).returns(["foo", {"Disabled" => true}])
- Plist.stubs(:parse_xml).returns({@resource[:name] => {"Disabled" => false}})
+ @provider.class.stubs(:read_plist).returns({@resource[:name] => {"Disabled" => false}})
+ FileTest.expects(:file?).with(Launchd_Overrides).returns(true)
@provider.enabled?.should == :true
end
it "should return false if the job plist says disabled is false and the global overrides says disabled is true" do
provider_class.stubs(:get_macosx_version_major).returns("10.6")
@provider.stubs(:plist_from_label).returns(["foo", {"Disabled" => false}])
- Plist.stubs(:parse_xml).returns({@resource[:name] => {"Disabled" => true}})
+ @provider.class.stubs(:read_plist).returns({@resource[:name] => {"Disabled" => true}})
+ FileTest.expects(:file?).with(Launchd_Overrides).returns(true)
@provider.enabled?.should == :false
end
it "should return true if the job plist and the global overrides have no disabled keys" do
provider_class.stubs(:get_macosx_version_major).returns("10.6")
@provider.stubs(:plist_from_label).returns(["foo", {}])
- Plist.stubs(:parse_xml).returns({})
+ @provider.class.stubs(:read_plist).returns({})
+ FileTest.expects(:file?).with(Launchd_Overrides).returns(true)
@provider.enabled?.should == :true
end
end
@@ -182,7 +185,7 @@ describe provider_class do
describe "when enabling the service on OS X 10.6" do
it "should write to the global launchd overrides file once" do
provider_class.stubs(:get_macosx_version_major).returns("10.6")
- Plist.stubs(:parse_xml).returns({})
+ @provider.class.stubs(:read_plist).returns({})
Plist::Emit.expects(:save_plist).once
@provider.enable
end
@@ -191,7 +194,7 @@ describe provider_class do
describe "when disabling the service on OS X 10.6" do
it "should write to the global launchd overrides file once" do
provider_class.stubs(:get_macosx_version_major).returns("10.6")
- Plist.stubs(:parse_xml).returns({})
+ @provider.class.stubs(:read_plist).returns({})
Plist::Emit.expects(:save_plist).once
@provider.enable
end
diff --git a/spec/unit/provider/user/user_role_add_spec.rb b/spec/unit/provider/user/user_role_add_spec.rb
index 211f4260a..b3244f19d 100644
--- a/spec/unit/provider/user/user_role_add_spec.rb
+++ b/spec/unit/provider/user/user_role_add_spec.rb
@@ -56,7 +56,7 @@ describe provider_class do
it "should use the add command when the user is not a role" do
@provider.stubs(:is_role?).returns(false)
@provider.expects(:addcmd).returns("useradd")
- @provider.expects(:run)
+ @provider.expects(:run).at_least_once
@provider.create
end
@@ -66,6 +66,15 @@ describe provider_class do
@provider.expects(:run)
@provider.create
end
+
+ it "should set password age rules" do
+ @resource = Puppet::Type.type(:user).new :name => "myuser", :password_min_age => 5, :password_max_age => 10, :provider => :user_role_add
+ @provider = provider_class.new(@resource)
+ @provider.stubs(:user_attributes)
+ @provider.stubs(:execute)
+ @provider.expects(:execute).with { |cmd, *args| args == ["-m", 5, "-M", 10, "myuser"] }
+ @provider.create
+ end
end
describe "when calling destroy" do
@@ -107,6 +116,7 @@ describe provider_class do
before do
@resource.expects(:allowdupe?).returns true
@provider.stubs(:is_role?).returns(false)
+ @provider.stubs(:execute)
@provider.expects(:execute).with { |args| args.include?("-o") }
end
@@ -246,4 +256,11 @@ describe provider_class do
@provider.password=("hashedpassword")
end
end
+
+ describe "#shadow_entry" do
+ it "should return the line for the right user" do
+ File.stubs(:readlines).returns(["someuser:!:10:5:20:7:1::\n", "fakeval:*:20:10:30:7:2::\n", "testuser:*:30:15:40:7:3::\n"])
+ @provider.shadow_entry.should == ["fakeval", "*", "20", "10", "30", "7", "2"]
+ end
+ end
end
diff --git a/spec/unit/provider/user/useradd_spec.rb b/spec/unit/provider/user/useradd_spec.rb
index 6eb9717b8..26367c584 100755
--- a/spec/unit/provider/user/useradd_spec.rb
+++ b/spec/unit/provider/user/useradd_spec.rb
@@ -15,6 +15,7 @@ describe provider_class do
# #1360
it "should add -o when allowdupe is enabled and the user is being created" do
@resource.expects(:allowdupe?).returns true
+ @provider.stubs(:execute)
@provider.expects(:execute).with { |args| args.include?("-o") }
@provider.create
end
@@ -26,6 +27,15 @@ describe provider_class do
@provider.uid = 150
end
+ it "should set password age rules" do
+ provider_class.has_feature :manages_password_age
+ @resource = Puppet::Type.type(:user).new :name => "myuser", :password_min_age => 5, :password_max_age => 10, :provider => :useradd
+ @provider = provider_class.new(@resource)
+ @provider.stubs(:execute)
+ @provider.expects(:execute).with { |cmd, *args| args == ["-m", 5, "-M", 10, "myuser"] }
+ @provider.create
+ end
+
describe "when checking to add allow dup" do
it "should check allow dup" do
@resource.expects(:allowdupe?)
@@ -109,6 +119,15 @@ describe provider_class do
@provider.stubs(:command).with(:add).returns("useradd")
@provider.stubs(:add_properties).returns(["-G", "somegroup"])
@resource.stubs(:[]).with(:name).returns("someuser")
+ @resource.stubs(:[]).with(:expiry).returns("somedate")
+ @provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", '-e somedate', "someuser"]
+ end
+
+ it "should return an array without -e if expery is undefined full command" do
+ @provider.stubs(:command).with(:add).returns("useradd")
+ @provider.stubs(:add_properties).returns(["-G", "somegroup"])
+ @resource.stubs(:[]).with(:name).returns("someuser")
+ @resource.stubs(:[]).with(:expiry).returns nil
@provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", "someuser"]
end
end
diff --git a/spec/unit/rails_spec.rb b/spec/unit/rails_spec.rb
index eaa968099..01e822ff3 100755
--- a/spec/unit/rails_spec.rb
+++ b/spec/unit/rails_spec.rb
@@ -47,14 +47,20 @@ describe Puppet::Rails, "when initializing any connection" do
Puppet::Rails.connect
end
- describe "on ActiveRecord 2.1.x" do
- confine("ActiveRecord 2.1.x") { ::ActiveRecord::VERSION::MAJOR == 2 and ::ActiveRecord::VERSION::MINOR <= 1 }
-
- it "should set ActiveRecord::Base.allow_concurrency" do
+ describe "ActiveRecord Version" do
+ it "should set ActiveRecord::Base.allow_concurrency if ActiveRecord is 2.1" do
+ Puppet::Util.stubs(:activerecord_version).returns(2.1)
ActiveRecord::Base.expects(:allow_concurrency=).with(true)
Puppet::Rails.connect
end
+
+ it "should not set ActiveRecord::Base.allow_concurrency if ActiveRecord is >= 2.2" do
+ Puppet::Util.stubs(:activerecord_version).returns(2.2)
+ ActiveRecord::Base.expects(:allow_concurrency=).never
+
+ Puppet::Rails.connect
+ end
end
it "should call ActiveRecord::Base.verify_active_connections!" do
diff --git a/spec/unit/reports/rrdgraph_spec.rb b/spec/unit/reports/rrdgraph_spec.rb
new file mode 100644
index 000000000..ce2cf7905
--- /dev/null
+++ b/spec/unit/reports/rrdgraph_spec.rb
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+require 'puppet/reports'
+
+processor = Puppet::Reports.report(:rrdgraph)
+
+describe processor do
+ include PuppetSpec::Files
+ before do
+ Puppet[:rrddir] = tmpdir('rrdgraph')
+ Puppet.settings.use :master
+ end
+
+ after do
+ FileUtils.rm_rf(Puppet[:rrddir])
+ end
+
+ it "should not error on 0.25.x report format" do
+ report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report0.25.x.yaml')).extend processor
+ report.expects(:mkhtml)
+ lambda{ report.process }.should_not raise_error
+ end
+
+ it "should not error on 2.6.x report format" do
+ report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report2.6.x.yaml')).extend processor
+ report.expects(:mkhtml)
+ lambda{ report.process }.should_not raise_error
+ end
+end
diff --git a/spec/unit/reports/tagmail_spec.rb b/spec/unit/reports/tagmail_spec.rb
index 59cb5b2b8..bdb16600e 100755
--- a/spec/unit/reports/tagmail_spec.rb
+++ b/spec/unit/reports/tagmail_spec.rb
@@ -31,6 +31,7 @@ describe tagmail do
{
"tag: abuse@domain.com" => [%w{abuse@domain.com}, %w{tag}, []],
+ "tag.localhost: abuse@domain.com" => [%w{abuse@domain.com}, %w{tag.localhost}, []],
"tag, other: abuse@domain.com" => [%w{abuse@domain.com}, %w{tag other}, []],
"tag-other: abuse@domain.com" => [%w{abuse@domain.com}, %w{tag-other}, []],
"tag, !other: abuse@domain.com" => [%w{abuse@domain.com}, %w{tag}, %w{other}],
diff --git a/spec/unit/sslcertificates/ca_spec.rb b/spec/unit/sslcertificates/ca_spec.rb
new file mode 100644
index 000000000..b1393b25d
--- /dev/null
+++ b/spec/unit/sslcertificates/ca_spec.rb
@@ -0,0 +1,110 @@
+#!/usr/bin/env ruby
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet'
+require 'puppet/sslcertificates'
+require 'puppet/sslcertificates/ca'
+
+describe Puppet::SSLCertificates::CA do
+ before :all do
+ @hosts = %w{host.domain.com Other.Testing.Com}
+ end
+
+ before :each do
+ Puppet::Util::SUIDManager.stubs(:asuser).yields
+ file = Tempfile.new("ca_testing")
+ @dir = file.path
+ file.delete
+
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
+
+ @ca = Puppet::SSLCertificates::CA.new
+ end
+
+ after :each do
+ system("rm -rf #{@dir}")
+ end
+
+ describe 'when cleaning' do
+ it 'should remove associated files' do
+ dirs = [:csrdir, :signeddir, :publickeydir, :privatekeydir, :certdir]
+
+ @hosts.each do |host|
+ files = []
+ dirs.each do |dir|
+ dir = Puppet[dir]
+
+ # Case insensitivity is handled through downcasing
+ file = File.join(dir, host.downcase + '.pem')
+
+ File.open(file, "w") do |f|
+ f.puts "testing"
+ end
+
+ files << file
+ end
+
+ lambda { @ca.clean(host) }.should_not raise_error
+
+ files.reject {|f| ! File.exists?(f)}.should be_empty
+ end
+ end
+ end
+
+ describe 'when mapping hosts to files' do
+ it 'should correctly return the certfile' do
+ @hosts.each do |host|
+ value = nil
+ lambda { value = @ca.host2certfile host }.should_not raise_error
+
+ File.join(Puppet[:signeddir], host.downcase + '.pem').should == value
+ end
+ end
+
+ it 'should correctly return the csrfile' do
+ @hosts.each do |host|
+ value = nil
+ lambda { value = @ca.host2csrfile host }.should_not raise_error
+
+ File.join(Puppet[:csrdir], host.downcase + '.pem').should == value
+ end
+ end
+ end
+
+ describe 'when listing' do
+ it 'should find all csr' do
+ list = []
+
+ # Make some fake CSRs
+ @hosts.each do |host|
+ file = File.join(Puppet[:csrdir], host.downcase + '.pem')
+ File.open(file, 'w') { |f| f.puts "yay" }
+ list << host.downcase
+ end
+
+ @ca.list.sort.should == list.sort
+ end
+ end
+
+ describe 'when creating a root certificate' do
+ before :each do
+ lambda { @ca.mkrootcert }.should_not raise_exception
+ end
+
+ it 'should store the public key' do
+ File.exists?(Puppet[:capub]).should be_true
+ end
+
+ it 'should prepend "Puppet CA: " to the fqdn as the ca_name by default' do
+ host_mock_fact = mock()
+ host_mock_fact.expects(:value).returns('myhost')
+ domain_mock_fact = mock()
+ domain_mock_fact.expects(:value).returns('puppetlabs.lan')
+ Facter.stubs(:[]).with('hostname').returns(host_mock_fact)
+ Facter.stubs(:[]).with('domain').returns(domain_mock_fact)
+
+ @ca.mkrootcert.name.should == 'Puppet CA: myhost.puppetlabs.lan'
+ end
+ end
+end
diff --git a/spec/unit/type/user_spec.rb b/spec/unit/type/user_spec.rb
index 4c6eb1150..ccea9ee4c 100755
--- a/spec/unit/type/user_spec.rb
+++ b/spec/unit/type/user_spec.rb
@@ -35,6 +35,14 @@ describe user do
user.provider_feature(:manages_solaris_rbac).should_not be_nil
end
+ it "should have a manages_expiry feature" do
+ user.provider_feature(:manages_expiry).should_not be_nil
+ end
+
+ it "should have a manages_password_age feature" do
+ user.provider_feature(:manages_password_age).should_not be_nil
+ end
+
describe "instances" do
it "should have a valid provider" do
user.new(:name => "foo").provider.class.ancestors.should be_include(Puppet::Provider)
@@ -47,7 +55,7 @@ describe user do
end
end
- properties = [:ensure, :uid, :gid, :home, :comment, :shell, :password, :groups, :roles, :auths, :profiles, :project, :keys]
+ properties = [:ensure, :uid, :gid, :home, :comment, :shell, :password, :password_min_age, :password_max_age, :groups, :roles, :auths, :profiles, :project, :keys, :expiry]
properties.each do |property|
it "should have a #{property} property" do
@@ -227,6 +235,16 @@ describe user do
end
end
+ describe "when managing expiry" do
+ before do
+ @expiry = user.attrclass(:expiry).new(:resource => @resource)
+ end
+
+ it "should fail if given an invalid date" do
+ lambda { @expiry.should = "200-20-20" }.should raise_error(Puppet::Error)
+ end
+ end
+
describe "when managing passwords" do
before do
@password = user.attrclass(:password).new(:resource => @resource, :should => "mypass")
diff --git a/spec/unit/type/whit_spec.rb b/spec/unit/type/whit_spec.rb
new file mode 100644
index 000000000..998d9df30
--- /dev/null
+++ b/spec/unit/type/whit_spec.rb
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+whit = Puppet::Type.type(:whit).new(:name => "Foo::Bar")
+
+describe whit do
+ it "should stringify as though it were the class it represents" do
+ whit.to_s.should == "Class[Foo::Bar]"
+ end
+end
diff --git a/spec/unit/type_spec.rb b/spec/unit/type_spec.rb
index 487750e52..48b00ec4a 100755
--- a/spec/unit/type_spec.rb
+++ b/spec/unit/type_spec.rb
@@ -545,6 +545,13 @@ describe Puppet::Type.metaparamclass(:audit) do
@resource[:audit].should == list
end
+ it "should accept the string 'all' to specify auditing all possible properties" do
+ @resource[:audit] = 'all'
+
+ list = @resource.class.properties.collect { |p| p.name }
+ @resource[:audit].should == list
+ end
+
it "should fail if asked to audit an invalid property" do
lambda { @resource[:audit] = :foobar }.should raise_error(Puppet::Error)
end
diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb
index 79195e657..28c33c295 100755
--- a/spec/unit/util/rdoc/parser_spec.rb
+++ b/spec/unit/util/rdoc/parser_spec.rb
@@ -19,7 +19,7 @@ describe RDoc::Parser do
it "should parse puppet files with the puppet parser" do
@parser.stubs(:scan_top_level)
parser = stub 'parser'
- Puppet::Parser::Parser.expects(:new).returns(parser)
+ Puppet::Parser::Parser.stubs(:new).returns(parser)
parser.expects(:parse)
parser.expects(:file=).with("module/manifests/init.pp")
@@ -340,10 +340,12 @@ describe RDoc::Parser do
def create_stmt(name)
stmt_value = stub "#{name}_value", :value => "myclass"
- stmt = stub_everything 'stmt', :name => name, :arguments => [stmt_value], :doc => "mydoc"
- stmt.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(false)
- stmt.stubs(:is_a?).with(Puppet::Parser::AST::Function).returns(true)
- stmt
+
+ Puppet::Parser::AST::Function.new(
+ :name => name,
+ :arguments => [stmt_value],
+ :doc => 'mydoc'
+ )
end
before(:each) do
@@ -377,10 +379,11 @@ describe RDoc::Parser do
def create_stmt
stmt_value = stub "resource_ref", :to_s => "File[\"/tmp/a\"]"
- stmt = stub_everything 'stmt', :name => "realize", :arguments => [stmt_value], :doc => "mydoc"
- stmt.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(false)
- stmt.stubs(:is_a?).with(Puppet::Parser::AST::Function).returns(true)
- stmt
+ Puppet::Parser::AST::Function.new(
+ :name => 'realize',
+ :arguments => [stmt_value],
+ :doc => 'mydoc'
+ )
end
before(:each) do
@@ -432,11 +435,12 @@ describe RDoc::Parser do
describe "when scanning for resources" do
before :each do
@class = stub_everything 'class'
-
- param = stub 'params', :children => []
- @stmt = stub_everything 'stmt', :type => "File", :title => "myfile", :doc => "mydoc", :params => param
- @stmt.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(false)
- @stmt.stubs(:is_a?).with(Puppet::Parser::AST::Resource).returns(true)
+ @stmt = Puppet::Parser::AST::Resource.new(
+ :type => "File",
+ :title => "myfile",
+ :doc => 'mydoc',
+ :parameters => Puppet::Parser::AST::ASTArray.new(:children => [])
+ )
@code = stub_everything 'code'
@code.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(true)
diff --git a/spec/unit/util/zaml_spec.rb b/spec/unit/util/zaml_spec.rb
index 4de57e6d3..f2bcefe01 100644..100755
--- a/spec/unit/util/zaml_spec.rb
+++ b/spec/unit/util/zaml_spec.rb
@@ -11,7 +11,8 @@ describe "Pure ruby yaml implementation" do
'test' => "--- test",
[] => "--- []",
:symbol => "--- !ruby/sym symbol",
- {:a => "A"} => "--- \n !ruby/sym a: A"
+ {:a => "A"} => "--- \n !ruby/sym a: A",
+ {:a => "x\ny"} => "--- \n !ruby/sym a: |-\n x\n y"
}.each { |o,y|
it "should convert the #{o.class} #{o.inspect} to yaml" do
o.to_yaml.should == y