producer-core 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/features/actions/mkdir.feature +14 -0
- data/features/steps/remote_steps.rb +8 -0
- data/features/tests/has_dir.feature +23 -0
- data/lib/producer/core/actions/mkdir.rb +15 -0
- data/lib/producer/core/condition/dsl.rb +1 -0
- data/lib/producer/core/remote/fs.rb +10 -0
- data/lib/producer/core/task/dsl.rb +1 -0
- data/lib/producer/core/tests/has_dir.rb +11 -0
- data/lib/producer/core/version.rb +1 -1
- data/lib/producer/core.rb +2 -0
- data/spec/producer/core/actions/file_writer_spec.rb +4 -4
- data/spec/producer/core/actions/mkdir_spec.rb +23 -0
- data/spec/producer/core/condition/dsl_spec.rb +1 -1
- data/spec/producer/core/remote/fs_spec.rb +51 -0
- data/spec/producer/core/task/dsl_spec.rb +1 -1
- data/spec/producer/core/tests/has_dir_spec.rb +28 -0
- metadata +11 -3
- data/features/recipes/env.feature +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ed15ccec37cb38bc7c4ea42a911708acd30630f
|
4
|
+
data.tar.gz: bc36933dae78ef8311eb2e840ab22cbb2927dd11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9128d8070fb39fa4cc1e4a6ba1ea9a19c29ac32b2088a412d2da5b66a5560b3b6bf9332a689423d246f936eb6aa9552b0e97a131679e11670048be996f194ceb
|
7
|
+
data.tar.gz: 1be0962d9d254e3f33a04636b66413084f957541456d7202cf120da1085d4cd33b856dcb464532356188e9123e77127be1ffa390a22caf3e283df3afd2919d99
|
@@ -0,0 +1,14 @@
|
|
1
|
+
@sshd
|
2
|
+
Feature: `mkdir' task action
|
3
|
+
|
4
|
+
Scenario: creates directory given as argument
|
5
|
+
Given a recipe with:
|
6
|
+
"""
|
7
|
+
target 'some_host.test'
|
8
|
+
|
9
|
+
task :create_some_dir do
|
10
|
+
mkdir 'some_directory'
|
11
|
+
end
|
12
|
+
"""
|
13
|
+
When I successfully execute the recipe
|
14
|
+
Then the remote directory "some_directory" must exists
|
@@ -1,7 +1,15 @@
|
|
1
|
+
Given /^a remote directory named "([^"]+)"$/ do |path|
|
2
|
+
create_dir path
|
3
|
+
end
|
4
|
+
|
1
5
|
Given /^a remote file named "([^"]+)"$/ do |file_name|
|
2
6
|
write_file file_name, ''
|
3
7
|
end
|
4
8
|
|
9
|
+
Then /^the remote directory "([^"]+)" should exists$/ do |path|
|
10
|
+
check_directory_presence([path], true)
|
11
|
+
end
|
12
|
+
|
5
13
|
Then /^the remote file "([^"]+)" should contain "([^"]+)"/ do |path, content|
|
6
14
|
check_file_content path, content, true
|
7
15
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
@sshd
|
2
|
+
Feature: `has_dir' condition keyword
|
3
|
+
|
4
|
+
Background:
|
5
|
+
Given a recipe with:
|
6
|
+
"""
|
7
|
+
target 'some_host.test'
|
8
|
+
|
9
|
+
task :testing_directory_existence do
|
10
|
+
condition { has_dir 'some_directory' }
|
11
|
+
|
12
|
+
echo 'evaluated'
|
13
|
+
end
|
14
|
+
"""
|
15
|
+
|
16
|
+
Scenario: succeeds when directory exists
|
17
|
+
Given a remote directory named "some_directory"
|
18
|
+
When I successfully execute the recipe
|
19
|
+
Then the output must contain "evaluated"
|
20
|
+
|
21
|
+
Scenario: fails when directory does not exist
|
22
|
+
When I successfully execute the recipe
|
23
|
+
Then the output must not contain "evaluated"
|
@@ -14,12 +14,22 @@ module Producer
|
|
14
14
|
@sftp ||= @remote.session.sftp.connect
|
15
15
|
end
|
16
16
|
|
17
|
+
def dir?(path)
|
18
|
+
sftp.stat!(path).directory?
|
19
|
+
rescue Net::SFTP::StatusException
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
17
23
|
def file?(path)
|
18
24
|
sftp.stat!(path).file?
|
19
25
|
rescue Net::SFTP::StatusException
|
20
26
|
false
|
21
27
|
end
|
22
28
|
|
29
|
+
def mkdir(path)
|
30
|
+
sftp.mkdir! path
|
31
|
+
end
|
32
|
+
|
23
33
|
def file_write(path, content)
|
24
34
|
sftp.file.open path, 'w' do |f|
|
25
35
|
f.write content
|
data/lib/producer/core.rb
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
require 'producer/core/action'
|
3
3
|
require 'producer/core/actions/echo'
|
4
4
|
require 'producer/core/actions/shell_command'
|
5
|
+
require 'producer/core/actions/mkdir'
|
5
6
|
require 'producer/core/actions/file_writer'
|
6
7
|
|
7
8
|
# condition tests (need to be defined before the condition DSL)
|
8
9
|
require 'producer/core/test'
|
10
|
+
require 'producer/core/tests/has_dir'
|
9
11
|
require 'producer/core/tests/has_env'
|
10
12
|
require 'producer/core/tests/has_file'
|
11
13
|
|
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Producer::Core
|
4
4
|
describe Actions::FileWriter do
|
5
|
-
let(:env)
|
6
|
-
let(:path)
|
7
|
-
let(:content)
|
8
|
-
subject(:writer)
|
5
|
+
let(:env) { Env.new }
|
6
|
+
let(:path) { 'some_path' }
|
7
|
+
let(:content) { 'some_content' }
|
8
|
+
subject(:writer) { Actions::FileWriter.new(env, path, content) }
|
9
9
|
|
10
10
|
describe '#apply' do
|
11
11
|
it 'writes content to file on remote filesystem' do
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Producer::Core
|
4
|
+
describe Actions::Mkdir do
|
5
|
+
let(:env) { Env.new }
|
6
|
+
let(:path) { 'some_path' }
|
7
|
+
subject(:mkdir) { Actions::Mkdir.new(env, path) }
|
8
|
+
|
9
|
+
describe '#apply' do
|
10
|
+
it 'creates directory on remote filesystem' do
|
11
|
+
expect(mkdir.fs).to receive(:mkdir).with(path)
|
12
|
+
mkdir.apply
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#path' do
|
17
|
+
it 'returns the path' do
|
18
|
+
expect(mkdir.path).to eq path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -6,7 +6,7 @@ module Producer::Core
|
|
6
6
|
let(:env) { double 'env' }
|
7
7
|
subject(:dsl) { Condition::DSL.new(env, &block) }
|
8
8
|
|
9
|
-
%w[has_env has_file].each do |test|
|
9
|
+
%w[has_dir has_env has_file].each do |test|
|
10
10
|
it "has `#{test}' test defined" do
|
11
11
|
expect(dsl).to respond_to test.to_sym
|
12
12
|
end
|
@@ -31,6 +31,45 @@ module Producer::Core
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
describe '#dir?' do
|
35
|
+
let(:sftp) { double('sftp').as_null_object }
|
36
|
+
let(:path) { 'some_directory_path' }
|
37
|
+
let(:stat) { double 'stat' }
|
38
|
+
|
39
|
+
before do
|
40
|
+
allow(fs).to receive(:sftp) { sftp }
|
41
|
+
allow(sftp).to receive(:stat!).with(path) { stat }
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when path given as argument is a directory' do
|
45
|
+
before { allow(stat).to receive(:directory?) { true } }
|
46
|
+
|
47
|
+
it 'returns true' do
|
48
|
+
expect(fs.dir? path).to be true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when path given as argument is not a directory' do
|
53
|
+
before { allow(stat).to receive(:directory?) { false } }
|
54
|
+
|
55
|
+
it 'returns false' do
|
56
|
+
expect(fs.dir? path).to be false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when querying the path raises a Net::SFTP::StatusException' do
|
61
|
+
before do
|
62
|
+
response = double 'response', code: '42', message: 'some message'
|
63
|
+
ex = Net::SFTP::StatusException.new(response)
|
64
|
+
allow(sftp).to receive(:stat!).with(path).and_raise(ex)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns false' do
|
68
|
+
expect(fs.dir? path).to be false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
34
73
|
# FIXME: We rely a lot on mocking net-sftp heavily, while we already use a
|
35
74
|
# part of net-ssh story helpers, which are more close to integration tests.
|
36
75
|
describe '#file?', :ssh do
|
@@ -73,6 +112,18 @@ module Producer::Core
|
|
73
112
|
end
|
74
113
|
end
|
75
114
|
|
115
|
+
describe '#mkdir' do
|
116
|
+
let(:sftp) { double 'sftp' }
|
117
|
+
let(:path) { 'some_directory_path' }
|
118
|
+
|
119
|
+
before { allow(fs).to receive(:sftp) { sftp } }
|
120
|
+
|
121
|
+
it 'creates the directory' do
|
122
|
+
expect(sftp).to receive(:mkdir!).with(path)
|
123
|
+
fs.mkdir path
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
76
127
|
describe '#file_write' do
|
77
128
|
let(:sftp) { double('sftp').as_null_object }
|
78
129
|
let(:file) { double('sftp').as_null_object }
|
@@ -6,7 +6,7 @@ module Producer::Core
|
|
6
6
|
let(:env) { Env.new }
|
7
7
|
subject(:dsl) { Task::DSL.new(env, &block) }
|
8
8
|
|
9
|
-
%w[echo sh file_write].each do |action|
|
9
|
+
%w[echo sh mkdir file_write].each do |action|
|
10
10
|
it "has `#{action}' action defined" do
|
11
11
|
expect(dsl).to respond_to action.to_sym
|
12
12
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Producer::Core
|
4
|
+
describe Tests::HasDir do
|
5
|
+
let(:env) { Env.new }
|
6
|
+
let(:path) { 'some_directory' }
|
7
|
+
subject(:has_dir) { Tests::HasDir.new(env, path) }
|
8
|
+
|
9
|
+
it 'is a kind of test' do
|
10
|
+
expect(has_dir).to be_a Test
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#verify', :ssh do
|
14
|
+
before { sftp_story }
|
15
|
+
|
16
|
+
it 'delegates the call on remote FS' do
|
17
|
+
expect(env.remote.fs).to receive(:dir?).with(path)
|
18
|
+
has_dir.verify
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns the dir existence' do
|
22
|
+
existence = double 'existence'
|
23
|
+
allow(env.remote.fs).to receive(:dir?) { existence }
|
24
|
+
expect(has_dir.verify).to be existence
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
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.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibault Jouan
|
@@ -110,10 +110,10 @@ files:
|
|
110
110
|
- bin/producer
|
111
111
|
- features/actions/echo.feature
|
112
112
|
- features/actions/file_write.feature
|
113
|
+
- features/actions/mkdir.feature
|
113
114
|
- features/actions/sh.feature
|
114
115
|
- features/cli/usage.feature
|
115
116
|
- features/recipes/ask.feature
|
116
|
-
- features/recipes/env.feature
|
117
117
|
- features/recipes/evaluation.feature
|
118
118
|
- features/recipes/macro.feature
|
119
119
|
- features/recipes/source.feature
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- features/support/ssh.rb
|
129
129
|
- features/tasks/condition.feature
|
130
130
|
- features/tasks/evaluation.feature
|
131
|
+
- features/tests/has_dir.feature
|
131
132
|
- features/tests/has_env.feature
|
132
133
|
- features/tests/has_file.feature
|
133
134
|
- features/tests/negated_test.feature
|
@@ -135,6 +136,7 @@ files:
|
|
135
136
|
- lib/producer/core/action.rb
|
136
137
|
- lib/producer/core/actions/echo.rb
|
137
138
|
- lib/producer/core/actions/file_writer.rb
|
139
|
+
- lib/producer/core/actions/mkdir.rb
|
138
140
|
- lib/producer/core/actions/shell_command.rb
|
139
141
|
- lib/producer/core/cli.rb
|
140
142
|
- lib/producer/core/condition.rb
|
@@ -150,6 +152,7 @@ files:
|
|
150
152
|
- lib/producer/core/task.rb
|
151
153
|
- lib/producer/core/task/dsl.rb
|
152
154
|
- lib/producer/core/test.rb
|
155
|
+
- lib/producer/core/tests/has_dir.rb
|
153
156
|
- lib/producer/core/tests/has_env.rb
|
154
157
|
- lib/producer/core/tests/has_file.rb
|
155
158
|
- lib/producer/core/version.rb
|
@@ -161,6 +164,7 @@ files:
|
|
161
164
|
- spec/producer/core/action_spec.rb
|
162
165
|
- spec/producer/core/actions/echo_spec.rb
|
163
166
|
- spec/producer/core/actions/file_writer_spec.rb
|
167
|
+
- spec/producer/core/actions/mkdir_spec.rb
|
164
168
|
- spec/producer/core/actions/shell_command_spec.rb
|
165
169
|
- spec/producer/core/cli_spec.rb
|
166
170
|
- spec/producer/core/condition/dsl_spec.rb
|
@@ -175,6 +179,7 @@ files:
|
|
175
179
|
- spec/producer/core/task/dsl_spec.rb
|
176
180
|
- spec/producer/core/task_spec.rb
|
177
181
|
- spec/producer/core/test_spec.rb
|
182
|
+
- spec/producer/core/tests/has_dir_spec.rb
|
178
183
|
- spec/producer/core/tests/has_env_spec.rb
|
179
184
|
- spec/producer/core/tests/has_file_spec.rb
|
180
185
|
- spec/producer/core/worker_spec.rb
|
@@ -208,10 +213,10 @@ summary: Provisioning tool
|
|
208
213
|
test_files:
|
209
214
|
- features/actions/echo.feature
|
210
215
|
- features/actions/file_write.feature
|
216
|
+
- features/actions/mkdir.feature
|
211
217
|
- features/actions/sh.feature
|
212
218
|
- features/cli/usage.feature
|
213
219
|
- features/recipes/ask.feature
|
214
|
-
- features/recipes/env.feature
|
215
220
|
- features/recipes/evaluation.feature
|
216
221
|
- features/recipes/macro.feature
|
217
222
|
- features/recipes/source.feature
|
@@ -226,6 +231,7 @@ test_files:
|
|
226
231
|
- features/support/ssh.rb
|
227
232
|
- features/tasks/condition.feature
|
228
233
|
- features/tasks/evaluation.feature
|
234
|
+
- features/tests/has_dir.feature
|
229
235
|
- features/tests/has_env.feature
|
230
236
|
- features/tests/has_file.feature
|
231
237
|
- features/tests/negated_test.feature
|
@@ -235,6 +241,7 @@ test_files:
|
|
235
241
|
- spec/producer/core/action_spec.rb
|
236
242
|
- spec/producer/core/actions/echo_spec.rb
|
237
243
|
- spec/producer/core/actions/file_writer_spec.rb
|
244
|
+
- spec/producer/core/actions/mkdir_spec.rb
|
238
245
|
- spec/producer/core/actions/shell_command_spec.rb
|
239
246
|
- spec/producer/core/cli_spec.rb
|
240
247
|
- spec/producer/core/condition/dsl_spec.rb
|
@@ -249,6 +256,7 @@ test_files:
|
|
249
256
|
- spec/producer/core/task/dsl_spec.rb
|
250
257
|
- spec/producer/core/task_spec.rb
|
251
258
|
- spec/producer/core/test_spec.rb
|
259
|
+
- spec/producer/core/tests/has_dir_spec.rb
|
252
260
|
- spec/producer/core/tests/has_env_spec.rb
|
253
261
|
- spec/producer/core/tests/has_file_spec.rb
|
254
262
|
- spec/producer/core/worker_spec.rb
|