From f7444ed37269f7b59dae93ed5ee98b0287d3d647 Mon Sep 17 00:00:00 2001 From: Alex Pop Date: Thu, 2 Feb 2017 22:10:41 +0000 Subject: [PATCH] update the tests to reflect the list->entries migration and where support Signed-off-by: Alex Pop --- test/unit/resources/processes_test.rb | 37 +++++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/test/unit/resources/processes_test.rb b/test/unit/resources/processes_test.rb index b540fa404..2011874bf 100644 --- a/test/unit/resources/processes_test.rb +++ b/test/unit/resources/processes_test.rb @@ -8,13 +8,14 @@ require 'inspec/resource' describe 'Inspec::Resources::Processes' do it 'handles empty process results' do resource = load_resource('processes', 'nothing') - _(resource.list).must_equal [] + _(resource.entries).must_equal [] end it 'verify processes resource' do resource = MockLoader.new(:freebsd10).load_resource('processes', 'login -fp apop') - _(resource.list.length).must_equal 2 - _(resource.list[0].to_h).must_equal({ + _(resource.list.length).must_equal 2 # until we deprecate + _(resource.entries.length).must_equal 2 + _(resource.entries[0].to_h).must_equal({ label: nil, pid: 7115, cpu: '0.3', @@ -32,8 +33,28 @@ describe 'Inspec::Resources::Processes' do it 'verify processes resource on linux os' do resource = MockLoader.new(:centos6).load_resource('processes', 'postgres: bifrost bifrost') - _(resource.list.length).must_equal 1 - _(resource.list[0].to_h).must_equal({ + _(resource.entries.length).must_equal 1 + _(resource.entries[0].to_h).must_equal({ + label: 'system_u:system_r:init_t:s0', + pid: 5127, + cpu: '0.0', + mem: '0.2', + vsz: 547208, + rss: 5376, + tty: '?', + stat: 'Ss', + start: '10:54:22', + time: '00:00:00', + user: 'opscode-pgsql', + command: 'postgres: bifrost bifrost 127.0.0.1(43699) idle', + }) + end + + it 'verify processes resource using where filters on linux os. String match regex' do + resource = MockLoader.new(:centos6).load_resource('processes', '.+') + _(resource.entries.length).must_equal 7 + _(resource.where { pid < 11663 && cpu == '0.0' }.users).must_equal(["opscode-pgsql", "opscode", "root", "httpd"]) + _(resource.where { user =~ /opscode-.*/ }.entries[0].to_h).must_equal({ label: 'system_u:system_r:init_t:s0', pid: 5127, cpu: '0.0', @@ -51,8 +72,8 @@ describe 'Inspec::Resources::Processes' do it 'verify long-run processes resource on linux os' do resource = MockLoader.new(:centos6).load_resource('processes', 'httpd') - _(resource.list.length).must_equal 4 - _(resource.list[0].to_h).must_equal({ + _(resource.entries.length).must_equal 4 + _(resource.entries[0].to_h).must_equal({ label: '-', pid: 4589, cpu: '0.0', @@ -70,7 +91,7 @@ describe 'Inspec::Resources::Processes' do it 'access attributes of a process' do resource = MockLoader.new(:centos6).load_resource('processes', 'postgres: bifrost bifrost') - process = resource.list[0] + process = resource.entries[0] process.user.must_equal 'opscode-pgsql' process[:user].must_equal 'opscode-pgsql' process['user'].must_equal 'opscode-pgsql'