Implement `` condition keyword (shell cmd status)
This commit is contained in:
parent
a2ca62e7f8
commit
7c6ac4c9d8
30
features/tests/shell_command_status.feature
Normal file
30
features/tests/shell_command_status.feature
Normal file
@ -0,0 +1,30 @@
|
||||
@sshd
|
||||
Feature: `` condition keyword
|
||||
|
||||
Scenario: succeeds when remote command execution is a success
|
||||
Given a recipe with:
|
||||
"""
|
||||
target 'some_host.test'
|
||||
|
||||
task :testing_remote_command do
|
||||
condition { `true` }
|
||||
|
||||
echo 'evaluated'
|
||||
end
|
||||
"""
|
||||
When I successfully execute the recipe
|
||||
Then the output must contain "evaluated"
|
||||
|
||||
Scenario: succeeds when remote executable is available
|
||||
Given a recipe with:
|
||||
"""
|
||||
target 'some_host.test'
|
||||
|
||||
task :testing_remote_command do
|
||||
condition { `false` }
|
||||
|
||||
echo 'evaluated'
|
||||
end
|
||||
"""
|
||||
When I successfully execute the recipe
|
||||
Then the output must not contain "evaluated"
|
@ -21,6 +21,7 @@ require 'producer/core/tests/has_dir'
|
||||
require 'producer/core/tests/has_env'
|
||||
require 'producer/core/tests/has_executable'
|
||||
require 'producer/core/tests/has_file'
|
||||
require 'producer/core/tests/shell_command_status'
|
||||
|
||||
require 'producer/core/cli'
|
||||
require 'producer/core/condition'
|
||||
|
@ -13,6 +13,7 @@ module Producer
|
||||
end
|
||||
end
|
||||
|
||||
define_test :`, Tests::ShellCommandStatus
|
||||
define_test :file_contains, Tests::FileContains
|
||||
define_test :has_env, Tests::HasEnv
|
||||
define_test :has_executable, Tests::HasExecutable
|
||||
|
18
lib/producer/core/tests/shell_command_status.rb
Normal file
18
lib/producer/core/tests/shell_command_status.rb
Normal file
@ -0,0 +1,18 @@
|
||||
module Producer
|
||||
module Core
|
||||
module Tests
|
||||
class ShellCommandStatus < Test
|
||||
def verify
|
||||
remote.execute(command)
|
||||
true
|
||||
rescue RemoteCommandExecutionError
|
||||
false
|
||||
end
|
||||
|
||||
def command
|
||||
arguments.first
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -8,6 +8,7 @@ module Producer::Core
|
||||
subject(:dsl) { DSL.new(env, &block) }
|
||||
|
||||
%w[
|
||||
`
|
||||
file_contains
|
||||
has_dir
|
||||
has_env
|
||||
|
34
spec/producer/core/tests/shell_command_status_spec.rb
Normal file
34
spec/producer/core/tests/shell_command_status_spec.rb
Normal file
@ -0,0 +1,34 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
module Tests
|
||||
describe ShellCommandStatus, :env do
|
||||
let(:command) { 'true' }
|
||||
subject(:test) { described_class.new(env, command) }
|
||||
|
||||
it_behaves_like 'test'
|
||||
|
||||
describe '#verify' do
|
||||
context 'command return status is 0' do
|
||||
it 'returns true' do
|
||||
expect(test.verify).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'command return status is not 0' do
|
||||
let(:command) { 'false' }
|
||||
|
||||
it 'returns false' do
|
||||
expect(test.verify).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#command' do
|
||||
it 'returns the first argument' do
|
||||
expect(test.command).to eq command
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user