[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585
James Turnbull
james at lovedthanlost.net
Fri Jan 23 14:21:53 UTC 2009
The following commit has been merged in the master branch:
commit 65d6b49950160e45ee4f12b525a1d9878666157f
Author: Jeffrey McCune <mccune.jeff at gmail.com>
Date: Mon Dec 1 20:16:11 2008 -0500
Updated mcx type and provider with comprehensive spec tests.
Signed-off-by: Jeffrey McCune <mccune.jeff at gmail.com>
Fixed default provider error with mcx type spec.
Signed-off-by: Jeffrey McCune <mccune.jeff at gmail.com>
diff --git a/lib/puppet/provider/mcx/mcxcontent.rb b/lib/puppet/provider/mcx/mcxcontent.rb
index fdcc8cc..27c583e 100644
--- a/lib/puppet/provider/mcx/mcxcontent.rb
+++ b/lib/puppet/provider/mcx/mcxcontent.rb
@@ -40,7 +40,7 @@ Original Author: Jeff McCune (mccune.jeff at gmail.com)"
:user => "Users",
:group => "Groups",
:computer => "Computers",
- :computergroup => "ComputerGroups",
+ :computerlist => "ComputerLists",
}
class MCXContentProviderException < Exception
@@ -85,7 +85,6 @@ Original Author: Jeff McCune (mccune.jeff at gmail.com)"
ds_t = TypeMap[ds_type]
ds_n = ds_name.to_s
ds_path = "/Local/Default/#{ds_t}/#{ds_n}"
-
dscl 'localhost', '-mcxexport', ds_path
end
@@ -139,6 +138,7 @@ Original Author: Jeff McCune (mccune.jeff at gmail.com)"
if ds_type.nil?
ds_type = parse_type(resource[:name])
end
+ raise MCXContentProviderException unless TypeMap.keys.include? ds_type.to_sym
ds_name = resource[:ds_name]
if ds_name.nil?
diff --git a/spec/unit/provider/mcx/mcxcontent.rb b/spec/unit/provider/mcx/mcxcontent.rb
index 6cb3fc7..eedff7d 100755
--- a/spec/unit/provider/mcx/mcxcontent.rb
+++ b/spec/unit/provider/mcx/mcxcontent.rb
@@ -22,26 +22,31 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
provider_class = Puppet::Type.type(:mcx).provider(:mcxcontent)
+# describe creates a new ExampleGroup object.
describe provider_class do
+ # :each executes before each test.
+ # :all executes once for the test group and before :each.
before :each do
# Create a mock resource
@resource = stub 'resource'
@provider = provider_class.new
- @attached_to = "/Users/katie"
+ @attached_to = "/Users/foobar"
+ @ds_path = "/Local/Default/Users/foobar"
# A catch all; no parameters set
@resource.stubs(:[]).returns(nil)
# But set name, ensure and enable
@resource.stubs(:[]).with(:name).returns @attached_to
- @resource.stubs(:[]).with(:enable).returns :true
+ @resource.stubs(:[]).with(:ensure).returns :present
@resource.stubs(:ref).returns "Mcx[#{@attached_to}]"
# stub out the provider methods that actually touch the filesystem
# or execute commands
- @provider.stubs(:execute).returns("")
+ @provider.class.stubs(:execute).returns('')
+ @provider.stubs(:execute).returns('')
@provider.stubs(:resource).returns @resource
end
@@ -65,4 +70,106 @@ describe provider_class do
@provider.should respond_to(:content=)
end
+ describe "when managing the resource" do
+ it "should execute external command dscl from :create" do
+ @provider.class.expects(:dscl).returns('').once
+ @provider.create
+ end
+ it "should execute external command dscl from :destroy" do
+ @provider.class.expects(:dscl).with('localhost', '-mcxdelete', @ds_path).returns('').once
+ @provider.destroy
+ end
+ it "should execute external command dscl from :exists?" do
+ @provider.class.expects(:dscl).with('localhost', '-mcxexport', @ds_path).returns('').once
+ @provider.exists?
+ end
+ it "should execute external command dscl from :content" do
+ @provider.class.expects(:dscl).with('localhost', '-mcxexport', @ds_path).returns('')
+ @provider.content
+ end
+ it "should execute external command dscl from :content=" do
+ @provider.class.expects(:dscl).returns('')
+ @provider.content=''
+ end
+ end
+
+ describe "when creating and parsing the name for ds_type" do
+ before :each do
+ @resource.stubs(:[]).with(:name).returns "/Foo/bar"
+ end
+ it "should not accept /Foo/bar" do
+ lambda { @provider.create }.should raise_error(MCXContentProviderException)
+ end
+ it "should accept /Foo/bar with ds_type => user" do
+ @resource.stubs(:[]).with(:ds_type).returns "user"
+ lambda { @provider.create }.should_not raise_error(MCXContentProviderException)
+ end
+ it "should accept /Foo/bar with ds_type => group" do
+ @resource.stubs(:[]).with(:ds_type).returns "group"
+ lambda { @provider.create }.should_not raise_error(MCXContentProviderException)
+ end
+ it "should accept /Foo/bar with ds_type => computer" do
+ @resource.stubs(:[]).with(:ds_type).returns "computer"
+ lambda { @provider.create }.should_not raise_error(MCXContentProviderException)
+ end
+ it "should accept :name => /Foo/bar with ds_type => computerlist" do
+ @resource.stubs(:[]).with(:ds_type).returns "computerlist"
+ lambda { @provider.create }.should_not raise_error(MCXContentProviderException)
+ end
+ end
+
+ describe "when creating and :name => foobar" do
+ before :each do
+ @resource.stubs(:[]).with(:name).returns "foobar"
+ end
+ it "should not accept unspecified :ds_type and :ds_name" do
+ lambda { @provider.create }.should raise_error(MCXContentProviderException)
+ end
+ it "should not accept unspecified :ds_type" do
+ @resource.stubs(:[]).with(:ds_type).returns "user"
+ lambda { @provider.create }.should raise_error(MCXContentProviderException)
+ end
+ it "should not accept unspecified :ds_name" do
+ @resource.stubs(:[]).with(:ds_name).returns "foo"
+ lambda { @provider.create }.should raise_error(MCXContentProviderException)
+ end
+ it "should accept :ds_type => user, ds_name => foo" do
+ @resource.stubs(:[]).with(:ds_type).returns "user"
+ @resource.stubs(:[]).with(:ds_name).returns "foo"
+ lambda { @provider.create }.should_not raise_error(MCXContentProviderException)
+ end
+ it "should accept :ds_type => group, ds_name => foo" do
+ @resource.stubs(:[]).with(:ds_type).returns "group"
+ @resource.stubs(:[]).with(:ds_name).returns "foo"
+ lambda { @provider.create }.should_not raise_error(MCXContentProviderException)
+ end
+ it "should accept :ds_type => computer, ds_name => foo" do
+ @resource.stubs(:[]).with(:ds_type).returns "computer"
+ @resource.stubs(:[]).with(:ds_name).returns "foo"
+ lambda { @provider.create }.should_not raise_error(MCXContentProviderException)
+ end
+ it "should accept :ds_type => computerlist, ds_name => foo" do
+ @resource.stubs(:[]).with(:ds_type).returns "computerlist"
+ @resource.stubs(:[]).with(:ds_name).returns "foo"
+ lambda { @provider.create }.should_not raise_error(MCXContentProviderException)
+ end
+ it "should not accept :ds_type => bogustype, ds_name => foo" do
+ @resource.stubs(:[]).with(:ds_type).returns "bogustype"
+ @resource.stubs(:[]).with(:ds_name).returns "foo"
+ lambda { @provider.create }.should raise_error(MCXContentProviderException)
+ end
+ end
+
+ describe "when gathering existing instances" do
+ it "should define an instances class method." do
+ @provider.class.should respond_to(:instances)
+ end
+ it "should call external command dscl -list /Local/Default/<ds_type> on each known ds_type" do
+ @provider.class.expects(:dscl).with('localhost', '-list', "/Local/Default/Users").returns('')
+ @provider.class.expects(:dscl).with('localhost', '-list', "/Local/Default/Groups").returns('')
+ @provider.class.expects(:dscl).with('localhost', '-list', "/Local/Default/Computers").returns('')
+ @provider.class.expects(:dscl).with('localhost', '-list', "/Local/Default/ComputerLists").returns('')
+ @provider.class.instances
+ end
+ end
end
diff --git a/spec/unit/type/mcx.rb b/spec/unit/type/mcx.rb
index fb67f07..bb9d59c 100755
--- a/spec/unit/type/mcx.rb
+++ b/spec/unit/type/mcx.rb
@@ -21,42 +21,86 @@
# Most of this code copied from /spec/type/service.rb
require File.dirname(__FILE__) + '/../../spec_helper'
-
-require "puppet/type/mcx"
-describe Puppet::Type.type(:mcx), "when validating attributes" do
+require 'puppet/type/mcx'
- [:name, :ds_type, :ds_name].each do |param|
- it "should have a #{param} parameter" do
- Puppet::Type.type(:mcx).attrtype(param).should == :param
+mcx_type = Puppet::Type.type(:mcx)
+
+describe mcx_type, "when validating attributes" do
+
+ properties = [:ensure, :content]
+ parameters = [:name, :ds_type, :ds_name]
+
+ parameters.each do |p|
+ it "should have a #{p} parameter" do
+ mcx_type.attrclass(p).ancestors.should be_include(Puppet::Parameter)
+ end
+ it "should have documentation for its #{p} parameter" do
+ mcx_type.attrclass(p).doc.should be_instance_of(String)
end
end
- [:ensure, :content].each do |param|
- it "should have a #{param} property" do
- Puppet::Type.type(:mcx).attrtype(param).should == :property
+ properties.each do |p|
+ it "should have a #{p} property" do
+ mcx_type.attrclass(p).ancestors.should be_include(Puppet::Property)
+ end
+ it "should have documentation for its #{p} property" do
+ mcx_type.attrclass(p).doc.should be_instance_of(String)
end
end
end
-describe Puppet::Type.type(:mcx), "when validating attribute values" do
+describe mcx_type, "default values" do
+
+ before :each do
+ provider_class = mcx_type.provider(mcx_type.providers[0])
+ end
+
+ after :each do
+ mcx_type.clear
+ end
+
+ it "should be nil for :ds_type" do
+ mcx_type.create(:name => '/Foo/bar')[:ds_type].should be_nil
+ end
+
+ it "should be nil for :ds_name" do
+ mcx_type.create(:name => '/Foo/bar')[:ds_name].should be_nil
+ end
+
+ it "should be nil for :content" do
+ mcx_type.create(:name => '/Foo/bar')[:content].should be_nil
+ end
+
+end
+
+describe mcx_type, "when validating properties" do
+
+ before :each do
+ provider_class = mcx_type.provider(mcx_type.providers[0])
+ end
- before do
- @provider = stub 'provider', :class => Puppet::Type.type(:mcx).defaultprovider, :clear => nil, :controllable? => false
- Puppet::Type.type(:mcx).defaultprovider.stubs(:new).returns(@provider)
+ after :each do
+ mcx_type.clear
end
- after do
- Puppet::Type.type(:mcx).clear
+ it "should be able to create an instance" do
+ lambda {
+ mcx_type.create(:name => '/Foo/bar')
+ }.should_not raise_error
end
it "should support :present as a value to :ensure" do
- Puppet::Type.type(:mcx).create(:name => "/Foo/bar", :ensure => :present)
+ lambda {
+ mcx_type.create(:name => "/Foo/bar", :ensure => :present)
+ }.should_not raise_error
end
it "should support :absent as a value to :ensure" do
- Puppet::Type.type(:mcx).create(:name => "/Foo/bar", :ensure => :absent)
+ lambda {
+ mcx_type.create(:name => "/Foo/bar", :ensure => :absent)
+ }.should_not raise_error
end
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list