diff options
author | Markus Roberts <Markus@reality.com> | 2010-06-23 15:51:08 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-06-23 22:27:29 -0700 |
commit | 51b70c05167399eb2274fc1add18b6b18d31429d (patch) | |
tree | 1a33b11f0f589d6f5cd806d6da9de317887ca0e6 /spec/unit/provider/selmodule_spec.rb | |
parent | 9958c805dd90acadbb56ed3095e665d8afa990cd (diff) | |
download | puppet-51b70c05167399eb2274fc1add18b6b18d31429d.tar.gz puppet-51b70c05167399eb2274fc1add18b6b18d31429d.tar.xz puppet-51b70c05167399eb2274fc1add18b6b18d31429d.zip |
[#3994] rename the specs to have _spec.rb at the end
Some spec files like active_record.rb had names that would confuse the
load path and get loaded instead of the intended implentation when the
spec was run from the same directory as the file.
Author: Matt Robinson <matt@puppetlabs.com>
Date: Fri Jun 11 15:29:33 2010 -0700
Diffstat (limited to 'spec/unit/provider/selmodule_spec.rb')
-rwxr-xr-x | spec/unit/provider/selmodule_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/unit/provider/selmodule_spec.rb b/spec/unit/provider/selmodule_spec.rb new file mode 100755 index 000000000..5f60322d8 --- /dev/null +++ b/spec/unit/provider/selmodule_spec.rb @@ -0,0 +1,66 @@ +#!/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(:command).with(:semodule).returns "/usr/sbin/semodule" + @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(:command).with(:semodule).returns "/usr/sbin/semodule" + @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(:command).with(:semodule).returns "/usr/sbin/semodule" + @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 |