summaryrefslogtreecommitdiffstats
path: root/spec/unit/util/posix_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/util/posix_spec.rb')
-rwxr-xr-xspec/unit/util/posix_spec.rb348
1 files changed, 174 insertions, 174 deletions
diff --git a/spec/unit/util/posix_spec.rb b/spec/unit/util/posix_spec.rb
index 33aa4a6f2..dbc90d9d0 100755
--- a/spec/unit/util/posix_spec.rb
+++ b/spec/unit/util/posix_spec.rb
@@ -5,252 +5,252 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
require 'puppet/util/posix'
class PosixTest
- include Puppet::Util::POSIX
+ include Puppet::Util::POSIX
end
describe Puppet::Util::POSIX do
- before do
- @posix = PosixTest.new
- end
+ before do
+ @posix = PosixTest.new
+ end
- [:group, :gr].each do |name|
- it "should return :gid as the field for #{name}" do
- @posix.idfield(name).should == :gid
- end
+ [:group, :gr].each do |name|
+ it "should return :gid as the field for #{name}" do
+ @posix.idfield(name).should == :gid
+ end
- it "should return :getgrgid as the id method for #{name}" do
- @posix.methodbyid(name).should == :getgrgid
- end
+ it "should return :getgrgid as the id method for #{name}" do
+ @posix.methodbyid(name).should == :getgrgid
+ end
- it "should return :getgrnam as the name method for #{name}" do
- @posix.methodbyname(name).should == :getgrnam
- end
+ it "should return :getgrnam as the name method for #{name}" do
+ @posix.methodbyname(name).should == :getgrnam
end
+ end
- [:user, :pw, :passwd].each do |name|
- it "should return :uid as the field for #{name}" do
- @posix.idfield(name).should == :uid
- end
+ [:user, :pw, :passwd].each do |name|
+ it "should return :uid as the field for #{name}" do
+ @posix.idfield(name).should == :uid
+ end
- it "should return :getpwuid as the id method for #{name}" do
- @posix.methodbyid(name).should == :getpwuid
- end
+ it "should return :getpwuid as the id method for #{name}" do
+ @posix.methodbyid(name).should == :getpwuid
+ end
- it "should return :getpwnam as the name method for #{name}" do
- @posix.methodbyname(name).should == :getpwnam
- end
+ it "should return :getpwnam as the name method for #{name}" do
+ @posix.methodbyname(name).should == :getpwnam
end
+ end
- describe "when retrieving a posix field" do
- before do
- @thing = stub 'thing', :field => "asdf"
- end
+ describe "when retrieving a posix field" do
+ before do
+ @thing = stub 'thing', :field => "asdf"
+ end
- it "should fail if no id was passed" do
- lambda { @posix.get_posix_field("asdf", "bar", nil) }.should raise_error(Puppet::DevError)
- end
+ it "should fail if no id was passed" do
+ lambda { @posix.get_posix_field("asdf", "bar", nil) }.should raise_error(Puppet::DevError)
+ end
- describe "and the id is an integer" do
- it "should log an error and return nil if the specified id is greater than the maximum allowed ID" do
- Puppet.settings.expects(:value).with(:maximum_uid).returns 100
- Puppet.expects(:err)
+ describe "and the id is an integer" do
+ it "should log an error and return nil if the specified id is greater than the maximum allowed ID" do
+ Puppet.settings.expects(:value).with(:maximum_uid).returns 100
+ Puppet.expects(:err)
- @posix.get_posix_field("asdf", "bar", 200).should be_nil
- end
+ @posix.get_posix_field("asdf", "bar", 200).should be_nil
+ end
- it "should use the method return by :methodbyid and return the specified field" do
- Etc.expects(:getgrgid).returns @thing
+ it "should use the method return by :methodbyid and return the specified field" do
+ Etc.expects(:getgrgid).returns @thing
- @thing.expects(:field).returns "myval"
+ @thing.expects(:field).returns "myval"
- @posix.get_posix_field(:gr, :field, 200).should == "myval"
- end
+ @posix.get_posix_field(:gr, :field, 200).should == "myval"
+ end
- it "should return nil if the method throws an exception" do
- Etc.expects(:getgrgid).raises ArgumentError
+ it "should return nil if the method throws an exception" do
+ Etc.expects(:getgrgid).raises ArgumentError
- @thing.expects(:field).never
+ @thing.expects(:field).never
- @posix.get_posix_field(:gr, :field, 200).should be_nil
- end
- end
+ @posix.get_posix_field(:gr, :field, 200).should be_nil
+ end
+ end
- describe "and the id is not an integer" do
- it "should use the method return by :methodbyid and return the specified field" do
- Etc.expects(:getgrnam).returns @thing
+ describe "and the id is not an integer" do
+ it "should use the method return by :methodbyid and return the specified field" do
+ Etc.expects(:getgrnam).returns @thing
- @thing.expects(:field).returns "myval"
+ @thing.expects(:field).returns "myval"
- @posix.get_posix_field(:gr, :field, "asdf").should == "myval"
- end
+ @posix.get_posix_field(:gr, :field, "asdf").should == "myval"
+ end
- it "should return nil if the method throws an exception" do
- Etc.expects(:getgrnam).raises ArgumentError
+ it "should return nil if the method throws an exception" do
+ Etc.expects(:getgrnam).raises ArgumentError
- @thing.expects(:field).never
+ @thing.expects(:field).never
- @posix.get_posix_field(:gr, :field, "asdf").should be_nil
- end
- end
+ @posix.get_posix_field(:gr, :field, "asdf").should be_nil
+ end
end
+ end
- describe "when returning the gid" do
- before do
- @posix.stubs(:get_posix_field)
- end
+ describe "when returning the gid" do
+ before do
+ @posix.stubs(:get_posix_field)
+ end
- describe "and the group is an integer" do
- it "should convert integers specified as a string into an integer" do
- @posix.expects(:get_posix_field).with(:group, :name, 100)
+ describe "and the group is an integer" do
+ it "should convert integers specified as a string into an integer" do
+ @posix.expects(:get_posix_field).with(:group, :name, 100)
- @posix.gid("100")
- end
+ @posix.gid("100")
+ end
- it "should look up the name for the group" do
- @posix.expects(:get_posix_field).with(:group, :name, 100)
+ it "should look up the name for the group" do
+ @posix.expects(:get_posix_field).with(:group, :name, 100)
- @posix.gid(100)
- end
+ @posix.gid(100)
+ end
- it "should return nil if the group cannot be found" do
- @posix.expects(:get_posix_field).once.returns nil
- @posix.expects(:search_posix_field).never
+ it "should return nil if the group cannot be found" do
+ @posix.expects(:get_posix_field).once.returns nil
+ @posix.expects(:search_posix_field).never
- @posix.gid(100).should be_nil
- end
+ @posix.gid(100).should be_nil
+ end
- it "should use the found name to look up the id" do
- @posix.expects(:get_posix_field).with(:group, :name, 100).returns "asdf"
- @posix.expects(:get_posix_field).with(:group, :gid, "asdf").returns 100
+ it "should use the found name to look up the id" do
+ @posix.expects(:get_posix_field).with(:group, :name, 100).returns "asdf"
+ @posix.expects(:get_posix_field).with(:group, :gid, "asdf").returns 100
- @posix.gid(100).should == 100
- end
+ @posix.gid(100).should == 100
+ end
- # LAK: This is because some platforms have a broken Etc module that always return
- # the same group.
- it "should use :search_posix_field if the discovered id does not match the passed-in id" do
- @posix.expects(:get_posix_field).with(:group, :name, 100).returns "asdf"
- @posix.expects(:get_posix_field).with(:group, :gid, "asdf").returns 50
+ # LAK: This is because some platforms have a broken Etc module that always return
+ # the same group.
+ it "should use :search_posix_field if the discovered id does not match the passed-in id" do
+ @posix.expects(:get_posix_field).with(:group, :name, 100).returns "asdf"
+ @posix.expects(:get_posix_field).with(:group, :gid, "asdf").returns 50
- @posix.expects(:search_posix_field).with(:group, :gid, 100).returns "asdf"
+ @posix.expects(:search_posix_field).with(:group, :gid, 100).returns "asdf"
- @posix.gid(100).should == "asdf"
- end
- end
+ @posix.gid(100).should == "asdf"
+ end
+ end
- describe "and the group is a string" do
- it "should look up the gid for the group" do
- @posix.expects(:get_posix_field).with(:group, :gid, "asdf")
+ describe "and the group is a string" do
+ it "should look up the gid for the group" do
+ @posix.expects(:get_posix_field).with(:group, :gid, "asdf")
- @posix.gid("asdf")
- end
+ @posix.gid("asdf")
+ end
- it "should return nil if the group cannot be found" do
- @posix.expects(:get_posix_field).once.returns nil
- @posix.expects(:search_posix_field).never
+ it "should return nil if the group cannot be found" do
+ @posix.expects(:get_posix_field).once.returns nil
+ @posix.expects(:search_posix_field).never
- @posix.gid("asdf").should be_nil
- end
+ @posix.gid("asdf").should be_nil
+ end
- it "should use the found gid to look up the nam" do
- @posix.expects(:get_posix_field).with(:group, :gid, "asdf").returns 100
- @posix.expects(:get_posix_field).with(:group, :name, 100).returns "asdf"
+ it "should use the found gid to look up the nam" do
+ @posix.expects(:get_posix_field).with(:group, :gid, "asdf").returns 100
+ @posix.expects(:get_posix_field).with(:group, :name, 100).returns "asdf"
- @posix.gid("asdf").should == 100
- end
+ @posix.gid("asdf").should == 100
+ end
- it "should use :search_posix_field if the discovered name does not match the passed-in name" do
- @posix.expects(:get_posix_field).with(:group, :gid, "asdf").returns 100
- @posix.expects(:get_posix_field).with(:group, :name, 100).returns "boo"
+ it "should use :search_posix_field if the discovered name does not match the passed-in name" do
+ @posix.expects(:get_posix_field).with(:group, :gid, "asdf").returns 100
+ @posix.expects(:get_posix_field).with(:group, :name, 100).returns "boo"
- @posix.expects(:search_posix_field).with(:group, :gid, "asdf").returns "asdf"
+ @posix.expects(:search_posix_field).with(:group, :gid, "asdf").returns "asdf"
- @posix.gid("asdf").should == "asdf"
- end
- end
+ @posix.gid("asdf").should == "asdf"
+ end
end
+ end
- describe "when returning the uid" do
- before do
- @posix.stubs(:get_posix_field)
- end
+ describe "when returning the uid" do
+ before do
+ @posix.stubs(:get_posix_field)
+ end
- describe "and the group is an integer" do
- it "should convert integers specified as a string into an integer" do
- @posix.expects(:get_posix_field).with(:passwd, :name, 100)
+ describe "and the group is an integer" do
+ it "should convert integers specified as a string into an integer" do
+ @posix.expects(:get_posix_field).with(:passwd, :name, 100)
- @posix.uid("100")
- end
+ @posix.uid("100")
+ end
- it "should look up the name for the group" do
- @posix.expects(:get_posix_field).with(:passwd, :name, 100)
+ it "should look up the name for the group" do
+ @posix.expects(:get_posix_field).with(:passwd, :name, 100)
- @posix.uid(100)
- end
+ @posix.uid(100)
+ end
- it "should return nil if the group cannot be found" do
- @posix.expects(:get_posix_field).once.returns nil
- @posix.expects(:search_posix_field).never
+ it "should return nil if the group cannot be found" do
+ @posix.expects(:get_posix_field).once.returns nil
+ @posix.expects(:search_posix_field).never
- @posix.uid(100).should be_nil
- end
+ @posix.uid(100).should be_nil
+ end
- it "should use the found name to look up the id" do
- @posix.expects(:get_posix_field).with(:passwd, :name, 100).returns "asdf"
- @posix.expects(:get_posix_field).with(:passwd, :uid, "asdf").returns 100
+ it "should use the found name to look up the id" do
+ @posix.expects(:get_posix_field).with(:passwd, :name, 100).returns "asdf"
+ @posix.expects(:get_posix_field).with(:passwd, :uid, "asdf").returns 100
- @posix.uid(100).should == 100
- end
+ @posix.uid(100).should == 100
+ end
- # LAK: This is because some platforms have a broken Etc module that always return
- # the same group.
- it "should use :search_posix_field if the discovered id does not match the passed-in id" do
- @posix.expects(:get_posix_field).with(:passwd, :name, 100).returns "asdf"
- @posix.expects(:get_posix_field).with(:passwd, :uid, "asdf").returns 50
+ # LAK: This is because some platforms have a broken Etc module that always return
+ # the same group.
+ it "should use :search_posix_field if the discovered id does not match the passed-in id" do
+ @posix.expects(:get_posix_field).with(:passwd, :name, 100).returns "asdf"
+ @posix.expects(:get_posix_field).with(:passwd, :uid, "asdf").returns 50
- @posix.expects(:search_posix_field).with(:passwd, :uid, 100).returns "asdf"
+ @posix.expects(:search_posix_field).with(:passwd, :uid, 100).returns "asdf"
- @posix.uid(100).should == "asdf"
- end
- end
+ @posix.uid(100).should == "asdf"
+ end
+ end
- describe "and the group is a string" do
- it "should look up the uid for the group" do
- @posix.expects(:get_posix_field).with(:passwd, :uid, "asdf")
+ describe "and the group is a string" do
+ it "should look up the uid for the group" do
+ @posix.expects(:get_posix_field).with(:passwd, :uid, "asdf")
- @posix.uid("asdf")
- end
+ @posix.uid("asdf")
+ end
- it "should return nil if the group cannot be found" do
- @posix.expects(:get_posix_field).once.returns nil
- @posix.expects(:search_posix_field).never
+ it "should return nil if the group cannot be found" do
+ @posix.expects(:get_posix_field).once.returns nil
+ @posix.expects(:search_posix_field).never
- @posix.uid("asdf").should be_nil
- end
+ @posix.uid("asdf").should be_nil
+ end
- it "should use the found uid to look up the nam" do
- @posix.expects(:get_posix_field).with(:passwd, :uid, "asdf").returns 100
- @posix.expects(:get_posix_field).with(:passwd, :name, 100).returns "asdf"
+ it "should use the found uid to look up the nam" do
+ @posix.expects(:get_posix_field).with(:passwd, :uid, "asdf").returns 100
+ @posix.expects(:get_posix_field).with(:passwd, :name, 100).returns "asdf"
- @posix.uid("asdf").should == 100
- end
+ @posix.uid("asdf").should == 100
+ end
- it "should use :search_posix_field if the discovered name does not match the passed-in name" do
- @posix.expects(:get_posix_field).with(:passwd, :uid, "asdf").returns 100
- @posix.expects(:get_posix_field).with(:passwd, :name, 100).returns "boo"
+ it "should use :search_posix_field if the discovered name does not match the passed-in name" do
+ @posix.expects(:get_posix_field).with(:passwd, :uid, "asdf").returns 100
+ @posix.expects(:get_posix_field).with(:passwd, :name, 100).returns "boo"
- @posix.expects(:search_posix_field).with(:passwd, :uid, "asdf").returns "asdf"
+ @posix.expects(:search_posix_field).with(:passwd, :uid, "asdf").returns "asdf"
- @posix.uid("asdf").should == "asdf"
- end
- end
+ @posix.uid("asdf").should == "asdf"
+ end
end
+ end
- it "should be able to iteratively search for posix values" do
- @posix.should respond_to(:search_posix_field)
- end
+ it "should be able to iteratively search for posix values" do
+ @posix.should respond_to(:search_posix_field)
+ end
- describe "when searching for posix values iteratively" do
- it "should iterate across all of the structs returned by Etc and return the appropriate field from the first matching value"
- end
+ describe "when searching for posix values iteratively" do
+ it "should iterate across all of the structs returned by Etc and return the appropriate field from the first matching value"
+ end
end