summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorJeffrey McCune <mccune.jeff@gmail.com>2008-12-01 20:16:11 -0500
committerJames Turnbull <james@lovedthanlost.net>2008-12-02 13:34:31 +1100
commit65d6b49950160e45ee4f12b525a1d9878666157f (patch)
tree41ab320cbae6b03f2262f94fe76e7cc7f6b42987 /spec/unit
parentfd128d6b3e5b1b9759646428d056faffade5d19a (diff)
downloadpuppet-65d6b49950160e45ee4f12b525a1d9878666157f.tar.gz
puppet-65d6b49950160e45ee4f12b525a1d9878666157f.tar.xz
puppet-65d6b49950160e45ee4f12b525a1d9878666157f.zip
Updated mcx type and provider with comprehensive spec tests.
Signed-off-by: Jeffrey McCune <mccune.jeff@gmail.com> Fixed default provider error with mcx type spec. Signed-off-by: Jeffrey McCune <mccune.jeff@gmail.com>
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/provider/mcx/mcxcontent.rb113
-rwxr-xr-xspec/unit/type/mcx.rb78
2 files changed, 171 insertions, 20 deletions
diff --git a/spec/unit/provider/mcx/mcxcontent.rb b/spec/unit/provider/mcx/mcxcontent.rb
index 6cb3fc78e..eedff7dad 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 fb67f07d9..bb9d59c73 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