extract selinux label handling for test

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-09-16 12:10:03 +02:00
parent 7137a9625b
commit 261cb6a485
7 changed files with 42 additions and 41 deletions

View file

@ -1,12 +1,37 @@
# encoding: utf-8
# Tests configuration:
module Test
class << self
# MTime tracks the maximum range of modification time in seconds.
# i.e. MTime == 60*60*1 is 1 hour of modification time range,
# which translates to a modification time range of:
# [ now-1hour, now ]
def mtime
60 * 60 * 24 * 1
end
# MTime tracks the maximum range of modification time in seconds.
# i.e. MTime == 60*60*1 is 1 hour of modification time range,
# which translates to a modification time range of:
# [ now-1hour, now ]
MTime = 60 * 60 * 24 * 1
def selinux_label(os, path = nil)
labels = {}
h = {}
h.default = Hash.new(nil)
h['redhat'] = {}
h['redhat'].default = 'unconfined_u:object_r:user_tmp_t:s0'
h['redhat']['5.11'] = 'user_u:object_r:tmp_t'
labels.default = h.dup
h = {}
h.default = Hash.new(nil)
h['redhat'] = {}
h['redhat'].default = 'system_u:object_r:null_device_t:s0'
h['redhat']['5.11'] = 'system_u:object_r:null_device_t'
labels['/dev/null'] = h.dup
labels[path][os[:family]][os[:release]]
end
end
end
# Run all tests
require 'minitest/autorun'

View file

@ -51,7 +51,7 @@ describe 'file interface' do
end
it 'has a modified time' do
file.mtime.must_be_close_to(Time.now.to_i - MTime/2, MTime)
file.mtime.must_be_close_to(Time.now.to_i - Test.mtime/2, Test.mtime)
end
it 'has inode size of 0' do
@ -59,11 +59,7 @@ describe 'file interface' do
end
it 'has selinux label handling' do
if os[:family] == 'redhat'
file.selinux_label.must_equal('unconfined_u:object_r:tmp_t:s0')
else
file.selinux_label.must_equal(nil)
end
file.selinux_label.must_equal(Test.selinux_label(os, file.path))
end
it 'has no product_version' do

View file

@ -51,7 +51,7 @@ describe 'file interface' do
end
it 'has a modified time' do
file.mtime.must_be_close_to(Time.now.to_i - MTime/2, MTime)
file.mtime.must_be_close_to(Time.now.to_i - Test.mtime/2, Test.mtime)
end
it 'has inode size of 0' do
@ -59,11 +59,7 @@ describe 'file interface' do
end
it 'has selinux label handling' do
if os[:family] == 'redhat'
file.selinux_label.must_equal('system_u:object_r:null_device_t:s0')
else
file.selinux_label.must_equal(nil)
end
file.selinux_label.must_equal(Test.selinux_label(os, file.path))
end
it 'has no product_version' do

View file

@ -55,7 +55,7 @@ describe 'file interface' do
end
it 'has a modified time' do
file.mtime.must_be_close_to(Time.now.to_i - MTime/2, MTime)
file.mtime.must_be_close_to(Time.now.to_i - Test.mtime/2, Test.mtime)
end
it 'has size' do
@ -64,11 +64,7 @@ describe 'file interface' do
end
it 'has selinux label handling' do
if os[:family] == 'redhat'
file.selinux_label.must_equal('unconfined_u:object_r:user_tmp_t:s0')
else
file.selinux_label.must_equal(nil)
end
file.selinux_label.must_equal(Test.selinux_label(os, file.path))
end
it 'has no product_version' do

View file

@ -51,7 +51,7 @@ describe 'file interface' do
end
it 'has a modified time' do
file.mtime.must_be_close_to(Time.now.to_i - MTime/2, MTime)
file.mtime.must_be_close_to(Time.now.to_i - Test.mtime/2, Test.mtime)
end
it 'has inode size' do
@ -59,11 +59,7 @@ describe 'file interface' do
end
it 'has selinux label handling' do
if os[:family] == 'redhat'
file.selinux_label.must_equal('unconfined_u:object_r:user_tmp_t:s0')
else
file.selinux_label.must_equal(nil)
end
file.selinux_label.must_equal(Test.selinux_label(os, file.path))
end
it 'has no product_version' do

View file

@ -54,7 +54,7 @@ describe 'file interface' do
# end
it 'has a modified time' do
file.mtime.must_be_close_to(Time.now.to_i - MTime/2, MTime)
file.mtime.must_be_close_to(Time.now.to_i - Test.mtime/2, Test.mtime)
end
it 'has inode size of 0' do
@ -62,11 +62,7 @@ describe 'file interface' do
end
it 'has selinux label handling' do
if os[:family] == 'redhat'
file.selinux_label.must_equal('unconfined_u:object_r:user_tmp_t:s0')
else
file.selinux_label.must_equal(nil)
end
file.selinux_label.must_equal(Test.selinux_label(os, file.path))
end

View file

@ -59,7 +59,7 @@ describe 'file interface' do
end
it 'has a modified time' do
file.mtime.must_be_close_to(Time.now.to_i - MTime/2, MTime)
file.mtime.must_be_close_to(Time.now.to_i - Test.mtime/2, Test.mtime)
end
it 'has size' do
@ -68,11 +68,7 @@ describe 'file interface' do
end
it 'has selinux label handling' do
if os[:family] == 'redhat'
file.selinux_label.must_equal('unconfined_u:object_r:user_tmp_t:s0')
else
file.selinux_label.must_equal(nil)
end
file.selinux_label.must_equal(Test.selinux_label(os, file.path))
end
it 'has no product_version' do