diff options
| author | Max Martin <max@puppetlabs.com> | 2011-04-27 13:27:40 -0700 |
|---|---|---|
| committer | Max Martin <max@puppetlabs.com> | 2011-04-27 13:27:40 -0700 |
| commit | 68c82d4d8b75ebd8f0ab61b37ba78cf5fbc52081 (patch) | |
| tree | d3f136373e6a10819975fa1ec0a931c1eb4afb37 /spec/unit | |
| parent | 32b13dad06195b37f0e10d13c6d2a9d958be00a7 (diff) | |
| parent | 1b12b55b6a2d3581f9643bf09d55727ba1213580 (diff) | |
| download | puppet-68c82d4d8b75ebd8f0ab61b37ba78cf5fbc52081.tar.gz puppet-68c82d4d8b75ebd8f0ab61b37ba78cf5fbc52081.tar.xz puppet-68c82d4d8b75ebd8f0ab61b37ba78cf5fbc52081.zip | |
Merge branch '2.7.next' into next
* 2.7.next:
(#3420) Nagios "name" attribute does not output correctly
(#4487) When setting environment on a host, ensure it is a string.
add test for ticket 7101
(#7220) Add the ability to "inherit" options.
(#6487) Add some testing for OS X version support in DirectoryService provider
(#6487) Directoryservice provider will fail in future OS releases
(#6368) Make the File type autorequire its nearest ancestor directory
Diffstat (limited to 'spec/unit')
| -rwxr-xr-x | spec/unit/interface/action_builder_spec.rb | 55 | ||||
| -rwxr-xr-x | spec/unit/interface/action_spec.rb | 55 | ||||
| -rwxr-xr-x | spec/unit/provider/nameservice/directoryservice_spec.rb | 60 | ||||
| -rwxr-xr-x | spec/unit/rails/host_spec.rb | 8 | ||||
| -rwxr-xr-x | spec/unit/type/file_spec.rb | 57 |
5 files changed, 235 insertions, 0 deletions
diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb index bf7afa74e..6f36d2b44 100755 --- a/spec/unit/interface/action_builder_spec.rb +++ b/spec/unit/interface/action_builder_spec.rb @@ -52,6 +52,61 @@ describe Puppet::Interface::ActionBuilder do end end + describe "#inherit_options_from" do + let :face do + Puppet::Interface.new(:face_with_some_options, '0.0.1') do + option '-w' + + action(:foo) do + option '-x', '--ex' + option '-y', '--why' + end + + action(:bar) do + option '-z', '--zee' + end + + action(:baz) do + option '-z', '--zed' + end + end + end + + it 'should add the options from the specified action' do + foo = face.get_action(:foo) + action = Puppet::Interface::ActionBuilder.build(face, :inherit_options) do + inherit_options_from foo + end + action.options.should == foo.options + end + + it 'should add the options from multiple actions' do + foo = face.get_action(:foo) + bar = face.get_action(:bar) + action = Puppet::Interface::ActionBuilder.build(face, :inherit_options) do + inherit_options_from foo + inherit_options_from bar + end + action.options.should == (foo.options + bar.options).uniq.sort + end + + it 'should permit symbolic names for actions in the same face' do + foo = face.get_action(:foo) + action = Puppet::Interface::ActionBuilder.build(face, :inherit_options) do + inherit_options_from :foo + end + action.options.should == foo.options + end + + it 'should raise a useful error if you supply a bad action name' do + expect do + Puppet::Interface::ActionBuilder.build(face, :inherit_options) do + inherit_options_from :nowhere + end + end.to raise_error /nowhere/ + end + end + context "inline documentation" do it "should set the summary" do action = Puppet::Interface::ActionBuilder.build(face, :foo) do diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb index 24826a6ef..735fbcb72 100755 --- a/spec/unit/interface/action_spec.rb +++ b/spec/unit/interface/action_spec.rb @@ -68,6 +68,61 @@ describe Puppet::Interface::Action do end end + describe "#inherit_options_from" do + let :face do + Puppet::Interface.new(:face_with_some_options, '0.0.1') do + option '-w' + + action(:foo) do + option '-x', '--ex' + option '-y', '--why' + end + + action(:bar) do + option '-z', '--zee' + end + + action(:baz) do + option '-z', '--zed' + end + + action(:noopts) do + # no options declared + end + end + end + + subject { action = face.action(:new_action) { } } + + it 'should add the options from the specified action' do + subject.inherit_options_from(foo = face.get_action(:foo)) + subject.options.should == foo.options + end + + it 'should not die when the specified action has no options' do + original_options = subject.options + subject.inherit_options_from(face.get_action(:noopts)) + subject.options.should == original_options + end + + it 'should add the options from multiple actions' do + subject.inherit_options_from(foo = face.get_action(:foo)) + subject.inherit_options_from(bar = face.get_action(:bar)) + subject.options.should == (foo.options + bar.options).uniq.sort + end + + it 'should not inherit face options' do + subject.expects(:add_option) + subject.expects(:add_option).with(face.get_option(:w)).never + subject.inherit_options_from(face.get_action(:bar)) + end + + it 'should raise an error if inheritance would duplicate options' do + subject.inherit_options_from(face.get_action(:bar)) + expect { subject.inherit_options_from(face.get_action(:baz)) }.to raise_error + end + end + describe "when invoking" do it "should be able to call other actions on the same object" do face = Puppet::Interface.new(:my_face, '0.0.1') do diff --git a/spec/unit/provider/nameservice/directoryservice_spec.rb b/spec/unit/provider/nameservice/directoryservice_spec.rb index 47f2ad0cd..7a83d7f20 100755 --- a/spec/unit/provider/nameservice/directoryservice_spec.rb +++ b/spec/unit/provider/nameservice/directoryservice_spec.rb @@ -35,3 +35,63 @@ require 'spec_helper' end end end + +describe 'DirectoryService.single_report' do + it 'should fail on OS X < 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.3") + + lambda { + Puppet::Provider::NameService::DirectoryService.single_report('resource_name') + }.should raise_error(RuntimeError, "Puppet does not support OS X versions < 10.4") + end + + it 'should use url data on 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.4") + Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users') + Puppet::Provider::NameService::DirectoryService.stubs(:list_all_present).returns( + ['root', 'user1', 'user2', 'resource_name'] + ) + Puppet::Provider::NameService::DirectoryService.stubs(:generate_attribute_hash) + Puppet::Provider::NameService::DirectoryService.stubs(:execute) + Puppet::Provider::NameService::DirectoryService.expects(:parse_dscl_url_data) + + Puppet::Provider::NameService::DirectoryService.single_report('resource_name') + end + + it 'should use plist data on > 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.5") + Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users') + Puppet::Provider::NameService::DirectoryService.stubs(:list_all_present).returns( + ['root', 'user1', 'user2', 'resource_name'] + ) + Puppet::Provider::NameService::DirectoryService.stubs(:generate_attribute_hash) + Puppet::Provider::NameService::DirectoryService.stubs(:execute) + Puppet::Provider::NameService::DirectoryService.expects(:parse_dscl_plist_data) + + Puppet::Provider::NameService::DirectoryService.single_report('resource_name') + end +end + +describe 'DirectoryService.get_exec_preamble' do + it 'should fail on OS X < 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.3") + + lambda { + Puppet::Provider::NameService::DirectoryService.get_exec_preamble('-list') + }.should raise_error(RuntimeError, "Puppet does not support OS X versions < 10.4") + end + + it 'should use url data on 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.4") + Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users') + + Puppet::Provider::NameService::DirectoryService.get_exec_preamble('-list').should include("-url") + end + + it 'should use plist data on > 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.5") + Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users') + + Puppet::Provider::NameService::DirectoryService.get_exec_preamble('-list').should include("-plist") + end +end diff --git a/spec/unit/rails/host_spec.rb b/spec/unit/rails/host_spec.rb index df0b2fa1d..98541c0a8 100755 --- a/spec/unit/rails/host_spec.rb +++ b/spec/unit/rails/host_spec.rb @@ -1,6 +1,8 @@ #!/usr/bin/env rspec require 'spec_helper' +require 'puppet/node/environment' + describe "Puppet::Rails::Host", :if => Puppet.features.rails? do def column(name, type) ActiveRecord::ConnectionAdapters::Column.new(name, nil, type, false) @@ -42,6 +44,12 @@ describe "Puppet::Rails::Host", :if => Puppet.features.rails? do Puppet::Rails::Host.from_puppet(@node) end + it "should stringify the environment" do + host = Puppet::Rails::Host.new + host.environment = Puppet::Node::Environment.new("production") + host.environment.class.should == String + end + it "should copy the ipaddress from the Puppet instance" do Puppet::Rails::Host.expects(:find_by_name).with("foo").returns @host diff --git a/spec/unit/type/file_spec.rb b/spec/unit/type/file_spec.rb index 683c3654b..6cd3ab701 100755 --- a/spec/unit/type/file_spec.rb +++ b/spec/unit/type/file_spec.rb @@ -168,6 +168,25 @@ describe Puppet::Type.type(:file) do reqs[0].target.must == file end + it "should autorequire its nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "/foo/bar/baz") + dir = Puppet::Type::File.new(:path => "/foo") + root = Puppet::Type::File.new(:path => "/") + @catalog.add_resource file + @catalog.add_resource dir + @catalog.add_resource root + reqs = file.autorequire + reqs.length.must == 1 + reqs[0].source.must == dir + reqs[0].target.must == file + end + + it "should not autorequire anything when there is no nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "/foo/bar/baz") + @catalog.add_resource file + file.autorequire.should be_empty + end + it "should not autorequire its parent dir if its parent dir is itself" do file = Puppet::Type::File.new(:path => "/") @catalog.add_resource file @@ -241,6 +260,25 @@ describe Puppet::Type.type(:file) do reqs[0].target.must == file end + it "should autorequire its nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "X:/foo/bar/baz") + dir = Puppet::Type::File.new(:path => "X:/foo") + root = Puppet::Type::File.new(:path => "X:/") + @catalog.add_resource file + @catalog.add_resource dir + @catalog.add_resource root + reqs = file.autorequire + reqs.length.must == 1 + reqs[0].source.must == dir + reqs[0].target.must == file + end + + it "should not autorequire anything when there is no nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "X:/foo/bar/baz") + @catalog.add_resource file + file.autorequire.should be_empty + end + it "should not autorequire its parent dir if its parent dir is itself" do file = Puppet::Type::File.new(:path => "X:/") @catalog.add_resource file @@ -302,6 +340,25 @@ describe Puppet::Type.type(:file) do reqs[0].target.must == file end + it "should autorequire its nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux") + dir = Puppet::Type::File.new(:path => "//server/foo/bar") + root = Puppet::Type::File.new(:path => "//server/foo") + @catalog.add_resource file + @catalog.add_resource dir + @catalog.add_resource root + reqs = file.autorequire + reqs.length.must == 1 + reqs[0].source.must == dir + reqs[0].target.must == file + end + + it "should not autorequire anything when there is no nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux") + @catalog.add_resource file + file.autorequire.should be_empty + end + it "should not autorequire its parent dir if its parent dir is itself" do file = Puppet::Type::File.new(:path => "//server/foo") @catalog.add_resource file |
