summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-12-09 15:10:09 -0600
committerLuke Kanies <luke@madstop.com>2008-12-09 15:10:09 -0600
commit71b8befa424c6c82a10a5cc7d7ea50331851c7e9 (patch)
tree0143dc9e61dba7b54ec0b44399b6c9d20ae32767 /spec
parent89e9ef7521f5d62f1eb65514fe8923d0456e6184 (diff)
parente5c36fd865a5699c867e68a23153ec40da919e33 (diff)
Merge branch '0.24.x'
Conflicts: CHANGELOG lib/puppet/type/tidy.rb spec/unit/type/file/ensure.rb spec/unit/type/tidy.rb
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/provider/macauthorization.rb147
-rwxr-xr-xspec/unit/provider/service/launchd.rb2
-rwxr-xr-xspec/unit/provider/zfs/solaris.rb4
-rwxr-xr-xspec/unit/type/file/ensure.rb11
-rwxr-xr-xspec/unit/type/macauthorization.rb78
-rwxr-xr-xspec/unit/type/tidy.rb6
-rwxr-xr-xspec/unit/type/user.rb12
-rwxr-xr-xspec/unit/type/zfs.rb35
8 files changed, 280 insertions, 15 deletions
diff --git a/spec/unit/provider/macauthorization.rb b/spec/unit/provider/macauthorization.rb
new file mode 100755
index 000000000..8c9636f16
--- /dev/null
+++ b/spec/unit/provider/macauthorization.rb
@@ -0,0 +1,147 @@
+#!/usr/bin/env ruby
+#
+# Unit testing for the macauthorization provider
+#
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet'
+require 'facter/util/plist'
+
+provider_class = Puppet::Type.type(:macauthorization).provider(:macauthorization)
+
+describe provider_class do
+
+ before :each do
+ # Create a mock resource
+ @resource = stub 'resource'
+
+ @authname = "foo.spam.eggs.puppettest"
+ @authplist = {}
+
+ @rules = {@authname => @authplist}
+
+ authdb = {}
+ authdb["rules"] = { "foorule" => "foo" }
+ authdb["rights"] = { "fooright" => "foo" }
+
+ # Stub out Plist::parse_xml
+ Plist.stubs(:parse_xml).returns(authdb)
+
+ # A catch all; no parameters set
+ @resource.stubs(:[]).returns(nil)
+
+ # But set name, ensure
+ @resource.stubs(:[]).with(:name).returns @authname
+ @resource.stubs(:[]).with(:ensure).returns :present
+ @resource.stubs(:ref).returns "MacAuthorization[#{@authname}]"
+
+ @provider = provider_class.new(@resource)
+ end
+
+ it "should have a create method" do
+ @provider.should respond_to(:create)
+ end
+
+ it "should have a destroy method" do
+ @provider.should respond_to(:destroy)
+ end
+
+ it "should have an exists? method" do
+ @provider.should respond_to(:exists?)
+ end
+
+ it "should have a flush method" do
+ @provider.should respond_to(:flush)
+ end
+
+ properties = [ :allow_root, :authenticate_user, :auth_class, :comment,
+ :group, :k_of_n, :mechanisms, :rule, :session_owner,
+ :shared, :timeout, :tries, :auth_type ]
+
+ properties.each do |prop|
+ it "should have a #{prop.to_s} method" do
+ @provider.should respond_to(prop.to_s)
+ end
+
+ it "should have a #{prop.to_s}= method" do
+ @provider.should respond_to(prop.to_s + "=")
+ end
+ end
+
+ describe "when destroying a right" do
+ before :each do
+ @resource.stubs(:[]).with(:auth_type).returns(:right)
+ end
+
+ it "should call the internal method destroy_right" do
+ @provider.expects(:destroy_right)
+ @provider.destroy
+ end
+ it "should call the external command 'security authorizationdb remove @authname" do
+ @provider.expects(:security).with("authorizationdb", :remove, @authname)
+ @provider.destroy
+ end
+ end
+
+ describe "when destroying a rule" do
+ before :each do
+ @resource.stubs(:[]).with(:auth_type).returns(:rule)
+ end
+
+ it "should call the internal method destroy_rule" do
+ @provider.expects(:destroy_rule)
+ @provider.destroy
+ end
+ end
+
+ describe "when flushing a right" do
+ before :each do
+ @resource.stubs(:[]).with(:auth_type).returns(:right)
+ end
+
+ it "should call the internal method flush_right" do
+ @provider.expects(:flush_right)
+ @provider.flush
+ end
+
+ it "should call the internal method set_right" do
+ @provider.expects(:set_right)
+ @provider.flush
+ end
+
+ it "should read and write to the auth database with the right arguments" do
+ @provider.expects(:execute).with() { |cmds, args|
+ cmds.include?("read") and
+ cmds.include?(@authname) and
+ args[:combine] == false
+ }.once
+
+ @provider.expects(:execute).with() { |cmds, args|
+ cmds.include?("write") and
+ cmds.include?(@authname) and
+ args[:combine] == false and
+ args[:stdinfile] != nil
+ }.once
+ @provider.flush
+ end
+
+ end
+
+ describe "when flushing a rule" do
+ before :each do
+ @resource.stubs(:[]).with(:auth_type).returns(:rule)
+ end
+
+ it "should call the internal method flush_rule" do
+ @provider.expects(:flush_rule)
+ @provider.flush
+ end
+
+ it "should call the internal method set_rule" do
+ @provider.expects(:set_rule)
+ @provider.flush
+ end
+ end
+
+end \ No newline at end of file
diff --git a/spec/unit/provider/service/launchd.rb b/spec/unit/provider/service/launchd.rb
index 9650ea423..cc2dae190 100755
--- a/spec/unit/provider/service/launchd.rb
+++ b/spec/unit/provider/service/launchd.rb
@@ -62,7 +62,7 @@ describe provider_class do
describe "when checking status" do
it "should call the external command 'launchctl list' once" do
- @provider.expects("launchctl").with(:list, @resource[:name]).returns(:running).once
+ @provider.expects(:launchctl).with(:list, @resource[:name]).returns(:running).once
@provider.status
end
end
diff --git a/spec/unit/provider/zfs/solaris.rb b/spec/unit/provider/zfs/solaris.rb
index 63aefcdc4..9189e44f0 100755
--- a/spec/unit/provider/zfs/solaris.rb
+++ b/spec/unit/provider/zfs/solaris.rb
@@ -66,12 +66,12 @@ describe provider_class do
[:mountpoint, :compression, :copies, :quota, :reservation, :sharenfs, :snapdir].each do |prop|
describe "when getting the #{prop} value" do
it "should call zfs with :get, #{prop} and this zfs" do
- @provider.expects(:zfs).with(:get, prop, @resource[:name]).returns("NAME PROPERTY VALUE SOURCE\nmyzfs name value blah")
+ @provider.expects(:zfs).with(:get, "-H", "-o", "value", prop, @resource[:name]).returns("value\n")
@provider.send(prop)
end
it "should get the third value of the second line from the output" do
- @provider.stubs(:zfs).with(:get, prop, @resource[:name]).returns("NAME PROPERTY VALUE SOURCE\nmyzfs name value blah")
+ @provider.stubs(:zfs).with(:get, "-H", "-o", "value", prop, @resource[:name]).returns("value\n")
@provider.send(prop).should == "value"
end
end
diff --git a/spec/unit/type/file/ensure.rb b/spec/unit/type/file/ensure.rb
index be1e65110..d766eeb35 100755
--- a/spec/unit/type/file/ensure.rb
+++ b/spec/unit/type/file/ensure.rb
@@ -3,10 +3,14 @@
Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
property = Puppet::Type.type(:file).attrclass(:ensure)
+
describe property do
before do
# Wow that's a messy interface to the resource.
- @resource = stub 'resource', :[] => nil, :[]= => nil, :property => nil, :newattr => nil, :parameter => nil
+ @resource = stub 'resource', :[] => nil, :[]= => nil, :property => nil, :newattr => nil, :parameter => nil, :replace? => true
+ @resource.stubs(:[]).returns "foo"
+ @resource.stubs(:[]).with(:path).returns "/my/file"
+ @ensure = property.new :resource => @resource
end
it "should be a subclass of Ensure" do
@@ -36,6 +40,11 @@ describe property do
@stat = stub 'stat', :ftype => "file"
end
+ it "should always be in sync if replace is 'false' unless the file is missing" do
+ @resource.expects(:replace?).returns false
+ @ensure.insync?(:link).should be_true
+ end
+
it "should be in sync if :ensure is set to :absent and the file does not exist" do
@ensure.should = :absent
diff --git a/spec/unit/type/macauthorization.rb b/spec/unit/type/macauthorization.rb
new file mode 100755
index 000000000..1c7f122b8
--- /dev/null
+++ b/spec/unit/type/macauthorization.rb
@@ -0,0 +1,78 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+macauth_type = Puppet::Type.type(:macauthorization)
+
+describe Puppet.type(:macauthorization), "when checking macauthorization objects" do
+
+ before do
+ authplist = {}
+ authplist["rules"] = { "foorule" => "foo" }
+ authplist["rights"] = { "fooright" => "foo" }
+ provider_class = macauth_type.provider(macauth_type.providers[0])
+ Plist.stubs(:parse_xml).with("/etc/authorization").returns(authplist)
+ macauth_type.stubs(:defaultprovider).returns provider_class
+ end
+
+ after do
+ macauth_type.clear
+ end
+
+
+ describe "when validating attributes" do
+
+ parameters = [:name,]
+ properties = [:auth_type, :allow_root, :authenticate_user, :auth_class,
+ :comment, :group, :k_of_n, :mechanisms, :rule,
+ :session_owner, :shared, :timeout, :tries]
+
+ parameters.each do |parameter|
+ it "should have a %s parameter" % parameter do
+ macauth_type.attrclass(parameter).ancestors.should be_include(Puppet::Parameter)
+ end
+
+ it "should have documentation for its %s parameter" % parameter do
+ macauth_type.attrclass(parameter).doc.should be_instance_of(String)
+ end
+ end
+
+ properties.each do |property|
+ it "should have a %s property" % property do
+ macauth_type.attrclass(property).ancestors.should be_include(Puppet::Property)
+ end
+
+ it "should have documentation for its %s property" % property do
+ macauth_type.attrclass(property).doc.should be_instance_of(String)
+ end
+ end
+
+ end
+
+ describe "when validating properties" do
+
+ it "should have a default provider inheriting from Puppet::Provider" do
+ macauth_type.defaultprovider.ancestors.should be_include(Puppet::Provider)
+ end
+
+ it "should be able to create an instance" do
+ lambda {
+ macauth_type.create(:name => 'foo')
+ }.should_not raise_error
+ end
+
+ it "should support :present as a value to :ensure" do
+ lambda {
+ macauth_type.create(:name => "foo", :ensure => :present)
+ }.should_not raise_error
+ end
+
+ it "should support :absent as a value to :ensure" do
+ lambda {
+ macauth_type.create(:name => "foo", :ensure => :absent)
+ }.should_not raise_error
+ end
+
+ end
+
+end \ No newline at end of file
diff --git a/spec/unit/type/tidy.rb b/spec/unit/type/tidy.rb
index 4609dbc85..c1cb8eabf 100755
--- a/spec/unit/type/tidy.rb
+++ b/spec/unit/type/tidy.rb
@@ -122,6 +122,12 @@ describe Puppet::Type.type(:tidy) do
@tidy.mkfile("/what/ever")
end
+
+ it "should do nothing if the targeted file does not exist" do
+ File.expects(:lstat).with("/what/ever").raises Errno::ENOENT
+
+ @tidy.generate.should == []
+ end
end
describe "and recursion is not used" do
diff --git a/spec/unit/type/user.rb b/spec/unit/type/user.rb
index 17524c5e5..78bfa2e82 100755
--- a/spec/unit/type/user.rb
+++ b/spec/unit/type/user.rb
@@ -239,12 +239,20 @@ describe user do
describe "when user has roles" do
it "should autorequire roles" do
- testuser = Puppet.type(:user).create(:name => "testuser", :roles => "testrole")
+ #this is a little funky because the autorequire depends on a property with a feature
+ testuser = Puppet.type(:user).create(:name => "testuser")
+ testuser.provider.class.expects(:feature?).with(:manages_solaris_rbac).returns(true)
+ testuser[:roles] = "testrole"
+
testrole = Puppet.type(:user).create(:name => "testrole")
+
config = Puppet::Node::Catalog.new :testing do |conf|
[testuser, testrole].each { |resource| conf.add_resource resource }
end
- testuser.autorequire
+
+ rel = testuser.autorequire[0]
+ rel.source.ref.should == testrole.ref
+ rel.target.ref.should == testuser.ref
end
end
end
diff --git a/spec/unit/type/zfs.rb b/spec/unit/type/zfs.rb
index 434415e24..08d6e0747 100755
--- a/spec/unit/type/zfs.rb
+++ b/spec/unit/type/zfs.rb
@@ -2,19 +2,14 @@
Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
-zpool = Puppet::Type.type(:zfs)
-
-describe zpool do
- before do
- @provider = stub 'provider'
- @resource = stub 'resource', :resource => nil, :provider => @provider, :line => nil, :file => nil
- end
+zfs = Puppet::Type.type(:zfs)
+describe zfs do
properties = [:ensure, :mountpoint, :compression, :copies, :quota, :reservation, :sharenfs, :snapdir]
properties.each do |property|
it "should have a %s property" % property do
- zpool.attrclass(property).ancestors.should be_include(Puppet::Property)
+ zfs.attrclass(property).ancestors.should be_include(Puppet::Property)
end
end
@@ -22,7 +17,29 @@ describe zpool do
parameters.each do |parameter|
it "should have a %s parameter" % parameter do
- zpool.attrclass(parameter).ancestors.should be_include(Puppet::Parameter)
+ zfs.attrclass(parameter).ancestors.should be_include(Puppet::Parameter)
end
end
+
+ it "should autorequire the containing zfss and the zpool" do
+ provider = mock "provider"
+ provider.stubs(:name).returns(:solaris)
+ zfs.stubs(:defaultprovider).returns(provider)
+ Puppet.type(:zpool).stubs(:defaultprovider).returns(provider)
+
+
+ foo_pool = Puppet.type(:zpool).create(:name => "foo")
+
+ foo_bar_zfs = Puppet.type(:zfs).create(:name => "foo/bar")
+ foo_bar_baz_zfs = Puppet.type(:zfs).create(:name => "foo/bar/baz")
+ foo_bar_baz_buz_zfs = Puppet.type(:zfs).create(:name => "foo/bar/baz/buz")
+
+ config = Puppet::Node::Catalog.new :testing do |conf|
+ [foo_pool, foo_bar_zfs, foo_bar_baz_zfs, foo_bar_baz_buz_zfs].each { |resource| conf.add_resource resource }
+ end
+
+ req = foo_bar_baz_buz_zfs.autorequire.collect { |edge| edge.source.ref }
+
+ [foo_pool.ref, foo_bar_zfs.ref, foo_bar_baz_zfs.ref].each { |ref| req.include?(ref).should == true }
+ end
end