[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:19 UTC 2009


The following commit has been merged in the master branch:
commit d803096c9a69e0c15548d1ab0d9136c7de234d07
Author: James Turnbull <james at lovedthanlost.net>
Date:   Wed Oct 8 14:00:35 2008 +1100

    Add new set of unit tests for selmodule type

diff --git a/spec/unit/other/selinux.rb b/spec/unit/other/selinux.rb
deleted file mode 100644
index 6f8fcb0..0000000
--- a/spec/unit/other/selinux.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-require 'puppet/type/selmodule'
-
-describe Puppet.type(:selmodule), " when checking policy modules" do
-	before :each do
-		@module = Puppet::Type::Selmodule.create(
-			:name => "foo",
-			:selmoduledir => "/some/path",
-			:selmodulepath => "/some/path/foo.pp",
-			:syncversion => true)
-	end
-	it "should be able to access :name" do
-		@module[:name].should == "foo"
-	end
-	it "should be able to access :selmoduledir" do
-		@module[:selmoduledir].should == "/some/path"
-	end
-	it "should be able to access :selmodulepath" do
-		@module[:selmodulepath].should == "/some/path/foo.pp"
-	end
-	it "should be able to access :syncversion" do
-		@module.property(:syncversion).should == :true
-	end
-	it "should set the syncversion value to false" do
-		@module[:syncversion] = :false
-		@module.property(:syncversion).should == :false
-	end
-	after :each do
-		Puppet::Type::Selmodule.clear()
-	end
-end
-
diff --git a/spec/unit/provider/selmodule-example.pp b/spec/unit/provider/selmodule-example.pp
new file mode 100644
index 0000000..28166ca
Binary files /dev/null and b/spec/unit/provider/selmodule-example.pp differ
diff --git a/spec/unit/provider/selmodule.rb b/spec/unit/provider/selmodule.rb
new file mode 100755
index 0000000..640e946
--- /dev/null
+++ b/spec/unit/provider/selmodule.rb
@@ -0,0 +1,63 @@
+#!/usr/bin/env ruby
+
+# Note: This unit test depends on having a sample SELinux policy file
+# in the same directory as this test called selmodule-example.pp
+# with version 1.5.0.  The provided selmodule-example.pp is the first
+# 256 bytes taken from /usr/share/selinux/targeted/nagios.pp on Fedora 9
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+provider_class = Puppet::Type.type(:selmodule).provider(:semodule)
+
+describe provider_class do
+    before :each do
+        @resource = stub("resource", :name => "foo")
+        @resource.stubs(:[]).returns "foo"
+        @provider = provider_class.new(@resource)
+    end
+
+    describe "exists? method" do 
+        it "should find a module if it is already loaded" do
+            @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields ["bar\t1.2.3\n", "foo\t4.4.4\n", "bang\t1.0.0\n"]
+            @provider.exists?.should == :true
+        end
+
+        it "should return nil if not loaded" do
+            @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields ["bar\t1.2.3\n", "bang\t1.0.0\n"]
+            @provider.exists?.should be_nil
+        end
+
+        it "should return nil if no modules are loaded" do
+            @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields []
+            @provider.exists?.should be_nil
+        end
+    end
+
+    describe "selmodversion_file" do
+        it "should return 1.5.0 for the example policy file" do
+            @provider.expects(:selmod_name_to_filename).returns "#{File.dirname(__FILE__)}/selmodule-example.pp"
+            @provider.selmodversion_file.should == "1.5.0"
+        end
+    end
+
+    describe "syncversion" do
+        it "should return :true if loaded and file modules are in sync" do
+            @provider.expects(:selmodversion_loaded).returns "1.5.0" 
+            @provider.expects(:selmodversion_file).returns "1.5.0"
+            @provider.syncversion.should == :true
+        end
+
+        it "should return :false if loaded and file modules are not in sync" do
+            @provider.expects(:selmodversion_loaded).returns "1.4.0"
+            @provider.expects(:selmodversion_file).returns "1.5.0"
+            @provider.syncversion.should == :false
+        end
+
+        it "should return before checking file version if no loaded policy" do
+            @provider.expects(:selmodversion_loaded).returns nil
+            @provider.syncversion.should == :false
+        end
+
+     end
+
+end
diff --git a/spec/unit/type/selmodule.rb b/spec/unit/type/selmodule.rb
new file mode 100755
index 0000000..f14bea9
--- /dev/null
+++ b/spec/unit/type/selmodule.rb
@@ -0,0 +1,18 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+describe Puppet::Type.type(:selmodule), "when validating attributes" do
+    [:name, :selmoduledir, :selmodulepath].each do |param|
+        it "should have a #{param} parameter" do
+            Puppet::Type.type(:selmodule).attrtype(param).should == :param
+        end
+    end
+
+    [:ensure, :syncversion].each do |param|
+        it "should have a #{param} property" do
+            Puppet::Type.type(:selmodule).attrtype(param).should == :property
+        end
+    end
+end
+

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list