使用 chef inspec 验证数据库输出

Validate database output using chef inspec

在执行以下 postgresql 命令时,如何使用 chef inspec 验证名称列和行列下的输出。

postgres=# select name, setting from pg_settings where (name ~ '_directory$'
postgres(# or name ~ '_tablespace');
         name         |        setting
----------------------+------------------------
 data_directory       | /var/lib/pgsql/10/data
 default_tablespace   |
 log_directory        | log
 stats_temp_directory | pg_stat_tmp
 temp_tablespaces     |
(5 rows)

您可以使用 2 个 postgres 资源:

  1. postgres_session 针对 PostgreSQL 数据库

    测试 SQL 命令 运行
    sql = postgres_session('username', 'password', 'host', 'port')
    describe sql.query('SELECT * FROM pg_shadow WHERE passwd IS NULL;') do
      its('output') { should eq '' }
    end
    
  2. postgres_conf 测试 Postgre 的配置文件内容SQL

    describe postgres_conf do
      its('max_connections') { should eq '5' }
    end