Support (key, value) form in env? condition keyword
This commit is contained in:
parent
44343d121b
commit
0485105e28
@ -21,7 +21,35 @@ Feature: `env?' condition keyword
|
|||||||
target 'some_host.test'
|
target 'some_host.test'
|
||||||
|
|
||||||
task :testing_env_var_definition do
|
task :testing_env_var_definition do
|
||||||
condition { env? :inexistent_var }
|
condition { env? :non_existent_var }
|
||||||
|
|
||||||
|
echo 'evaluated'
|
||||||
|
end
|
||||||
|
"""
|
||||||
|
When I successfully execute the recipe
|
||||||
|
Then the output must not contain "evaluated"
|
||||||
|
|
||||||
|
Scenario: succeeds when remote environment variable value match
|
||||||
|
Given a recipe with:
|
||||||
|
"""
|
||||||
|
target 'some_host.test'
|
||||||
|
|
||||||
|
task :testing_env_var_value do
|
||||||
|
condition { env? :shell, '/bin/sh' }
|
||||||
|
|
||||||
|
echo 'evaluated'
|
||||||
|
end
|
||||||
|
"""
|
||||||
|
When I successfully execute the recipe
|
||||||
|
Then the output must contain "evaluated"
|
||||||
|
|
||||||
|
Scenario: fails when remote environment variable value does not match
|
||||||
|
Given a recipe with:
|
||||||
|
"""
|
||||||
|
target 'some_host.test'
|
||||||
|
|
||||||
|
task :testing_env_var_value do
|
||||||
|
condition { env? :shell, 'non_existent_shell' }
|
||||||
|
|
||||||
echo 'evaluated'
|
echo 'evaluated'
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,18 @@ module Producer
|
|||||||
module Tests
|
module Tests
|
||||||
class HasEnv < Test
|
class HasEnv < Test
|
||||||
def verify
|
def verify
|
||||||
remote.environment.key? arguments.first.to_s.upcase
|
case arguments.size
|
||||||
|
when 1
|
||||||
|
remote.environment.key? key
|
||||||
|
when 2
|
||||||
|
remote.environment[key] == arguments.last
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def key
|
||||||
|
arguments.first.to_s.upcase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,10 +3,11 @@ require 'spec_helper'
|
|||||||
module Producer::Core
|
module Producer::Core
|
||||||
module Tests
|
module Tests
|
||||||
describe HasEnv do
|
describe HasEnv do
|
||||||
let(:env) { Env.new }
|
let(:env) { Env.new }
|
||||||
let(:variable_name) { 'SOME_VAR' }
|
let(:var_name) { 'SOME_VAR' }
|
||||||
let(:remote_env) { { 'SOME_VAR' => 'SOME_VALUE' } }
|
let(:var_value) { 'SOME_VALUE' }
|
||||||
subject(:has_env) { HasEnv.new(env, variable_name) }
|
let(:remote_env) { { 'SOME_VAR' => 'SOME_VALUE' } }
|
||||||
|
subject(:has_env) { HasEnv.new(env, var_name) }
|
||||||
|
|
||||||
it_behaves_like 'test'
|
it_behaves_like 'test'
|
||||||
|
|
||||||
@ -14,26 +15,58 @@ module Producer::Core
|
|||||||
allow(env.remote).to receive(:environment) { remote_env }
|
allow(env.remote).to receive(:environment) { remote_env }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#verify' do
|
context 'when only var name is provided' do
|
||||||
context 'remote environment var is defined' do
|
describe '#verify' do
|
||||||
it 'returns true' do
|
context 'when remote environment var is defined' do
|
||||||
expect(has_env.verify).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when var name is given as a lowercase symbol' do
|
|
||||||
let(:variable_name) { :some_var }
|
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
expect(has_env.verify).to be true
|
expect(has_env.verify).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when var name is given as a lowercase symbol' do
|
||||||
|
let(:var_name) { :some_var }
|
||||||
|
|
||||||
|
it 'returns true' do
|
||||||
|
expect(has_env.verify).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when remote environment var is not defined' do
|
||||||
|
let(:var_name) { 'SOME_NON_EXISTENT_VAR' }
|
||||||
|
|
||||||
|
it 'returns false' do
|
||||||
|
expect(has_env.verify).to be false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'remote environment var is not defined' do
|
context 'when var name and value are provided' do
|
||||||
let(:variable_name) { 'SOME_NON_EXISTENT_VAR' }
|
subject(:has_env) { HasEnv.new(env, var_name, var_value) }
|
||||||
|
|
||||||
it 'returns false' do
|
describe '#verify' do
|
||||||
expect(has_env.verify).to be false
|
context 'when remote environment var is defined' do
|
||||||
|
context 'when value is the same' do
|
||||||
|
it 'returns true' do
|
||||||
|
expect(has_env.verify).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when value differs' do
|
||||||
|
let(:remote_env) { { 'SOME_VAR' => 'SOME_OTHER_VALUE' } }
|
||||||
|
|
||||||
|
it 'return false' do
|
||||||
|
expect(has_env.verify).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when remote environment var is not defined' do
|
||||||
|
let(:var_name) { 'SOME_NON_EXISTENT_VAR' }
|
||||||
|
|
||||||
|
it 'return false' do
|
||||||
|
expect(has_env.verify).to be false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user