Allow `mkdir' action to work recursively
This commit is contained in:
parent
1e3cd696c8
commit
bd66ec25e4
@ -19,3 +19,13 @@ Feature: `mkdir' task action
|
||||
When I successfully execute the recipe on remote target
|
||||
Then the remote directory "some_directory_0700" must have 0700 mode
|
||||
And the remote directory "some_directory_0500" must have 0500 mode
|
||||
|
||||
Scenario: creates directories recursively
|
||||
Given a recipe with:
|
||||
"""
|
||||
task :mkdir_action do
|
||||
mkdir 'some/directory'
|
||||
end
|
||||
"""
|
||||
When I successfully execute the recipe on remote target
|
||||
Then the remote directory "some/directory" must exists
|
||||
|
@ -1,6 +1,7 @@
|
||||
require 'forwardable'
|
||||
|
||||
require 'etc'
|
||||
require 'forwardable'
|
||||
require 'pathname'
|
||||
|
||||
require 'net/ssh'
|
||||
require 'net/sftp'
|
||||
|
||||
|
@ -7,11 +7,12 @@ module Producer
|
||||
end
|
||||
|
||||
def apply
|
||||
case arguments.size
|
||||
when 1
|
||||
fs.mkdir path
|
||||
when 2
|
||||
fs.mkdir path, mode
|
||||
Pathname.new(path).descend do |p|
|
||||
next if fs.dir? p
|
||||
case arguments.size
|
||||
when 1 then fs.mkdir p.to_s
|
||||
when 2 then fs.mkdir p.to_s, mode
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -9,6 +9,8 @@ module Producer::Core
|
||||
it_behaves_like 'action'
|
||||
|
||||
describe '#apply' do
|
||||
before { allow(remote_fs).to receive(:dir?) { false } }
|
||||
|
||||
it 'creates directory on remote filesystem' do
|
||||
expect(remote_fs).to receive(:mkdir).with(path)
|
||||
mkdir.apply
|
||||
@ -22,6 +24,25 @@ module Producer::Core
|
||||
mkdir.apply
|
||||
end
|
||||
end
|
||||
|
||||
context 'when parent directories does not exists' do
|
||||
let(:path) { 'some/path' }
|
||||
|
||||
it 'creates parent directories' do
|
||||
expect(remote_fs).to receive(:mkdir).with('some').ordered
|
||||
expect(remote_fs).to receive(:mkdir).with('some/path').ordered
|
||||
mkdir.apply
|
||||
end
|
||||
end
|
||||
|
||||
context 'when directory already exists' do
|
||||
before { allow(remote_fs).to receive(:dir?) { true } }
|
||||
|
||||
it 'creates directory on remote filesystem' do
|
||||
expect(remote_fs).not_to receive(:mkdir)
|
||||
mkdir.apply
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user