Show process name during inspec output

Signed-off-by: Juan Carlos Castillo Cano <jccastillocano@gmail.com>
This commit is contained in:
Juan Carlos Castillo Cano 2016-11-29 11:00:43 +00:00
parent 1cd2519d90
commit 58ef61f1f4
2 changed files with 13 additions and 2 deletions

View file

@ -21,9 +21,10 @@ module Inspec::Resources
:states
def initialize(grep)
@grep = grep
# turn into a regexp if it isn't one yet
if grep.class == String
grep = '(/[^/]*)*'+grep if grep[0] != '/'
grep = '(/[^/]*)*' + grep if grep[0] != '/'
grep = Regexp.new('^' + grep + '(\s|$)')
end
all_cmds = ps_axo
@ -38,7 +39,7 @@ module Inspec::Resources
end
def to_s
'Processes'
"Processes #{@grep.class == String ? @grep : @grep.inspect}"
end
private

View file

@ -70,4 +70,14 @@ describe 'Inspec::Resources::Processes' do
_(resource.users.sort).must_equal ['opscode-pgsql']
_(resource.states.sort).must_equal ['Ss']
end
it 'command name matches with output (string)' do
resource = MockLoader.new(:centos6).load_resource('processes', 'mysqld')
_(resource.to_s).must_equal 'Processes mysqld'
end
it 'command name matches with output (regex)' do
resource = MockLoader.new(:centos6).load_resource('processes', /mysqld/)
_(resource.to_s).must_equal 'Processes /mysqld/'
end
end