From f2a8898434d3c55843300d5007fc770dfd567297 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Wed, 14 Oct 2015 23:25:01 +0200 Subject: [PATCH] allow mock command to support sha256 mocking of commands --- lib/train/transports/mock.rb | 4 +++- test/unit/transports/mock_test.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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