Skip to content

Commit

Permalink
Merge pull request #544 from twolfson/dev/add.more.file.methods.sqwished
Browse files Browse the repository at this point in the history
Added mode, owner_user, and owner_group methods to file
  • Loading branch information
mizzy committed Jan 9, 2016
2 parents 124b28f + 2d8147d commit c609427
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/serverspec/type/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def content
@content
end

def group
@runner.get_file_owner_group(@name).stdout.strip
end

def version?(version)
@runner.check_file_has_version(@name, version)
end
Expand All @@ -121,11 +125,19 @@ def link_target
@runner.get_file_link_target(@name).stdout.strip
end

def mode
@runner.get_file_mode(@name).stdout.strip
end

def mtime
d = @runner.get_file_mtime(@name).stdout.strip
DateTime.strptime(d, '%s').new_offset(DateTime.now.offset)
end

def owner
@runner.get_file_owner_user(@name).stdout.strip
end

def size
@runner.get_file_size(@name).stdout.strip.to_i
end
Expand Down
15 changes: 15 additions & 0 deletions spec/type/base/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@
its(:sha256sum) { should_not eq 'INVALIDSHA256CHECKSUM' }
end

describe file('/etc/passwd') do
let(:stdout) { "root\r\n" }
its(:group) { should eq 'root' }
end

describe file('/etc/passwd') do
let(:stdout) {<<EOF
root:x:0:0:root:/root:/bin/bash
Expand All @@ -342,11 +347,21 @@
its(:link_target) { should eq '/etc/pam.dsystem-auth-ac' }
end

describe file('/etc/passwd') do
let(:stdout) { "644\r\n" }
its(:mode) { should eq '644' }
end

describe file('/etc/passwd') do
let(:stdout) { Time.now.to_i.to_s }
its(:mtime) { should > DateTime.now - 1 }
end

describe file('/etc/passwd') do
let(:stdout) { "root\r\n" }
its(:owner) { should eq 'root' }
end

describe file('/etc/passwod') do
let(:stdout) { 100.to_s }
its(:size) { should > 0 }
Expand Down

0 comments on commit c609427

Please sign in to comment.