summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorMax Martin <max@puppetlabs.com>2011-04-13 16:52:20 -0700
committerMax Martin <max@puppetlabs.com>2011-04-13 16:52:20 -0700
commitd9d9709c1eac46a94160dd75de34eafeb6c6de0c (patch)
treed86a85e406a70f6dc062af0d823d7ed1bfa5695b /spec/unit
parentda4457be4dedaed5368bacf81a08f0429e21cd45 (diff)
parent6a8068b3912d6275efe4005258a06d03363c8944 (diff)
Merge branch '2.6.next' into 2.6.x
* 2.6.next: (#2331) Remove darwinports pkg provider, replace with rewritten macports provider Fixed #7082 - Added system support for groups (#7018) Give more context on the service type's assumptions. Wording tweaks. (#7018) explain internals better in service provider documentation maint: Fix sqlite3 require to really be optional maint: Fix sporadic sqlite error (#6818) Stop from getting Rails 3 named_scope deprecation warning (#6856) Copy dangling symlinks with 'links => manage' File resource.
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/indirector/facts/inventory_active_record_spec.rb6
-rwxr-xr-xspec/unit/provider/group/groupadd_spec.rb12
-rwxr-xr-xspec/unit/provider/package/macports_spec.rb122
-rwxr-xr-xspec/unit/type/file/source_spec.rb1
-rwxr-xr-xspec/unit/type/group_spec.rb9
5 files changed, 147 insertions, 3 deletions
diff --git a/spec/unit/indirector/facts/inventory_active_record_spec.rb b/spec/unit/indirector/facts/inventory_active_record_spec.rb
index 9558abde2..022150c76 100644
--- a/spec/unit/indirector/facts/inventory_active_record_spec.rb
+++ b/spec/unit/indirector/facts/inventory_active_record_spec.rb
@@ -1,7 +1,10 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../../spec_helper'
-require 'sqlite3' rescue nil
+begin
+ require 'sqlite3'
+rescue LoadError
+end
require 'tempfile'
require 'puppet/rails'
@@ -29,6 +32,7 @@ describe "Puppet::Node::Facts::InventoryActiveRecord", :if => (Puppet.features.r
after :each do
Puppet::Rails.teardown
+ ActiveRecord::Base.remove_connection
end
describe "#save" do
diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb
index 33d9acd98..65cc887e4 100755
--- a/spec/unit/provider/group/groupadd_spec.rb
+++ b/spec/unit/provider/group/groupadd_spec.rb
@@ -10,10 +10,10 @@ describe provider_class do
@provider = provider_class.new(@resource)
end
- # #1360
it "should add -o when allowdupe is enabled and the group is being created" do
@resource.stubs(:should).returns "fakeval"
@resource.stubs(:[]).returns "fakeval"
+ @resource.stubs(:system?).returns true
@resource.expects(:allowdupe?).returns true
@provider.expects(:execute).with { |args| args.include?("-o") }
@@ -28,4 +28,14 @@ describe provider_class do
@provider.gid = 150
end
+
+ it "should add -r when system is enabled and the group is being created" do
+ @resource.stubs(:should).returns "fakeval"
+ @resource.stubs(:[]).returns "fakeval"
+ @resource.expects(:system?).returns true
+ @resource.stubs(:allowdupe?).returns true
+ @provider.expects(:execute).with { |args| args.include?("-r") }
+
+ @provider.create
+ end
end
diff --git a/spec/unit/provider/package/macports_spec.rb b/spec/unit/provider/package/macports_spec.rb
new file mode 100755
index 000000000..7d1acd537
--- /dev/null
+++ b/spec/unit/provider/package/macports_spec.rb
@@ -0,0 +1,122 @@
+require 'spec_helper'
+
+provider_class = Puppet::Type.type(:package).provider(:macports)
+
+describe provider_class do
+ let :resource_name do
+ "foo"
+ end
+
+ let :resource do
+ Puppet::Type.type(:package).new(:name => resource_name, :provider => :macports)
+ end
+
+ let :provider do
+ prov = resource.provider
+ prov.expects(:execute).never
+ prov
+ end
+
+ let :current_hash do
+ {:name => resource_name, :ensure => "1.2.3", :revision => "1", :provider => :macports}
+ end
+
+ describe "provider features" do
+ subject { provider }
+
+ it { should be_installable }
+ it { should be_uninstallable }
+ it { should be_upgradeable }
+ it { should be_versionable }
+ end
+
+ describe "when listing all instances" do
+ it "should call port -q installed" do
+ provider_class.expects(:port).with("-q", :installed).returns("")
+ provider_class.instances
+ end
+
+ it "should create instances from active ports" do
+ provider_class.expects(:port).returns("foo @1.234.5_2 (active)")
+ provider_class.instances.size.should == 1
+ end
+
+ it "should ignore ports that aren't activated" do
+ provider_class.expects(:port).returns("foo @1.234.5_2")
+ provider_class.instances.size.should == 0
+ end
+ end
+
+ describe "when installing" do
+ it "should not specify a version when ensure is set to latest" do
+ resource[:ensure] = :latest
+ provider.expects(:port).with { |flag, method, name, version|
+ version.should be_nil
+ }
+ provider.install
+ end
+
+ it "should not specify a version when ensure is set to present" do
+ resource[:ensure] = :present
+ provider.expects(:port).with { |flag, method, name, version|
+ version.should be_nil
+ }
+ provider.install
+ end
+
+ it "should specify a version when ensure is set to a version" do
+ resource[:ensure] = "1.2.3"
+ provider.expects(:port).with { |flag, method, name, version|
+ version.should be
+ }
+ provider.install
+ end
+ end
+
+ describe "when querying for the latest version" do
+ let :new_info_line do
+ "1.2.3 2"
+ end
+ let :infoargs do
+ ["-q", :info, "--line", "--version", "--revision", resource_name]
+ end
+
+ it "should return nil when the package cannot be found" do
+ resource[:name] = resource_name
+ provider.expects(:port).returns("")
+ provider.latest.should == nil
+ end
+
+ it "should return the current version if the installed port has the same revision" do
+ current_hash[:revision] = "2"
+ provider.expects(:port).with(*infoargs).returns(new_info_line)
+ provider.expects(:query).returns(current_hash)
+ provider.latest.should == current_hash[:ensure]
+ end
+
+ it "should return the new version_revision if the installed port has a lower revision" do
+ current_hash[:revision] = "1"
+ provider.expects(:port).with(*infoargs).returns(new_info_line)
+ provider.expects(:query).returns(current_hash)
+ provider.latest.should == "1.2.3_2"
+ end
+ end
+
+ describe "when updating a port" do
+ it "should execute port upgrade if the port is installed" do
+ resource[:name] = resource_name
+ resource[:ensure] = :present
+ provider.expects(:query).returns(current_hash)
+ provider.expects(:port).with("-q", :upgrade, resource_name)
+ provider.update
+ end
+
+ it "should execute port install if the port is not installed" do
+ resource[:name] = resource_name
+ resource[:ensure] = :present
+ provider.expects(:query).returns("")
+ provider.expects(:port).with("-q", :install, resource_name)
+ provider.update
+ end
+ end
+end
diff --git a/spec/unit/type/file/source_spec.rb b/spec/unit/type/file/source_spec.rb
index 00cc2f235..6e04fa2a5 100755
--- a/spec/unit/type/file/source_spec.rb
+++ b/spec/unit/type/file/source_spec.rb
@@ -187,6 +187,7 @@ describe Puppet::Type.type(:file).attrclass(:source) do
describe "and the source is a link" do
it "should set the target to the link destination" do
@metadata.stubs(:ftype).returns "link"
+ @metadata.stubs(:links).returns "manage"
@resource.stubs(:[])
@resource.stubs(:[]=)
diff --git a/spec/unit/type/group_spec.rb b/spec/unit/type/group_spec.rb
index b41ce71a0..e373dac6e 100755
--- a/spec/unit/type/group_spec.rb
+++ b/spec/unit/type/group_spec.rb
@@ -16,6 +16,10 @@ describe Puppet::Type.type(:group) do
@class.defaultprovider.ancestors.should be_include(Puppet::Provider)
end
+ it "should have a system_groups feature" do
+ @class.provider_feature(:system_groups).should_not be_nil
+ end
+
describe "when validating attributes" do
[:name, :allowdupe].each do |param|
it "should have a #{param} parameter" do
@@ -38,11 +42,14 @@ describe Puppet::Type.type(:group) do
end
end
- # #1407 - we need to declare the allowdupe param as boolean.
it "should have a boolean method for determining if duplicates are allowed" do
@class.new(:name => "foo").methods.should be_include("allowdupe?")
end
+ it "should have a boolean method for determining if system groups are allowed" do
+ @class.new(:name => "foo").methods.should be_include("system?")
+ end
+
it "should call 'create' to create the group" do
group = @class.new(:name => "foo", :ensure => :present)
group.provider.expects(:create)