Sha256: 243ae962e03e211fa8d4f89a4d967a3f37219bde5a3b028cfe436e44791c67d5

Contents?: true

Size: 1.78 KB

Versions: 31

Compression:

Stored size: 1.78 KB

Contents

#!/usr/bin/env rspec

require 'spec_helper'

describe Puppet::Type.type(:file).attrclass(:group) do
  include PuppetSpec::Files

  let(:path) { tmpfile('mode_spec') }
  let(:resource) { Puppet::Type.type(:file).new :path => path, :group => 'users' }
  let(:group) { resource.property(:group) }

  before :each do
    # If the provider was already loaded without root, it won't have the
    # feature, so we have to add it here to test.
    Puppet::Type.type(:file).defaultprovider.has_feature :manages_ownership
  end

  describe "#insync?" do
    before :each do
      resource[:group] = ['foos', 'bars']

      resource.provider.stubs(:name2gid).with('foos').returns 1001
      resource.provider.stubs(:name2gid).with('bars').returns 1002
    end

    it "should fail if an group's id can't be found by name" do
      resource.provider.stubs(:name2gid).returns nil

      expect { group.insync?(5) }.to raise_error(/Could not find group foos/)
    end

    it "should use the id for comparisons, not the name" do
      group.insync?('foos').should be_false
    end

    it "should return true if the current group is one of the desired group" do
      group.insync?(1001).should be_true
    end

    it "should return false if the current group is not one of the desired group" do
      group.insync?(1003).should be_false
    end
  end

  %w[is_to_s should_to_s].each do |prop_to_s|
    describe "##{prop_to_s}" do
      it "should use the name of the user if it can find it" do
        resource.provider.stubs(:gid2name).with(1001).returns 'foos'

        group.send(prop_to_s, 1001).should == 'foos'
      end

      it "should use the id of the user if it can't" do
        resource.provider.stubs(:gid2name).with(1001).returns nil

        group.send(prop_to_s, 1001).should == 1001
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
puppet-2.7.26 spec/unit/type/file/group_spec.rb
puppet-2.7.25 spec/unit/type/file/group_spec.rb
puppet-2.7.24 spec/unit/type/file/group_spec.rb
puppet-2.7.23 spec/unit/type/file/group_spec.rb
puppet-2.7.22 spec/unit/type/file/group_spec.rb
puppet-2.7.21 spec/unit/type/file/group_spec.rb
puppet-2.7.20 spec/unit/type/file/group_spec.rb
puppet-2.7.20.rc1 spec/unit/type/file/group_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/type/file/group_spec.rb
puppet-2.7.19 spec/unit/type/file/group_spec.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/type/file/group_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/type/file/group_spec.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/type/file/group_spec.rb
puppet-2.7.18 spec/unit/type/file/group_spec.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/type/file/group_spec.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/type/file/group_spec.rb
puppet-2.7.17 spec/unit/type/file/group_spec.rb
puppet-2.7.16 spec/unit/type/file/group_spec.rb
puppet-2.7.14 spec/unit/type/file/group_spec.rb
puppet-2.7.13 spec/unit/type/file/group_spec.rb