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
|
When I successfully execute the recipe on remote target
|
||||||
Then the remote directory "some_directory_0700" must have 0700 mode
|
Then the remote directory "some_directory_0700" must have 0700 mode
|
||||||
And the remote directory "some_directory_0500" must have 0500 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 'etc'
|
||||||
|
require 'forwardable'
|
||||||
|
require 'pathname'
|
||||||
|
|
||||||
require 'net/ssh'
|
require 'net/ssh'
|
||||||
require 'net/sftp'
|
require 'net/sftp'
|
||||||
|
|
||||||
|
@ -7,11 +7,12 @@ module Producer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def apply
|
def apply
|
||||||
case arguments.size
|
Pathname.new(path).descend do |p|
|
||||||
when 1
|
next if fs.dir? p
|
||||||
fs.mkdir path
|
case arguments.size
|
||||||
when 2
|
when 1 then fs.mkdir p.to_s
|
||||||
fs.mkdir path, mode
|
when 2 then fs.mkdir p.to_s, mode
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ module Producer::Core
|
|||||||
it_behaves_like 'action'
|
it_behaves_like 'action'
|
||||||
|
|
||||||
describe '#apply' do
|
describe '#apply' do
|
||||||
|
before { allow(remote_fs).to receive(:dir?) { false } }
|
||||||
|
|
||||||
it 'creates directory on remote filesystem' do
|
it 'creates directory on remote filesystem' do
|
||||||
expect(remote_fs).to receive(:mkdir).with(path)
|
expect(remote_fs).to receive(:mkdir).with(path)
|
||||||
mkdir.apply
|
mkdir.apply
|
||||||
@ -22,6 +24,25 @@ module Producer::Core
|
|||||||
mkdir.apply
|
mkdir.apply
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user