You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
control 'test' do
impact 1.0
title 'test'
desc '
Test
'
describe file('/root/test.json') do
it { should be_file }
end
describe json('/root/test.json') do
its(['hash','subhash','key']) {should eq "value"}
its(['array']) { should include "zero" }
its(['array',0]) { should eq "zero" }
end
end
And i get the following output:
× test: Test (1 failed)
✔ File /root/test.json should be file
✔ Json /root/test.json ["hash", "subhash", "key"] should eq "value"
✔ Json /root/test.json ["array"] should include "zero"
× Json /root/test.json ["array", 0] should eq "zero"
expected: "zero"
got: [nil, nil, nil]
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-"zero"
+[nil, nil, nil]
Hash access and access to the array node itself is working as expected but indexed access to the array is not working, only returning nil objects.
InSpec and Platform Version
inspec version 1.16.1
The text was updated successfully, but these errors were encountered:
@schegi agreed, it does appear that something is incorrect with the implementation or possibly the docs.
If you only care about the first or last element, you can use the first and last methods:
describe json('/tmp/test.json') do
its('array.first') { should eq 'zero' }
its('array.last') { should eq 'two' }
end
However, accessing the array items by index number does appear to be taking the full array contents and then replacing the values with nil instead. I'm not sure why and need to go dig in the code.
I hope this workaround helps for now, and I'll update this issue when I have time to dig in and take a look.
I believe I have found the bug, and I'm putting up a PR shortly to fix it and to add some tests to the ObjectTraverser class that is responsible for this functionality.
Description
Currently trying to use the json resource. Array access via index is not working as described in the documentation.
I got the following json in test.json
and the following control:
And i get the following output:
Hash access and access to the array node itself is working as expected but indexed access to the array is not working, only returning nil objects.
InSpec and Platform Version
inspec version 1.16.1
The text was updated successfully, but these errors were encountered: