Implement `file_eq' condition keyword
This commit is contained in:
parent
9e70e9aec4
commit
4a83e8c71a
26
features/test_file_eq.feature
Normal file
26
features/test_file_eq.feature
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
@sshd
|
||||||
|
Feature: `file_eq' condition keyword
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given a recipe with:
|
||||||
|
"""
|
||||||
|
task :file_eq_test do
|
||||||
|
condition { file_eq 'some_file', 'some content' }
|
||||||
|
|
||||||
|
echo 'evaluated'
|
||||||
|
end
|
||||||
|
"""
|
||||||
|
|
||||||
|
Scenario: succeeds when file content is expected content
|
||||||
|
Given a remote file named "some_file" with "some content"
|
||||||
|
When I successfully execute the recipe on remote target
|
||||||
|
Then the output must contain "evaluated"
|
||||||
|
|
||||||
|
Scenario: fails when file content is not expected content
|
||||||
|
Given a remote file named "some_file" with "some content padded"
|
||||||
|
When I successfully execute the recipe on remote target
|
||||||
|
Then the output must not contain "evaluated"
|
||||||
|
|
||||||
|
Scenario: fails when file does not exist
|
||||||
|
When I successfully execute the recipe on remote target
|
||||||
|
Then the output must not contain "evaluated"
|
@ -18,6 +18,7 @@ require 'producer/core/actions/file_writer'
|
|||||||
require 'producer/core/test'
|
require 'producer/core/test'
|
||||||
require 'producer/core/tests/condition_test'
|
require 'producer/core/tests/condition_test'
|
||||||
require 'producer/core/tests/file_contains'
|
require 'producer/core/tests/file_contains'
|
||||||
|
require 'producer/core/tests/file_eq'
|
||||||
require 'producer/core/tests/has_dir'
|
require 'producer/core/tests/has_dir'
|
||||||
require 'producer/core/tests/has_env'
|
require 'producer/core/tests/has_env'
|
||||||
require 'producer/core/tests/has_executable'
|
require 'producer/core/tests/has_executable'
|
||||||
|
@ -25,6 +25,7 @@ module Producer
|
|||||||
define_test :`, Tests::ShellCommandStatus
|
define_test :`, Tests::ShellCommandStatus
|
||||||
define_test :sh, Tests::ShellCommandStatus
|
define_test :sh, Tests::ShellCommandStatus
|
||||||
define_test :file_contains, Tests::FileContains
|
define_test :file_contains, Tests::FileContains
|
||||||
|
define_test :file_eq, Tests::FileEq
|
||||||
define_test :env?, Tests::HasEnv
|
define_test :env?, Tests::HasEnv
|
||||||
define_test :executable?, Tests::HasExecutable
|
define_test :executable?, Tests::HasExecutable
|
||||||
define_test :dir?, Tests::HasDir
|
define_test :dir?, Tests::HasDir
|
||||||
|
22
lib/producer/core/tests/file_eq.rb
Normal file
22
lib/producer/core/tests/file_eq.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
module Producer
|
||||||
|
module Core
|
||||||
|
module Tests
|
||||||
|
class FileEq < Test
|
||||||
|
def verify
|
||||||
|
file_content ? file_content == expected_content : false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def file_content
|
||||||
|
@file_content ||= fs.file_read(arguments[0])
|
||||||
|
end
|
||||||
|
|
||||||
|
def expected_content
|
||||||
|
arguments[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -11,6 +11,7 @@ module Producer::Core
|
|||||||
`
|
`
|
||||||
sh
|
sh
|
||||||
file_contains
|
file_contains
|
||||||
|
file_eq
|
||||||
dir?
|
dir?
|
||||||
env?
|
env?
|
||||||
executable?
|
executable?
|
||||||
|
45
spec/producer/core/tests/file_eq_spec.rb
Normal file
45
spec/producer/core/tests/file_eq_spec.rb
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
module Producer::Core
|
||||||
|
module Tests
|
||||||
|
describe FileEq, :env do
|
||||||
|
let(:filepath) { 'some_file' }
|
||||||
|
let(:content) { 'some content' }
|
||||||
|
subject(:test) { FileEq.new(env, filepath, content) }
|
||||||
|
|
||||||
|
it_behaves_like 'test'
|
||||||
|
|
||||||
|
describe '#verify' do
|
||||||
|
context 'when file content matches' do
|
||||||
|
before do
|
||||||
|
allow(remote_fs).to receive(:file_read).with(filepath) { content }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true' do
|
||||||
|
expect(test.verify).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when file content does not match' do
|
||||||
|
before do
|
||||||
|
allow(remote_fs).to receive(:file_read).with(filepath) { 'foo bar' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false' do
|
||||||
|
expect(test.verify).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when file does not exist' do
|
||||||
|
before do
|
||||||
|
allow(remote_fs).to receive(:file_read).with(filepath) { nil }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false' do
|
||||||
|
expect(test.verify).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user