From a6373a8021cd89ba420aa9be03badba067863b6e Mon Sep 17 00:00:00 2001 From: Adam Leff Date: Thu, 9 Nov 2017 06:23:55 -0500 Subject: [PATCH] Build a complete mock OS object (#206) InSpec expects there to be four parameters on every OS object: name, release, family, and arch. When the mock backend is used, only "family" is ever populated. When evaluating blocks, such as an only_if block, when the mock backend is used, errors will be encountered if someone tries to do something like: os.name.include?('something') ... because `os.name` will be nil during an inspec check, for example. This change properly populates all four expected parameters of the OS whenever the mock backend is used. The `mock_os` method still allows for one-off setting of the value as needed for unit tests, but it's now merged with the default four values. Signed-off-by: Adam Leff --- lib/train/transports/mock.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/train/transports/mock.rb b/lib/train/transports/mock.rb index 82bb38f2..46aa0776 100644 --- a/lib/train/transports/mock.rb +++ b/lib/train/transports/mock.rb @@ -65,7 +65,7 @@ class Connection < BaseConnection def initialize(conf = nil) super(conf) - @os = OS.new(self, family: 'unknown') + mock_os @commands = {} end @@ -73,8 +73,9 @@ def uri 'mock://' end - def mock_os(value) - @os = OS.new(self, value) + def mock_os(value = {}) + os_params = { name: 'unknown', family: 'unknown', release: 'unknown', arch: 'unknown' }.merge(value) + @os = OS.new(self, os_params) end def mock_command(cmd, stdout = nil, stderr = nil, exit_status = 0)