Skip to content

Commit

Permalink
Add first test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
roidelapluie committed Aug 7, 2015
1 parent e59b8b6 commit b84c8ae
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/unit/puppet/provider/posixacl_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

provider_class = Puppet::Type.type(:acl).provider(:posixacl)

describe provider_class do

it 'declares a getfacl command' do
expect{
provider_class.command :getfacl
}.not_to raise_error
end
it 'declares a setfacl command' do
expect{
provider_class.command :setfacl
}.not_to raise_error
end
end
112 changes: 112 additions & 0 deletions spec/unit/puppet/type/acl_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
require 'spec_helper'

acl_type = Puppet::Type.type(:acl)


describe acl_type do
context 'when not setting parameters' do
it 'should fail without permissions' do
expect{
acl_type.new :name => '/tmp/foo'
}.to raise_error
end
end
context 'when setting parameters' do
it 'should work with a correct permission parameter' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['user:root:rwx']
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:permission]).to eq(['user:root:rwx'])
end
it 'should convert a permission string to an array' do
resource = acl_type.new :name => '/tmp/foo', :permission => 'user:root:rwx'
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:permission]).to eq(['user:root:rwx'])
end
it 'should convert the u: shorcut to user:' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['u:root:rwx']
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:permission]).to eq(['user:root:rwx'])
end
it 'should convert the g: shorcut to group:' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['g:root:rwx']
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:permission]).to eq(['group:root:rwx'])
end
it 'should convert the m: shorcut to mask:' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['m::rwx']
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:permission]).to eq(['mask::rwx'])
end
it 'should convert the o: shorcut to other:' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx']
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:permission]).to eq(['other::rwx'])
end
it 'should have the "set" action by default' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx']
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:action]).to eq(:set)
end
it 'should accept an action "set"' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx'], :action => :set
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:action]).to eq(:set)
end
it 'should accept an action "purge"' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx'], :action => :purge
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:action]).to eq(:purge)
end
it 'should accept an action "unset"' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx'], :action => :unset
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:action]).to eq(:unset)
end
it 'should accept an action "exact"' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx'], :action => :exact
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:action]).to eq(:exact)
end
it 'should have path as namevar' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx']
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:path]).to eq(resource[:name])
end
it 'should accept a path parameter' do
resource = acl_type.new :path => '/tmp/foo', :permission => ['o::rwx'], :action => :exact
expect(resource[:path]).to eq('/tmp/foo')
expect(resource[:name]).to eq(resource[:path])
end
it 'should not be recursive by default' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx']
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:recursive]).to eq(:false)
end
it 'should accept a recursive "true"' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx'], :recursive => true
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:recursive]).to eq(:true)
end
it 'should accept a recurse "false"' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx'], :recursive => false
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:recursive]).to eq(:false)
end
it 'should fail with a wrong action' do
expect{
acl_type.new :name => '/tmp/foo', :permission => ['o::rwx'], :action => :xset
}.to raise_error
end
it 'should fail with a wrong first argument' do
expect{
acl_type.new :name => '/tmp/foo', :permission => ['wrong::rwx']
}.to raise_error
end
it 'should fail with a wrong last argument' do
expect{
acl_type.new :name => '/tmp/foo', :permission => ['user::-_-']
}.to raise_error
end
end

end

0 comments on commit b84c8ae

Please sign in to comment.