summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorMax Martin <max@puppetlabs.com>2011-06-02 15:56:22 -0700
committerMax Martin <max@puppetlabs.com>2011-06-02 15:56:22 -0700
commit4801e10c81264b20c2d35b0d44c10cfb0668d1b9 (patch)
tree3e3024bbd4a46a3ab2af5bf29ec2f3b30db270d7 /spec/unit
parent520cbc0292ec0cf75b6871bb0a4bc12bce506bb0 (diff)
parent4ad88017d3b8b8000325f5165520a6c21b48c469 (diff)
downloadpuppet-4801e10c81264b20c2d35b0d44c10cfb0668d1b9.tar.gz
puppet-4801e10c81264b20c2d35b0d44c10cfb0668d1b9.tar.xz
puppet-4801e10c81264b20c2d35b0d44c10cfb0668d1b9.zip
Merge branch '2.7.x'
* 2.7.x: (40 commits) (#7746) Fix bootstrap issues from #7717 fix. (#7683) Use ronn, when available, to render the output. (#7683) Add a 'man' face and subcommand to Puppet. maint: remove obsolete work-around code from help face. (#7699) Don't duplicate inherited action names on faces. (#7177) Deprecate implicit 'puppet apply' for 2.7.0 (#7717) Layout cleanup for subcommand extraction. #7211: Test unknown options don't shadow unknown actions. #7211: nasty logic error with global Face options taking arguments. #7211: more helpful error messages in various cases. maint: Fix order dependent test failure (#5966) Add support for hostname regular expressions in auth.conf (#7708) Delete extended documentation from configuration reference (#7707) Document signals in puppet agent and puppet master help add puppet master polling step for ticket 7117 (#5318) Always notice changes to manifests when compiling. (#5318) Always notice changes to manifests when compiling. (#7557) Remove Faces Application maint: Fix order dependent spec failure for face indirection (#7690) Don't blow up when listing terminuses available for faces ... Conflicts (resolved manually): acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/application/face_base_spec.rb36
-rwxr-xr-xspec/unit/application/faces_spec.rb14
-rwxr-xr-xspec/unit/application/indirection_base_spec.rb3
-rwxr-xr-xspec/unit/indirector/terminus_spec.rb6
-rwxr-xr-xspec/unit/interface/action_manager_spec.rb50
-rwxr-xr-xspec/unit/network/authstore_spec.rb40
-rwxr-xr-xspec/unit/parser/ast/resource_reference_spec.rb24
-rwxr-xr-xspec/unit/util/autoload_spec.rb4
8 files changed, 135 insertions, 42 deletions
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb
index 3318e061e..0a4a86be6 100755
--- a/spec/unit/application/face_base_spec.rb
+++ b/spec/unit/application/face_base_spec.rb
@@ -52,6 +52,12 @@ describe Puppet::Application::FaceBase do
end
end
+ it "should stop if the first thing found is not an action" do
+ app.command_line.stubs(:args).returns %w{banana count_args}
+ expect { app.run }.to exit_with 1
+ @logs.first.message.should =~ /has no 'banana' action/
+ end
+
it "should use the default action if not given any arguments" do
app.command_line.stubs(:args).returns []
action = stub(:options => [], :render_as => nil)
@@ -77,7 +83,29 @@ describe Puppet::Application::FaceBase do
Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(nil)
app.stubs(:main)
expect { app.run }.to exit_with 1
- @logs.first.message.should =~ /does not have a default action/
+ @logs.first.message.should =~ /has no 'bar' action./
+ end
+
+ [%w{something_I_cannot_do},
+ %w{something_I_cannot_do argument}].each do |input|
+ it "should report unknown actions nicely" do
+ app.command_line.stubs(:args).returns input
+ Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(nil)
+ app.stubs(:main)
+ expect { app.run }.to exit_with 1
+ @logs.first.message.should =~ /has no 'something_I_cannot_do' action/
+ end
+ end
+
+ [%w{something_I_cannot_do --unknown-option},
+ %w{something_I_cannot_do argument --unknown-option}].each do |input|
+ it "should report unknown actions even if there are unknown options" do
+ app.command_line.stubs(:args).returns input
+ Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(nil)
+ app.stubs(:main)
+ expect { app.run }.to exit_with 1
+ @logs.first.message.should =~ /has no 'something_I_cannot_do' action/
+ end
end
it "should report a sensible error when options with = fail" do
@@ -149,7 +177,7 @@ describe Puppet::Application::FaceBase do
end
it "should handle application-level options", :'fails_on_ruby_1.9.2' => true do
- app.command_line.stubs(:args).returns %w{basetest --verbose return_true}
+ app.command_line.stubs(:args).returns %w{--verbose return_true}
app.preinit
app.parse_options
app.face.name.should == :basetest
@@ -304,7 +332,7 @@ EOT
end
it "should fail early if asked to render an invalid format" do
- app.command_line.stubs(:args).returns %w{--render-as interpretive-dance help help}
+ app.command_line.stubs(:args).returns %w{--render-as interpretive-dance return_true}
# We shouldn't get here, thanks to the exception, and our expectation on
# it, but this helps us fail if that slips up and all. --daniel 2011-04-27
Puppet::Face[:help, :current].expects(:help).never
@@ -315,7 +343,7 @@ EOT
end
it "should work if asked to render a NetworkHandler format" do
- app.command_line.stubs(:args).returns %w{dummy find dummy --render-as yaml}
+ app.command_line.stubs(:args).returns %w{count_args a b c --render-as yaml}
expect {
expect { app.run }.to exit_with 0
}.to have_printed(/--- 3/)
diff --git a/spec/unit/application/faces_spec.rb b/spec/unit/application/faces_spec.rb
deleted file mode 100755
index cc159b6a5..000000000
--- a/spec/unit/application/faces_spec.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/env rspec
-require 'spec_helper'
-require 'puppet/application/faces'
-
-describe Puppet::Application::Faces do
- it "should be an application" do
- Puppet::Application::Faces.superclass.should equal(Puppet::Application)
- end
-
- it "should always call 'list'" do
- subject.expects(:list)
- subject.main
- end
-end
diff --git a/spec/unit/application/indirection_base_spec.rb b/spec/unit/application/indirection_base_spec.rb
index d72def6cf..8a5eee2c6 100755
--- a/spec/unit/application/indirection_base_spec.rb
+++ b/spec/unit/application/indirection_base_spec.rb
@@ -19,7 +19,6 @@ face.instance_variable_set('@version', :current)
Puppet::Face.register(face)
########################################################################
-
describe Puppet::Application::IndirectionBase do
subject { Puppet::Application::TestIndirection.new }
@@ -27,6 +26,8 @@ describe Puppet::Application::IndirectionBase do
# It would be nice not to have to stub this, but whatever... writing an
# entire indirection stack would cause us more grief. --daniel 2011-03-31
terminus = stub_everything("test indirection terminus")
+ terminus.stubs(:name).returns(:testindirection)
+
Puppet::Indirector::Indirection.expects(:instance).
with(:testindirection).returns(terminus)
diff --git a/spec/unit/indirector/terminus_spec.rb b/spec/unit/indirector/terminus_spec.rb
index 33932cfca..2f37c1ff5 100755
--- a/spec/unit/indirector/terminus_spec.rb
+++ b/spec/unit/indirector/terminus_spec.rb
@@ -242,3 +242,9 @@ describe Puppet::Indirector::Terminus, " when creating terminus class types", :'
end
end
+describe Puppet::Indirector::Terminus, " when listing terminus classes" do
+ it "should list the terminus files available to load" do
+ Puppet::Util::Autoload.any_instance.stubs(:files_to_load).returns ["/foo/bar/baz", "/max/runs/marathon"]
+ Puppet::Indirector::Terminus.terminus_classes('my_stuff').should == [:baz, :marathon]
+ end
+end
diff --git a/spec/unit/interface/action_manager_spec.rb b/spec/unit/interface/action_manager_spec.rb
index e357a5fa1..3a84e4f83 100755
--- a/spec/unit/interface/action_manager_spec.rb
+++ b/spec/unit/interface/action_manager_spec.rb
@@ -186,23 +186,49 @@ describe Puppet::Interface::ActionManager do
@instance.should be_action(:foo)
end
- it "should list actions defined in superclasses" do
- @subclass = Class.new(@klass)
- @instance = @subclass.new
+ context "with actions defined in superclass" do
+ before :each do
+ @subclass = Class.new(@klass)
+ @instance = @subclass.new
+
+ @klass.action(:parent) do
+ when_invoked { |options| "a" }
+ end
+ @subclass.action(:sub) do
+ when_invoked { |options| "a" }
+ end
+ @instance.action(:instance) do
+ when_invoked { |options| "a" }
+ end
+ end
+
+ it "should list actions defined in superclasses" do
+ @instance.should be_action(:parent)
+ @instance.should be_action(:sub)
+ @instance.should be_action(:instance)
+ end
- @klass.action(:parent) do
- when_invoked { |options| "a" }
+ it "should list inherited actions" do
+ @instance.actions.should =~ [:instance, :parent, :sub]
end
- @subclass.action(:sub) do
- when_invoked { |options| "a" }
+
+ it "should not duplicate instance actions after fetching them (#7699)" do
+ @instance.actions.should =~ [:instance, :parent, :sub]
+ @instance.get_action(:instance)
+ @instance.actions.should =~ [:instance, :parent, :sub]
end
- @instance.action(:instance) do
- when_invoked { |options| "a" }
+
+ it "should not duplicate subclass actions after fetching them (#7699)" do
+ @instance.actions.should =~ [:instance, :parent, :sub]
+ @instance.get_action(:sub)
+ @instance.actions.should =~ [:instance, :parent, :sub]
end
- @instance.should be_action(:parent)
- @instance.should be_action(:sub)
- @instance.should be_action(:instance)
+ it "should not duplicate superclass actions after fetching them (#7699)" do
+ @instance.actions.should =~ [:instance, :parent, :sub]
+ @instance.get_action(:parent)
+ @instance.actions.should =~ [:instance, :parent, :sub]
+ end
end
it "should create an instance method when an action is defined in a superclass" do
diff --git a/spec/unit/network/authstore_spec.rb b/spec/unit/network/authstore_spec.rb
index d62c8abaa..32ce1930f 100755
--- a/spec/unit/network/authstore_spec.rb
+++ b/spec/unit/network/authstore_spec.rb
@@ -4,11 +4,12 @@ require 'spec_helper'
require 'puppet/network/authconfig'
describe Puppet::Network::AuthStore do
- describe "when checking if the acl has some entries" do
- before :each do
- @authstore = Puppet::Network::AuthStore.new
- end
+ before :each do
+ @authstore = Puppet::Network::AuthStore.new
+ @authstore.reset_interpolation
+ end
+ describe "when checking if the acl has some entries" do
it "should be empty if no ACE have been entered" do
@authstore.should be_empty
end
@@ -31,6 +32,37 @@ describe Puppet::Network::AuthStore do
@authstore.should_not be_empty
end
end
+
+ describe "when checking global allow" do
+ it "should not be enabled by default" do
+ @authstore.should_not be_globalallow
+ @authstore.should_not be_allowed('foo.bar.com', '192.168.1.1')
+ end
+
+ it "should always allow when enabled" do
+ @authstore.allow('*')
+
+ @authstore.should be_globalallow
+ @authstore.should be_allowed('foo.bar.com', '192.168.1.1')
+ end
+ end
+
+ describe "when checking a regex type of allow" do
+ before :each do
+ @authstore.allow('/^(test-)?host[0-9]+\.other-domain\.(com|org|net)$|some-domain\.com/')
+ @ip = '192.168.1.1'
+ end
+ ['host5.other-domain.com', 'test-host12.other-domain.net', 'foo.some-domain.com'].each { |name|
+ it "should allow the host #{name}" do
+ @authstore.should be_allowed(name, @ip)
+ end
+ }
+ ['host0.some-other-domain.com',''].each { |name|
+ it "should not allow the host #{name}" do
+ @authstore.should_not be_allowed(name, @ip)
+ end
+ }
+ end
end
describe Puppet::Network::AuthStore::Declaration do
diff --git a/spec/unit/parser/ast/resource_reference_spec.rb b/spec/unit/parser/ast/resource_reference_spec.rb
index 627754dd1..4d1c191cf 100755
--- a/spec/unit/parser/ast/resource_reference_spec.rb
+++ b/spec/unit/parser/ast/resource_reference_spec.rb
@@ -9,21 +9,25 @@ describe Puppet::Parser::AST::ResourceReference do
@scope = Puppet::Parser::Scope.new
end
+ def ast_name(value)
+ Puppet::Parser::AST::Name.new(:value => value)
+ end
+
def newref(type, title)
- title = stub 'title', :safeevaluate => title
- ref = Puppet::Parser::AST::ResourceReference.new(:type => type, :title => title)
+ title_array = Puppet::Parser::AST::ASTArray.new(:children => [title])
+ ref = Puppet::Parser::AST::ResourceReference.new(:type => type, :title => title_array)
end
it "should correctly produce reference strings" do
- newref("File", "/tmp/yay").evaluate(@scope).to_s.should == "File[/tmp/yay]"
+ newref("File", ast_name("/tmp/yay")).evaluate(@scope).to_s.should == "File[/tmp/yay]"
end
it "should produce a single resource when the title evaluates to a string" do
- newref("File", "/tmp/yay").evaluate(@scope).should == Puppet::Resource.new("file", "/tmp/yay")
+ newref("File", ast_name("/tmp/yay")).evaluate(@scope).should == Puppet::Resource.new("file", "/tmp/yay")
end
it "should return an array of resources if given an array of titles" do
- titles = mock 'titles', :safeevaluate => ["title1","title2"]
+ titles = Puppet::Parser::AST::ASTArray.new(:children => [ast_name("title1"), ast_name("title2")])
ref = ast::ResourceReference.new( :title => titles, :type => "File" )
ref.evaluate(@scope).should == [
Puppet::Resource.new("file", "title1"),
@@ -31,6 +35,16 @@ describe Puppet::Parser::AST::ResourceReference do
]
end
+ it "should return an array of resources if given a variable containing an array of titles" do
+ @scope.setvar("my_files", ["foo", "bar"])
+ titles = Puppet::Parser::AST::Variable.new(:value => "my_files")
+ ref = newref('File', titles)
+ ref.evaluate(@scope).should == [
+ Puppet::Resource.new("file", "foo"),
+ Puppet::Resource.new("file", "bar")
+ ]
+ end
+
it "should return a correct representation when converting to string" do
type = stub 'type', :is_a? => true, :to_s => "file"
title = stub 'title', :is_a? => true, :to_s => "[/tmp/a, /tmp/b]"
diff --git a/spec/unit/util/autoload_spec.rb b/spec/unit/util/autoload_spec.rb
index 512f06c75..d61b7689e 100755
--- a/spec/unit/util/autoload_spec.rb
+++ b/spec/unit/util/autoload_spec.rb
@@ -51,9 +51,9 @@ describe Puppet::Util::Autoload do
@autoload.search_directories.should == %w{/one /two /libdir1 /lib/dir/two /third/lib/dir} + $LOAD_PATH
end
- it "should include in its search path all of the search directories that have a subdirectory matching the autoload path" do
+ it "should include in its search path all of the unique search directories that have a subdirectory matching the autoload path" do
@autoload = Puppet::Util::Autoload.new("foo", "loaddir")
- @autoload.expects(:search_directories).returns %w{/one /two /three}
+ @autoload.expects(:search_directories).returns %w{/one /two /three /three}
FileTest.expects(:directory?).with("/one/loaddir").returns true
FileTest.expects(:directory?).with("/two/loaddir").returns false
FileTest.expects(:directory?).with("/three/loaddir").returns true