Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: add mock backend initialization #119

Merged
merged 1 commit into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/train/transports/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Connection < BaseConnection
attr_reader :os

def initialize(conf = nil)
@conf = conf || {}
super(conf)
@os = OS.new(self, family: 'unknown')
@commands = {}
end
Expand All @@ -82,7 +82,7 @@ def mock_command(cmd, stdout = nil, stderr = nil, exit_status = 0)
end

def command_not_found(cmd)
if @conf[:verbose]
if @options[:verbose]
STDERR.puts('Command not mocked:')
STDERR.puts(' '+cmd.to_s.split("\n").join("\n "))
STDERR.puts(' SHA: ' + Digest::SHA256.hexdigest(cmd.to_s))
Expand All @@ -97,7 +97,7 @@ def run_command(cmd)
end

def file_not_found(path)
STDERR.puts('File not mocked: '+path.to_s) if @conf[:verbose]
STDERR.puts('File not mocked: '+path.to_s) if @options[:verbose]
File.new(self, path)
end

Expand Down
11 changes: 9 additions & 2 deletions test/unit/transports/mock_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,18 @@
end

describe 'when accessing a mocked file' do
JSON = Train.create('local').connection.file(__FILE__).to_json
RES = Train::Transports::Mock::Connection::File.from_json(JSON)
it 'handles a non-existing file' do
x = rand.to_s
f = connection.file(x)
f.must_be_kind_of Train::Transports::Mock::Connection::File
f.exist?.must_equal false
f.path.must_equal x
end

# tests if all fields between the local json and resulting mock file
# are equal
JSON = Train.create('local').connection.file(__FILE__).to_json
RES = Train::Transports::Mock::Connection::File.from_json(JSON)
%w{ content mode owner group }.each do |f|
it "can be initialized from json (field #{f})" do
RES.method(f).call.must_equal JSON[f]
Expand Down