【问题标题】:chef inspec validation of the nested json file厨师检查嵌套 json 文件的验证
【发布时间】:2021-05-26 13:18:07
【问题描述】:

我正在使用 chef inspec 在下面的 json 文件中验证注解是否等于 Test。

"imdata": [
    {
        "aaaPwdStrengthProfile": {
            "attributes": {
                "annotation": "Test",
            }
        }
    }
]

尝试使用以下脚本但出现错误

describe json('C:/output.json') do
  its(['imdata','aaaPwdStrengthProfile','attributes','annotation']) { should eq 'Test' }
end

【问题讨论】:

    标签: json chef-infra devops inspec


    【解决方案1】:

    在您尝试测试的 JSON 文件中,imdata 是一个数组 []。嵌套字典 { .. } 是该数组的第一个元素 (0)。

    我根据您的问题将 JSON 数据创建为 /tmp/sample.json。所以inspec测试应该参考'imdata', 0,,如下:

    describe json('/tmp/sample.json') do
      its(['imdata', 0, 'aaaPwdStrengthProfile', 'attributes', 'annotation']) { should eq 'Test' }
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-07
      • 2018-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-18
      相关资源
      最近更新 更多