Sha256: dd8acb6b7877089978c07917e1427382448c8e4d1c751c3a97e653ab7be0dd66

Contents?: true

Size: 1.77 KB

Versions: 71

Compression:

Stored size: 1.77 KB

Contents

#! /usr/bin/env ruby

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 a 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

71 entries across 71 versions & 1 rubygems

Version Path
puppet-3.8.7 spec/unit/type/file/group_spec.rb
puppet-3.8.7-x86-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.7-x64-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.6 spec/unit/type/file/group_spec.rb
puppet-3.8.6-x86-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.6-x64-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.5 spec/unit/type/file/group_spec.rb
puppet-3.8.5-x86-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.5-x64-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.4 spec/unit/type/file/group_spec.rb
puppet-3.8.4-x86-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.4-x64-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.3 spec/unit/type/file/group_spec.rb
puppet-3.8.3-x86-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.3-x64-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.2 spec/unit/type/file/group_spec.rb
puppet-3.8.2-x86-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.2-x64-mingw32 spec/unit/type/file/group_spec.rb
puppet-3.8.1 spec/unit/type/file/group_spec.rb
puppet-3.8.1-x86-mingw32 spec/unit/type/file/group_spec.rb