Implement basic `sh' task action feature:
* Executes a command on the remote host; * Forwards remote standard output.
This commit is contained in:
parent
8123cf5052
commit
f10914c7d7
26
features/actions/sh.feature
Normal file
26
features/actions/sh.feature
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
@sshd
|
||||||
|
Feature: sh task action
|
||||||
|
|
||||||
|
Scenario: executes command
|
||||||
|
Given a recipe with:
|
||||||
|
"""
|
||||||
|
target 'some_host.test'
|
||||||
|
|
||||||
|
task :some_task do
|
||||||
|
sh '\true'
|
||||||
|
end
|
||||||
|
"""
|
||||||
|
When I execute the recipe
|
||||||
|
Then the exit status must be 0
|
||||||
|
|
||||||
|
Scenario: forwards standard ouput
|
||||||
|
Given a recipe with:
|
||||||
|
"""
|
||||||
|
target 'some_host.test'
|
||||||
|
|
||||||
|
task :some_task do
|
||||||
|
sh '\echo from remote'
|
||||||
|
end
|
||||||
|
"""
|
||||||
|
When I execute the recipe
|
||||||
|
Then the output must contain "from remote"
|
@ -1,4 +1,5 @@
|
|||||||
require 'producer/core/action'
|
require 'producer/core/action'
|
||||||
|
require 'producer/core/actions/shell_command'
|
||||||
require 'producer/core/cli'
|
require 'producer/core/cli'
|
||||||
require 'producer/core/env'
|
require 'producer/core/env'
|
||||||
require 'producer/core/errors'
|
require 'producer/core/errors'
|
||||||
|
11
lib/producer/core/actions/shell_command.rb
Normal file
11
lib/producer/core/actions/shell_command.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
module Producer
|
||||||
|
module Core
|
||||||
|
module Actions
|
||||||
|
class ShellCommand < Action
|
||||||
|
def apply
|
||||||
|
env.output env.remote.execute(arguments.first)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -10,6 +10,8 @@ module Producer
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
define_action :sh, Actions::ShellCommand
|
||||||
|
|
||||||
attr_accessor :actions
|
attr_accessor :actions
|
||||||
|
|
||||||
def initialize(&block)
|
def initialize(&block)
|
||||||
|
27
spec/producer/core/actions/shell_command_spec.rb
Normal file
27
spec/producer/core/actions/shell_command_spec.rb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
module Producer::Core
|
||||||
|
describe Actions::ShellCommand do
|
||||||
|
let(:env) { Env.new }
|
||||||
|
let(:command_args) { 'hello from remote host'}
|
||||||
|
let(:command) { "echo #{command_args}" }
|
||||||
|
subject(:sh) { Actions::ShellCommand.new(env, command) }
|
||||||
|
|
||||||
|
describe '#apply' do
|
||||||
|
before do
|
||||||
|
env.output = StringIO.new
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'delegates the call to env.remote.execute method' do
|
||||||
|
expect(env.remote).to receive(:execute).with(command)
|
||||||
|
sh.apply
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'forwards the returned output to env.output' do
|
||||||
|
allow(env.remote).to receive(:execute) { command_args }
|
||||||
|
expect(env).to receive(:output).with(command_args)
|
||||||
|
sh.apply
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -6,6 +6,12 @@ module Producer::Core
|
|||||||
let(:env) { double('env') }
|
let(:env) { double('env') }
|
||||||
subject(:dsl) { Task::DSL.new &block }
|
subject(:dsl) { Task::DSL.new &block }
|
||||||
|
|
||||||
|
%w[sh].each do |action|
|
||||||
|
it "has `#{action}' action defined" do
|
||||||
|
expect(dsl).to respond_to action.to_sym
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '.define_action' do
|
describe '.define_action' do
|
||||||
it 'defines a new action keyword' do
|
it 'defines a new action keyword' do
|
||||||
Task::DSL.define_action(:some_action, Object)
|
Task::DSL.define_action(:some_action, Object)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user