From 2d8147d2555417581f9cc39aca10f1edbd7def4f Mon Sep 17 00:00:00 2001 From: Todd Wolfson Date: Fri, 8 Jan 2016 11:59:05 -0600 Subject: [PATCH] Added mode, owner_user, and owner_group methods to file --- lib/serverspec/type/file.rb | 12 ++++++++++++ spec/type/base/file_spec.rb | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/serverspec/type/file.rb b/lib/serverspec/type/file.rb index 03fb9047..e42aa590 100644 --- a/lib/serverspec/type/file.rb +++ b/lib/serverspec/type/file.rb @@ -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 @@ -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 diff --git a/spec/type/base/file_spec.rb b/spec/type/base/file_spec.rb index 1c35723d..22c6852c 100644 --- a/spec/type/base/file_spec.rb +++ b/spec/type/base/file_spec.rb @@ -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) {< 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 }