diff --git a/lib/train/transports/mock.rb b/lib/train/transports/mock.rb index 701b68f9..0fc7ed93 100644 --- a/lib/train/transports/mock.rb +++ b/lib/train/transports/mock.rb @@ -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) diff --git a/test/unit/transports/mock_test.rb b/test/unit/transports/mock_test.rb index 5cadbf68..39bebb42 100644 --- a/test/unit/transports/mock_test.rb +++ b/test/unit/transports/mock_test.rb @@ -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 } @@ -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