我正在运行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但这不起作用,因为变量result没有存储值'f‘。
我的问题是如何将值存储在变量中,并将其用于inspec中的下一个测试?如何打印inspec中的变量值(调试语句)
发布于 2019-10-09 16:36:53
就我的记忆而言,您应该将sql查询赋给一个变量,将该变量传递给describe块,以便可以使用匹配器(但感觉在本例中并不需要它),然后对该变量设置一个条件。它应该是这样的:
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
endhttps://stackoverflow.com/questions/58296069
复制相似问题