Implement `has_executable' condition keyword
This commit is contained in:
parent
aa3694b58c
commit
eeab386216
30
features/tests/has_executable.feature
Normal file
30
features/tests/has_executable.feature
Normal file
@ -0,0 +1,30 @@
|
||||
@sshd
|
||||
Feature: `has_executable' condition keyword
|
||||
|
||||
Scenario: succeeds when remote executable is available
|
||||
Given a recipe with:
|
||||
"""
|
||||
target 'some_host.test'
|
||||
|
||||
task :testing_executable_availability do
|
||||
condition { has_executable '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_executable_availability do
|
||||
condition { has_executable 'some_non_existent_executable' }
|
||||
|
||||
echo 'evaluated'
|
||||
end
|
||||
"""
|
||||
When I successfully execute the recipe
|
||||
Then the output must not contain "evaluated"
|
@ -19,6 +19,7 @@ require 'producer/core/test'
|
||||
require 'producer/core/tests/file_contains'
|
||||
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/cli'
|
||||
|
@ -13,10 +13,11 @@ module Producer
|
||||
end
|
||||
end
|
||||
|
||||
define_test :file_contains, Tests::FileContains
|
||||
define_test :has_env, Tests::HasEnv
|
||||
define_test :has_dir, Tests::HasDir
|
||||
define_test :has_file, Tests::HasFile
|
||||
define_test :file_contains, Tests::FileContains
|
||||
define_test :has_env, Tests::HasEnv
|
||||
define_test :has_executable, Tests::HasExecutable
|
||||
define_test :has_dir, Tests::HasDir
|
||||
define_test :has_file, Tests::HasFile
|
||||
|
||||
attr_reader :block, :env, :tests
|
||||
|
||||
|
14
lib/producer/core/tests/has_executable.rb
Normal file
14
lib/producer/core/tests/has_executable.rb
Normal file
@ -0,0 +1,14 @@
|
||||
module Producer
|
||||
module Core
|
||||
module Tests
|
||||
class HasExecutable < Test
|
||||
def verify
|
||||
remote.execute("type #{arguments.first}")
|
||||
true
|
||||
rescue RemoteCommandExecutionError
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -7,7 +7,13 @@ module Producer::Core
|
||||
let(:env) { double 'env' }
|
||||
subject(:dsl) { DSL.new(env, &block) }
|
||||
|
||||
%w[file_contains has_dir has_env has_file].each do |test|
|
||||
%w[
|
||||
file_contains
|
||||
has_dir
|
||||
has_env
|
||||
has_executable
|
||||
has_file
|
||||
].each do |test|
|
||||
it "has `#{test}' test defined" do
|
||||
expect(dsl).to respond_to test.to_sym
|
||||
end
|
||||
|
29
spec/producer/core/tests/has_executable_spec.rb
Normal file
29
spec/producer/core/tests/has_executable_spec.rb
Normal file
@ -0,0 +1,29 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
module Tests
|
||||
describe HasExecutable, :env do
|
||||
subject(:has_env) { HasExecutable.new(env, executable) }
|
||||
|
||||
it_behaves_like 'test'
|
||||
|
||||
describe '#verify' do
|
||||
context 'executable exists' do
|
||||
let(:executable) { 'true' }
|
||||
|
||||
it 'returns true' do
|
||||
expect(has_env.verify).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'executable does not exist' do
|
||||
let(:executable) { 'some_non_existent_executable' }
|
||||
|
||||
it 'returns false' do
|
||||
expect(has_env.verify).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user