producer-core 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7eb43f3bef9d4d62b0d7b1b74a2c8e71f58410e2
4
- data.tar.gz: ec652f99e4273ba9f603bcbc8e602abbbf583437
3
+ metadata.gz: b765ca3e62a5f6d52c70023568a7ff479eb90fb4
4
+ data.tar.gz: c742add987d14bc54d14933bf560d236e89f3be0
5
5
  SHA512:
6
- metadata.gz: 8e6d71a688e80c7a9e806c67de3f917dd51fb322af9dfb8f45379980579894423c149812e2f653dba3d11f460dce998ed9422c035c069d535d3857f133be081c
7
- data.tar.gz: 3ea4adbcebff73ab03680bee2f3c579df399738c6a5c638fdbd08755262bb219efd6fcdfc2be81d5f2f577b044bd9fdbf5ac0c3035db02de1e75959497537588
6
+ metadata.gz: a59aea6fc1ea7fc7ce56b0ce33adbd53095d895945f2a036a2057b2b9f9b5460047d92b94a5f20866b20756d39511ab38e032dca792f85e5b786d73995028792
7
+ data.tar.gz: dd3ef0d2f879a4d9e1dd4b1bd3cb2747c390070f9d7544db077d044aa76dda67e11883ff08b45e79042fba471a6ca2bf351e625f7ee67457b4d9272f74f0b959
@@ -19,3 +19,13 @@ Feature: `mkdir' task action
19
19
  When I successfully execute the recipe on remote target
20
20
  Then the remote directory "some_directory_0700" must have 0700 mode
21
21
  And the remote directory "some_directory_0500" must have 0500 mode
22
+
23
+ Scenario: creates directories recursively
24
+ Given a recipe with:
25
+ """
26
+ task :mkdir_action do
27
+ mkdir 'some/directory'
28
+ end
29
+ """
30
+ When I successfully execute the recipe on remote target
31
+ Then the remote directory "some/directory" must exists
@@ -10,4 +10,14 @@ Feature: `target' recipe keyword
10
10
  end
11
11
  """
12
12
  When I successfully execute the recipe
13
- Then the output must contain exactly "some_host.example\n"
13
+ Then the output must contain "some_host.example"
14
+
15
+ Scenario: returns current target when no arguments are provided
16
+ Given a recipe with:
17
+ """
18
+ target 'some_host.example'
19
+
20
+ env.output.puts target
21
+ """
22
+ When I successfully execute the recipe
23
+ Then the output must contain "some_host.example"
@@ -7,14 +7,16 @@ module Producer
7
7
  end
8
8
 
9
9
  def apply
10
- case arguments.size
11
- when 1
12
- fs.mkdir path
13
- when 2
14
- fs.mkdir path, mode
10
+ Pathname.new(path).descend do |p|
11
+ next if fs.dir? p
12
+ fs.mkdir p.to_s
13
+ fs.chmod p.to_s, mode if mode
15
14
  end
16
15
  end
17
16
 
17
+
18
+ private
19
+
18
20
  def path
19
21
  arguments.first
20
22
  end
@@ -26,8 +26,8 @@ module Producer
26
26
  instance_eval File.read("./#{filepath}.rb"), "#{filepath}.rb"
27
27
  end
28
28
 
29
- def target(hostname)
30
- env.target ||= hostname
29
+ def target(hostname = nil)
30
+ if hostname then env.target ||= hostname else env.target end
31
31
  end
32
32
 
33
33
  def task(name, *args, &block)
@@ -20,6 +20,10 @@ module Producer
20
20
  false
21
21
  end
22
22
 
23
+ def chmod(path, mode)
24
+ sftp.setstat! path, permissions: mode
25
+ end
26
+
23
27
  def mkdir(path, mode = nil)
24
28
  options = mode ? { permissions: mode } : {}
25
29
  sftp.mkdir! path, options
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Core
3
- VERSION = '0.3.6'.freeze
3
+ VERSION = '0.3.7'.freeze
4
4
  end
5
5
  end
data/lib/producer/core.rb CHANGED
@@ -1,6 +1,7 @@
1
+ require 'etc'
1
2
  require 'forwardable'
3
+ require 'pathname'
2
4
 
3
- require 'etc'
4
5
  require 'net/ssh'
5
6
  require 'net/sftp'
6
7
 
@@ -9,6 +9,8 @@ module Producer::Core
9
9
  it_behaves_like 'action'
10
10
 
11
11
  describe '#apply' do
12
+ before { allow(remote_fs).to receive(:dir?) { false } }
13
+
12
14
  it 'creates directory on remote filesystem' do
13
15
  expect(remote_fs).to receive(:mkdir).with(path)
14
16
  mkdir.apply
@@ -17,29 +19,28 @@ module Producer::Core
17
19
  context 'when a mode was given' do
18
20
  subject(:mkdir) { Mkdir.new(env, path, 0700) }
19
21
 
20
- it 'creates the directory with given mode' do
21
- expect(remote_fs).to receive(:mkdir).with(anything, 0700)
22
+ it 'changes the directory with given mode' do
23
+ expect(remote_fs).to receive(:chmod).with(path, 0700)
22
24
  mkdir.apply
23
25
  end
24
26
  end
25
- end
26
27
 
27
- describe '#path' do
28
- it 'returns the path' do
29
- expect(mkdir.path).to eq path
30
- end
31
- end
28
+ context 'when parent directories does not exists' do
29
+ let(:path) { 'some/path' }
32
30
 
33
- describe '#mode' do
34
- it 'returns nil' do
35
- expect(mkdir.mode).to be nil
31
+ it 'creates parent directories' do
32
+ expect(remote_fs).to receive(:mkdir).with('some').ordered
33
+ expect(remote_fs).to receive(:mkdir).with('some/path').ordered
34
+ mkdir.apply
35
+ end
36
36
  end
37
37
 
38
- context 'when a mode was given' do
39
- subject(:mkdir) { Mkdir.new(env, path, 0700) }
38
+ context 'when directory already exists' do
39
+ before { allow(remote_fs).to receive(:dir?) { true } }
40
40
 
41
- it 'returns the mode' do
42
- expect(mkdir.mode).to be 0700
41
+ it 'creates directory on remote filesystem' do
42
+ expect(remote_fs).not_to receive(:mkdir)
43
+ mkdir.apply
43
44
  end
44
45
  end
45
46
  end
@@ -38,6 +38,13 @@ module Producer::Core
38
38
  expect { recipe.target host }.not_to change { env.target }
39
39
  end
40
40
  end
41
+
42
+ context 'when no arguments are provided' do
43
+ it 'returns current target' do
44
+ recipe.target host
45
+ expect(recipe.target).to eq host
46
+ end
47
+ end
41
48
  end
42
49
 
43
50
  describe '#task' do
@@ -36,7 +36,7 @@ module TestEnvHelpers
36
36
  end
37
37
 
38
38
  def build_remote
39
- fs = RSpec::Mocks::Double.new('remote fs')
39
+ fs = instance_spy Producer::Core::Remote::FS
40
40
  remote = Producer::Core::Testing::MockRemote.new('some_host.test')
41
41
  remote.define_singleton_method(:fs) { fs }
42
42
  remote
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: producer-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan