Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mode, owner_user, and owner_group methods to file #544

Merged
merged 1 commit into from
Jan 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to avoid using let(:stdout) but couldn't seem to get it working otherwise. I'm still not sure how the be_mode and be_owned_by matchers are working =/

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