mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
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:
parent
eb450c08a6
commit
f7444ed372
1 changed files with 29 additions and 8 deletions
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue