【问题标题】:Chef Inspec Test JSON output from an HTTP API来自 HTTP API 的 Chef Inspec 测试 JSON 输出
【发布时间】:2019-06-13 13:25:52
【问题描述】:

我正在尝试创建一个检查控件,我需要在其中检查 json 文件中的状态,该文件在点击 http url 时被下载。 当我点击http://localhost:5000/aaa/bbb/ccc/v1/healthCheck url 时,会下载一个文件(healthCheck.json)。 我正在尝试执行以下代码

control "file_check" do
  http_request = http('http://localhost:5000/aaa/bbb/ccc/v1/healthCheck')
  describe json(content: http_request.body) do
    its('status') { should eq 'success' }
  end
end

我得到的错误是

"results": [
            {
              "status": "failed",
              "code_desc": "Control Source Code Error a00972-http/controls/http.rb:5 ",
              "run_time": 0.0006573,
              "start_time": "2019-06-13T09:56:57+10:00",
              "message": "undefined method `body' for nil:NilClass",
              "exception": "RuntimeError",

提前感谢您的帮助。

【问题讨论】:

    标签: json ruby http chef-infra inspec


    【解决方案1】:

    根据json resource,您没有正确访问json路径。

    改变:

    its('status') { should eq 'success' }
    

    到:

    its(['results', 0, 'status']) { should eq 'success' }
    

    请注意results[0].success的值为failed

    【讨论】:

      猜你喜欢
      • 2018-03-30
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 2018-03-16
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多