如何在Inspec的http块中使用字符串连接?

时间:2018-12-12 16:12:36

标签: ruby chef inspec

我有一个包含http块的Inspec控件。该网址保存在名为DNScloudui['value']的变量中-我想在该网址的开头添加https://

DNScloudui = attribute('DNS_name_cloudui')

control 'Website reachability' do
  title 'Check reachability by GET requests'
  describe http(DNScloudui['value'], method: 'GET') do
    its('status') { should cmp 200 }
  end
end

我该如何实现?

1 个答案:

答案 0 :(得分:1)

假设DNScloudui返回一个非nil值,那么您可以使用字符串插值来获取DNScloudui变量的值。例如:

DNScloudui = attribute('DNS_name_cloudui')

control 'Website reachability' do
  title 'Check reachability by GET requests'
  describe http("https://#{DNScloudui['value']}", method: 'GET') do
    its('status') { should cmp 200 }
  end
end

还要查看您的DNScloudui变量的名称,我建议您坚持使用ruby naming conventions and style guides