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

allow mock command to support sha256 mocking of commands #9

Merged
merged 1 commit into from
Oct 14, 2015
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
4 changes: 3 additions & 1 deletion lib/train/transports/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def mock_command(cmd, stdout = nil, stderr = nil, exit_status = 0)
end

def run_command(cmd)
@commands[cmd] || mock_command(cmd)
@commands[cmd] ||
@commands[Digest::SHA256.hexdigest cmd] ||
mock_command(cmd)
end

def file(path)
Expand Down
9 changes: 9 additions & 0 deletions test/unit/transports/mock_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# encoding: utf-8
require 'helper'
require 'train/transports/mock'
require 'digest/sha2'

describe 'mock transport' do
let(:transport) { Train::Transports::Mock.new }
Expand Down Expand Up @@ -44,6 +45,14 @@
connection.mock_command(cmd, nil, nil, code)
connection.run_command(cmd).exit_status.must_equal(code)
end

it 'can mock a command via its SHA2 sum' do
out = rand.to_s
cmd = rand.to_s
shacmd = Digest::SHA256.hexdigest cmd
connection.mock_command(shacmd, out)
connection.run_command(cmd).stdout.must_equal(out)
end
end

describe 'when accessing a mocked os' do
Expand Down