update the tests to reflect the list->entries migration and where support

Signed-off-by: Alex Pop <apop@chef.io>
This commit is contained in:
Alex Pop 2017-02-02 22:10:41 +00:00
parent eb450c08a6
commit f7444ed372

View file

@ -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'