Accept mode as argument in `mkdir' action
This commit is contained in:
parent
5cb6296057
commit
94f6bbb4aa
@ -12,3 +12,17 @@ Feature: `mkdir' task action
|
|||||||
"""
|
"""
|
||||||
When I successfully execute the recipe
|
When I successfully execute the recipe
|
||||||
Then the remote directory "some_directory" must exists
|
Then the remote directory "some_directory" must exists
|
||||||
|
|
||||||
|
Scenario: creates directory with given permissions
|
||||||
|
Given a recipe with:
|
||||||
|
"""
|
||||||
|
target 'some_host.test'
|
||||||
|
|
||||||
|
task :create_some_dir do
|
||||||
|
mkdir '0700_directory', 0700
|
||||||
|
mkdir '0500_directory', 0500
|
||||||
|
end
|
||||||
|
"""
|
||||||
|
When I successfully execute the recipe
|
||||||
|
Then the remote directory "0700_directory" must have 0700 mode
|
||||||
|
And the remote directory "0500_directory" must have 0500 mode
|
||||||
|
@ -22,9 +22,16 @@ Then /^the remote file "([^"]+)" must contain exactly "([^"]+)"$/ do |path, cont
|
|||||||
check_exact_file_content path, content
|
check_exact_file_content path, content
|
||||||
end
|
end
|
||||||
|
|
||||||
Then /^the remote file "([^"]+)" must have (\d+) mode$/ do |path, mode|
|
def stat_mode(path)
|
||||||
in_current_dir do
|
in_current_dir do
|
||||||
puts path, ('%o' % [File::Stat.new(path).mode])[-4, 4], mode
|
('%o' % [File::Stat.new(path).mode])[-4, 4]
|
||||||
expect(('%o' % [File::Stat.new(path).mode])[-4, 4]).to match mode
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Then /^the remote file "([^"]+)" must have (\d+) mode$/ do |path, mode|
|
||||||
|
expect(stat_mode path).to eq mode
|
||||||
|
end
|
||||||
|
|
||||||
|
Then /^the remote directory "([^"]+)" must have (\d+) mode$/ do |path, mode|
|
||||||
|
expect(stat_mode path).to eq mode
|
||||||
|
end
|
||||||
|
@ -3,12 +3,21 @@ module Producer
|
|||||||
module Actions
|
module Actions
|
||||||
class Mkdir < Action
|
class Mkdir < Action
|
||||||
def apply
|
def apply
|
||||||
fs.mkdir path
|
case arguments.size
|
||||||
|
when 1
|
||||||
|
fs.mkdir path
|
||||||
|
when 2
|
||||||
|
fs.mkdir path, mode
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def path
|
def path
|
||||||
arguments.first
|
arguments.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mode
|
||||||
|
arguments[1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,8 +20,9 @@ module Producer
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def mkdir(path)
|
def mkdir(path, mode = nil)
|
||||||
sftp.mkdir! path
|
options = mode ? { permissions: mode } : {}
|
||||||
|
sftp.mkdir! path, options
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_read(path)
|
def file_read(path)
|
||||||
|
@ -13,6 +13,15 @@ module Producer::Core
|
|||||||
expect(remote_fs).to receive(:mkdir).with(path)
|
expect(remote_fs).to receive(:mkdir).with(path)
|
||||||
mkdir.apply
|
mkdir.apply
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when a mode was given' do
|
||||||
|
subject(:mkdir) { Mkdir.new(env, path, 0700) }
|
||||||
|
|
||||||
|
it 'creates the directory with given mode' do
|
||||||
|
expect(remote_fs).to receive(:mkdir).with(anything, 0700)
|
||||||
|
mkdir.apply
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#path' do
|
describe '#path' do
|
||||||
@ -20,6 +29,20 @@ module Producer::Core
|
|||||||
expect(mkdir.path).to eq path
|
expect(mkdir.path).to eq path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#mode' do
|
||||||
|
it 'returns nil' do
|
||||||
|
expect(mkdir.mode).to be nil
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when a mode was given' do
|
||||||
|
subject(:mkdir) { Mkdir.new(env, path, 0700) }
|
||||||
|
|
||||||
|
it 'returns the mode' do
|
||||||
|
expect(mkdir.mode).to be 0700
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -89,9 +89,16 @@ module Producer::Core
|
|||||||
let(:path) { 'some_directory_path' }
|
let(:path) { 'some_directory_path' }
|
||||||
|
|
||||||
it 'creates the directory' do
|
it 'creates the directory' do
|
||||||
expect(sftp).to receive(:mkdir!).with(path)
|
expect(sftp).to receive(:mkdir!).with(path, anything)
|
||||||
fs.mkdir path
|
fs.mkdir path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'specifies permissions from optional mode argument' do
|
||||||
|
expect(sftp).to receive(:mkdir!) do |_, options|
|
||||||
|
expect(options[:permissions]).to eq 0700
|
||||||
|
end
|
||||||
|
fs.mkdir path, 0700
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#file_read' do
|
describe '#file_read' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user