make postgres resource working in mock runner (for inspec check) (#1961)

* make postgres resource working in mock runner (for inspec check)

Signed-off-by: Christoph Hartmann <chris@lollyrock.com>

* keep nil for empty states

Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
This commit is contained in:
Christoph Hartmann 2017-06-26 06:16:09 -07:00 committed by Dominik Richter
parent 3bb98fa1e8
commit 9ac36bca30
2 changed files with 11 additions and 3 deletions

View file

@ -11,8 +11,7 @@ module Inspec::Resources
attr_reader :service, :data_dir, :conf_dir, :conf_path, :version, :cluster attr_reader :service, :data_dir, :conf_dir, :conf_path, :version, :cluster
def initialize def initialize
os = inspec.os if inspec.os.debian?
if os.debian?
# #
# https://wiki.debian.org/PostgreSql # https://wiki.debian.org/PostgreSql
# #
@ -40,8 +39,14 @@ module Inspec::Resources
@service = 'postgresql' @service = 'postgresql'
@service += "-#{@version}" if @version.to_f >= 9.4 @service += "-#{@version}" if @version.to_f >= 9.4
@conf_dir ||= @data_dir @conf_dir ||= @data_dir
verify_dirs verify_dirs
if !@version.nil? && !@conf_dir.empty?
@conf_path = File.join @conf_dir, 'postgresql.conf' @conf_path = File.join @conf_dir, 'postgresql.conf'
else
@conf_path = nil
return skip_resource 'Seems like PostgreSQL is not installed on your system'
end
end end
def to_s def to_s

View file

@ -24,6 +24,9 @@ module Inspec::Resources
def initialize(conf_path = nil) def initialize(conf_path = nil)
@conf_path = conf_path || inspec.postgres.conf_path @conf_path = conf_path || inspec.postgres.conf_path
if @conf_path.nil?
return skip_resource 'PostgreSQL conf path is not set'
end
@conf_dir = File.expand_path(File.dirname(@conf_path)) @conf_dir = File.expand_path(File.dirname(@conf_path))
@files_contents = {} @files_contents = {}
@content = nil @content = nil