Skip to content

Commit

Permalink
Build a complete mock OS object (#206)
Browse files Browse the repository at this point in the history
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 <adam@leff.co>
  • Loading branch information
adamleff authored and chris-rock committed Nov 9, 2017
1 parent 57387de commit a6373a8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/train/transports/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ class Connection < BaseConnection

def initialize(conf = nil)
super(conf)
@os = OS.new(self, family: 'unknown')
mock_os
@commands = {}
end

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)
Expand Down

0 comments on commit a6373a8

Please sign in to comment.