Support `mkdir' status attributes
This commit is contained in:
@@ -4,10 +4,23 @@ module Producer::Core
|
||||
module Actions
|
||||
describe Mkdir, :env do
|
||||
let(:path) { 'some_path' }
|
||||
subject(:mkdir) { described_class.new(env, path) }
|
||||
let(:options) { { } }
|
||||
subject(:mkdir) { described_class.new(env, path, options) }
|
||||
|
||||
it_behaves_like 'action'
|
||||
|
||||
describe '#initialize' do
|
||||
let(:options) { { mode: 0700, user: 'root' } }
|
||||
|
||||
it 'translates mode option as permissions' do
|
||||
expect(mkdir.options[:permissions]).to eq 0700
|
||||
end
|
||||
|
||||
it 'translates user option as owner' do
|
||||
expect(mkdir.options[:owner]).to eq 'root'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#apply' do
|
||||
before { allow(remote_fs).to receive(:dir?) { false } }
|
||||
|
||||
@@ -16,11 +29,11 @@ module Producer::Core
|
||||
mkdir.apply
|
||||
end
|
||||
|
||||
context 'when a mode was given' do
|
||||
subject(:mkdir) { described_class.new(env, path, 0700) }
|
||||
context 'when status options are given' do
|
||||
let(:options) { { group: 'wheel' } }
|
||||
|
||||
it 'changes the directory with given mode' do
|
||||
expect(remote_fs).to receive(:chmod).with(path, 0700)
|
||||
it 'changes the directory status with given options' do
|
||||
expect(remote_fs).to receive(:setstat).with(path, options)
|
||||
mkdir.apply
|
||||
end
|
||||
end
|
||||
@@ -38,7 +51,7 @@ module Producer::Core
|
||||
context 'when directory already exists' do
|
||||
before { allow(remote_fs).to receive(:dir?) { true } }
|
||||
|
||||
it 'creates directory on remote filesystem' do
|
||||
it 'does not create any directory' do
|
||||
expect(remote_fs).not_to receive(:mkdir)
|
||||
mkdir.apply
|
||||
end
|
||||
|
@@ -86,18 +86,12 @@ module Producer::Core
|
||||
end
|
||||
|
||||
describe '#mkdir' do
|
||||
let(:path) { 'some_directory_path' }
|
||||
let(:path) { 'some_directory_path' }
|
||||
let(:attributes) { { foo: :bar } }
|
||||
|
||||
it 'creates the directory' do
|
||||
expect(sftp).to receive(:mkdir!).with(path, anything)
|
||||
fs.mkdir path
|
||||
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
|
||||
expect(sftp).to receive(:mkdir!).with(path, attributes)
|
||||
fs.mkdir path, attributes
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -3,7 +3,8 @@ module Producer::Core
|
||||
include TestEnvHelpers
|
||||
|
||||
let(:arguments) { [:some, :arguments] }
|
||||
subject(:action) { described_class.new(env, *arguments) }
|
||||
let(:options) { { foo: :bar } }
|
||||
subject(:action) { described_class.new(env, *arguments, options) }
|
||||
|
||||
describe '#env' do
|
||||
it 'returns the assigned env' do
|
||||
@@ -17,6 +18,12 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
|
||||
describe '#options' do
|
||||
it 'returns the assigned options' do
|
||||
expect(action.options).to eq options
|
||||
end
|
||||
end
|
||||
|
||||
describe '#input' do
|
||||
it 'returns env input' do
|
||||
expect(action.input).to be env.input
|
||||
|
Reference in New Issue
Block a user