Inspec 配置文件中的决策

Decision in Inspec profiles

我正在 运行创建一个 postgres inspec 配置文件,并希望 运行 仅当节点是主节点时才进行某些测试。这是我的个人资料

sql = postgres_session('postgres', password, 'localhost')
result = describe sql.query('SELECT pg_is_in_recovery()') do
    its('output') { should eq 'f' }
end
if result == 'f'
   describe sql.query('SELECT state from pg_stat_replication') do
      its('output') { should match 'streaming' }
   end
end

但这不起作用,因为变量结果不存储值 'f'。

我的问题是如何将值存储在变量中并将其用于 inspec 中的下一个测试? 我们如何在 inspec 中打印变量值(调试语句)

仅凭我的记忆,你应该将 sql 查询分配给一个变量,将该变量传递给 describe 块,这样你就可以使用匹配器(但感觉你不需要它在你的case),然后在该变量上放置一个条件。它应该是这样的:

sql = postgres_session('postgres', password, 'localhost')
result = sql.query('SELECT pg_is_in_recovery()')

if result.output == 'f'
   describe sql.query('SELECT state from pg_stat_replication') do
      its('output') { should match 'streaming' }
   end
end