producer-core 0.3.8 → 0.3.9

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: 6a595e50ec520bdedf5e94b927b4dd8080a1acef
4
- data.tar.gz: 1c7c1f218276ed668d62c2d31f482e12a2f3ca40
3
+ metadata.gz: fba0f36e7a80a2897a17831da23ae1e9a7510ab3
4
+ data.tar.gz: 53ec1accae1569022521804498ea3eb379e6d6d8
5
5
  SHA512:
6
- metadata.gz: 727921d665f949d90cb092b3c653c698a7f1c82d2d48e1dd8f73adbb9905fd60c3b0348a6bfdc3c1e01b77c35f7843507768c3f18102d3e5e9ae8d16b748b9a6
7
- data.tar.gz: b2ece9b39a0be51041fd89f1b526c2d8042a252c3e4961be6cb9c621420c1f5bbccfab531df0885b3fa8f29473c07c32de8f30d46b2a6f7332bdccff2b2f9d73
6
+ metadata.gz: 024a23110ed45ca7ed46d78a4ca77e403de5283482aedc549b34f63b3aa14ab38d70f9defbab90e8b8ed935e28e1a116a0307cfc35d4b577dee77934a2364a3a
7
+ data.tar.gz: 8a5c854adfa2ae0d8bec10abe38995d9aaf7ce312013081a7b4b226c0a58519419457f33be3cd52142864e0be0317fc1e0527f09881a73308cd843a81b5fbd89
@@ -0,0 +1,27 @@
1
+ Feature: `template' task keyword
2
+
3
+ Background:
4
+ Given a file named "basic.erb" with:
5
+ """
6
+ basic template
7
+ """
8
+ Given a file named "variables.erb" with:
9
+ """
10
+ <%= @foo %>
11
+ """
12
+
13
+ Scenario: renders an ERB template file
14
+ Given a recipe with:
15
+ """
16
+ task(:echo_template) { echo template 'basic' }
17
+ """
18
+ When I execute the recipe
19
+ Then the output must contain "basic template"
20
+
21
+ Scenario: renders ERB with given attributes as member data
22
+ Given a recipe with:
23
+ """
24
+ task(:echo_template) { echo template('variables', foo: 'bar') }
25
+ """
26
+ When I execute the recipe
27
+ Then the output must contain "bar"
@@ -0,0 +1,26 @@
1
+ @sshd
2
+ Feature: `file_match' condition keyword
3
+
4
+ Background:
5
+ Given a recipe with:
6
+ """
7
+ task :file_match_test do
8
+ condition { file_match 'some_file', /\Asome_content\z/ }
9
+
10
+ echo 'evaluated'
11
+ end
12
+ """
13
+
14
+ Scenario: succeeds when file match pattern
15
+ Given a remote file named "some_file" with "some_content"
16
+ When I successfully execute the recipe on remote target
17
+ Then the output must contain "evaluated"
18
+
19
+ Scenario: fails when file does not match pattern
20
+ Given a remote file named "some_file" with "some_other_content"
21
+ When I successfully execute the recipe on remote target
22
+ Then the output must not contain "evaluated"
23
+
24
+ Scenario: fails when file does not exist
25
+ When I successfully execute the recipe on remote target
26
+ Then the output must not contain "evaluated"
@@ -36,6 +36,7 @@ module Producer
36
36
  define_test :sh, Tests::ShellCommandStatus
37
37
  define_test :file_contains, Tests::FileContains
38
38
  define_test :file_eq, Tests::FileEq
39
+ define_test :file_match, Tests::FileMatch
39
40
  define_test :env?, Tests::HasEnv
40
41
  define_test :executable?, Tests::HasExecutable
41
42
  define_test :dir?, Tests::HasDir
@@ -25,7 +25,7 @@ module Producer
25
25
  end
26
26
 
27
27
  def execute(command, output = '', error_output = '')
28
- channel = session.open_channel do |channel|
28
+ session.open_channel do |channel|
29
29
  channel.exec command do |ch, success|
30
30
  ch.on_data do |c, data|
31
31
  output << data
@@ -40,8 +40,7 @@ module Producer
40
40
  fail RemoteCommandExecutionError, command if exit_status != 0
41
41
  end
42
42
  end
43
- end
44
- channel.wait
43
+ end.wait
45
44
  output
46
45
  end
47
46
 
@@ -57,6 +57,25 @@ module Producer
57
57
  def get(key)
58
58
  @env[key]
59
59
  end
60
+
61
+ def template(path, variables = {})
62
+ path = "#{path}.erb"
63
+ tpl = ERB.new(File.read(path), nil, '-')
64
+ tpl.filename = path
65
+ tpl.result build_erb_binding variables
66
+ end
67
+
68
+
69
+ private
70
+
71
+ def build_erb_binding(variables)
72
+ Object.new.instance_eval do |o|
73
+ variables.each do |k, v|
74
+ o.instance_variable_set "@#{k}", v
75
+ end
76
+ binding
77
+ end
78
+ end
60
79
  end
61
80
  end
62
81
  end
@@ -7,6 +7,7 @@ module Producer
7
7
  content ? content.include?(arguments[1]) : false
8
8
  end
9
9
 
10
+
10
11
  private
11
12
 
12
13
  def file_content
@@ -0,0 +1,18 @@
1
+ module Producer
2
+ module Core
3
+ module Tests
4
+ class FileMatch < Test
5
+ def verify
6
+ !!(file_content =~ arguments[1])
7
+ end
8
+
9
+
10
+ private
11
+
12
+ def file_content
13
+ fs.file_read(arguments[0]) or ''
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -11,6 +11,7 @@ module Producer
11
11
  end
12
12
  end
13
13
 
14
+
14
15
  private
15
16
 
16
17
  def key
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Core
3
- VERSION = '0.3.8'.freeze
3
+ VERSION = '0.3.9'.freeze
4
4
  end
5
5
  end
data/lib/producer/core.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'erb'
1
2
  require 'etc'
2
3
  require 'forwardable'
3
4
  require 'optparse'
@@ -21,6 +22,7 @@ require 'producer/core/test'
21
22
  require 'producer/core/tests/condition_test'
22
23
  require 'producer/core/tests/file_contains'
23
24
  require 'producer/core/tests/file_eq'
25
+ require 'producer/core/tests/file_match'
24
26
  require 'producer/core/tests/has_dir'
25
27
  require 'producer/core/tests/has_env'
26
28
  require 'producer/core/tests/has_executable'
@@ -4,7 +4,7 @@ module Producer::Core
4
4
  module Actions
5
5
  describe Echo, :env do
6
6
  let(:text) { 'hello' }
7
- subject(:echo) { Echo.new(env, text) }
7
+ subject(:echo) { described_class.new(env, text) }
8
8
 
9
9
  it_behaves_like 'action'
10
10
 
@@ -6,7 +6,7 @@ module Producer::Core
6
6
  let(:path) { 'some_path' }
7
7
  let(:content) { 'some content' }
8
8
  let(:added_content) { ' added' }
9
- subject(:action) { FileAppend.new(env, path, added_content) }
9
+ subject(:action) { described_class.new(env, path, added_content) }
10
10
 
11
11
  it_behaves_like 'action'
12
12
 
@@ -7,7 +7,7 @@ module Producer::Core
7
7
  let(:pattern) { 'content' }
8
8
  let(:replacement) { 'other content' }
9
9
  let(:content) { 'some content' }
10
- subject(:action) { FileReplaceContent.new(env, path, pattern, replacement) }
10
+ subject(:action) { described_class.new(env, path, pattern, replacement) }
11
11
 
12
12
  it_behaves_like 'action'
13
13
 
@@ -5,7 +5,7 @@ module Producer::Core
5
5
  describe FileWriter, :env do
6
6
  let(:path) { 'some_path' }
7
7
  let(:content) { 'some_content' }
8
- subject(:writer) { FileWriter.new(env, path, content) }
8
+ subject(:writer) { described_class.new(env, path, content) }
9
9
 
10
10
  it_behaves_like 'action'
11
11
 
@@ -16,7 +16,7 @@ module Producer::Core
16
16
  end
17
17
 
18
18
  context 'when a mode was given' do
19
- subject(:writer) { FileWriter.new(env, path, content, 0600) }
19
+ subject(:writer) { described_class.new(env, path, content, 0600) }
20
20
 
21
21
  it 'specifies the given mode' do
22
22
  expect(remote_fs)
@@ -44,7 +44,7 @@ module Producer::Core
44
44
  end
45
45
 
46
46
  context 'when a mode was given' do
47
- subject(:writer) { FileWriter.new(env, path, content, 0600) }
47
+ subject(:writer) { described_class.new(env, path, content, 0600) }
48
48
 
49
49
  it 'returns the mode' do
50
50
  expect(writer.mode).to eq 0600
@@ -4,7 +4,7 @@ module Producer::Core
4
4
  module Actions
5
5
  describe Mkdir, :env do
6
6
  let(:path) { 'some_path' }
7
- subject(:mkdir) { Mkdir.new(env, path) }
7
+ subject(:mkdir) { described_class.new(env, path) }
8
8
 
9
9
  it_behaves_like 'action'
10
10
 
@@ -17,7 +17,7 @@ module Producer::Core
17
17
  end
18
18
 
19
19
  context 'when a mode was given' do
20
- subject(:mkdir) { Mkdir.new(env, path, 0700) }
20
+ subject(:mkdir) { described_class.new(env, path, 0700) }
21
21
 
22
22
  it 'changes the directory with given mode' do
23
23
  expect(remote_fs).to receive(:chmod).with(path, 0700)
@@ -5,7 +5,7 @@ module Producer::Core
5
5
  describe ShellCommand, :env do
6
6
  let(:command_args) { 'hello from remote host' }
7
7
  let(:command) { "echo #{command_args}" }
8
- subject(:sh) { ShellCommand.new(env, command) }
8
+ subject(:sh) { described_class.new(env, command) }
9
9
 
10
10
  it_behaves_like 'action'
11
11
 
@@ -9,6 +9,7 @@ module Producer::Core
9
9
  sh
10
10
  file_contains
11
11
  file_eq
12
+ file_match
12
13
  dir?
13
14
  env?
14
15
  executable?
@@ -87,7 +88,7 @@ module Producer::Core
87
88
  before { described_class.define_test(:some_test, some_test) }
88
89
 
89
90
  it 'returns an evaluated condition' do
90
- expect(condition).to be_a Condition
91
+ expect(condition).to be_a described_class
91
92
  end
92
93
 
93
94
  it 'evaluates the condition tests' do
@@ -4,7 +4,7 @@ module Producer::Core
4
4
  describe Prompter do
5
5
  let(:input) { StringIO.new }
6
6
  let(:output) { StringIO.new }
7
- subject(:prompter) { Prompter.new(input, output) }
7
+ subject(:prompter) { described_class.new(input, output) }
8
8
 
9
9
  describe '#initialize' do
10
10
  it 'assigns the given input' do
@@ -5,7 +5,7 @@ module Producer::Core
5
5
  describe FS do
6
6
  let(:sftp_file) { double 'sftp_file' }
7
7
  let(:sftp) { double('sftp', file: sftp_file) }
8
- subject(:fs) { FS.new(sftp) }
8
+ subject(:fs) { described_class.new(sftp) }
9
9
 
10
10
  describe '#initialize' do
11
11
  it 'assigns the sftp session' do
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module Producer::Core
4
4
  describe Remote do
5
5
  let(:hostname) { 'some_host.example' }
6
- subject(:remote) { Remote.new(hostname) }
6
+ subject(:remote) { described_class.new(hostname) }
7
7
 
8
8
  describe '#initialize' do
9
9
  it 'assigns the given hostname' do
@@ -4,7 +4,7 @@ require 'producer/core/testing'
4
4
  module Producer::Core
5
5
  module Testing
6
6
  describe MockRemote do
7
- subject(:remote) { MockRemote.new('some_host.example') }
7
+ subject(:remote) { described_class.new('some_host.example') }
8
8
 
9
9
  it 'is a remote' do
10
10
  expect(remote).to be_a Remote
@@ -5,7 +5,7 @@ module Producer::Core
5
5
  describe FileContains, :env do
6
6
  let(:filepath) { 'some_file' }
7
7
  let(:content) { 'some_content' }
8
- subject(:test) { FileContains.new(env, filepath, content) }
8
+ subject(:test) { described_class.new(env, filepath, content) }
9
9
 
10
10
  it_behaves_like 'test'
11
11
 
@@ -5,7 +5,7 @@ module Producer::Core
5
5
  describe FileEq, :env do
6
6
  let(:filepath) { 'some_file' }
7
7
  let(:content) { 'some content' }
8
- subject(:test) { FileEq.new(env, filepath, content) }
8
+ subject(:test) { described_class.new(env, filepath, content) }
9
9
 
10
10
  it_behaves_like 'test'
11
11
 
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ module Producer::Core
4
+ module Tests
5
+ describe FileMatch, :env do
6
+ let(:filepath) { 'some_file' }
7
+ let(:pattern) { /\Asome_content\z/ }
8
+ subject(:test) { described_class.new(env, filepath, pattern) }
9
+
10
+ it_behaves_like 'test'
11
+
12
+ describe '#verify' do
13
+ context 'when file matches the pattern' do
14
+ before do
15
+ allow(remote_fs)
16
+ .to receive(:file_read).with(filepath) { 'some_content' }
17
+ end
18
+
19
+ it 'returns true' do
20
+ expect(test.verify).to be true
21
+ end
22
+ end
23
+
24
+ context 'when file does not match the pattern' do
25
+ before do
26
+ allow(remote_fs).to receive(:file_read).with(filepath) { 'foo bar' }
27
+ end
28
+
29
+ it 'returns false' do
30
+ expect(test.verify).to be false
31
+ end
32
+ end
33
+
34
+ context 'when file does not exist' do
35
+ before do
36
+ allow(remote_fs).to receive(:file_read).with(filepath) { nil }
37
+ end
38
+
39
+ it 'returns false' do
40
+ expect(test.verify).to be false
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -4,7 +4,7 @@ module Producer::Core
4
4
  module Tests
5
5
  describe HasDir, :env do
6
6
  let(:path) { 'some_directory' }
7
- subject(:has_dir) { HasDir.new(env, path) }
7
+ subject(:has_dir) { described_class.new(env, path) }
8
8
 
9
9
  it_behaves_like 'test'
10
10
 
@@ -7,7 +7,7 @@ module Producer::Core
7
7
  let(:var_name) { 'SOME_VAR' }
8
8
  let(:var_value) { 'SOME_VALUE' }
9
9
  let(:remote_env) { { 'SOME_VAR' => 'SOME_VALUE' } }
10
- subject(:has_env) { HasEnv.new(env, var_name) }
10
+ subject(:has_env) { described_class.new(env, var_name) }
11
11
 
12
12
  it_behaves_like 'test'
13
13
 
@@ -42,7 +42,7 @@ module Producer::Core
42
42
  end
43
43
 
44
44
  context 'when var name and value are provided' do
45
- subject(:has_env) { HasEnv.new(env, var_name, var_value) }
45
+ subject(:has_env) { described_class.new(env, var_name, var_value) }
46
46
 
47
47
  describe '#verify' do
48
48
  context 'when remote environment var is defined' do
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module Producer::Core
4
4
  module Tests
5
5
  describe HasExecutable, :env do
6
- subject(:test) { HasExecutable.new(env, executable) }
6
+ subject(:test) { described_class.new(env, executable) }
7
7
 
8
8
  it_behaves_like 'test'
9
9
 
@@ -4,7 +4,7 @@ module Producer::Core
4
4
  module Tests
5
5
  describe HasFile, :env do
6
6
  let(:filepath) { 'some_file' }
7
- subject(:has_file) { HasFile.new(env, filepath) }
7
+ subject(:has_file) { described_class.new(env, filepath) }
8
8
 
9
9
  it_behaves_like 'test'
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: producer-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-26 00:00:00.000000000 Z
11
+ date: 2014-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -155,12 +155,14 @@ files:
155
155
  - features/task_condition.feature
156
156
  - features/task_nested_tasks.feature
157
157
  - features/task_target.feature
158
+ - features/task_template.feature
158
159
  - features/test_dir.feature
159
160
  - features/test_env.feature
160
161
  - features/test_executable.feature
161
162
  - features/test_file.feature
162
163
  - features/test_file_contains.feature
163
164
  - features/test_file_eq.feature
165
+ - features/test_file_match.feature
164
166
  - features/test_shell_command_status.feature
165
167
  - lib/producer/core.rb
166
168
  - lib/producer/core/action.rb
@@ -188,6 +190,7 @@ files:
188
190
  - lib/producer/core/tests/condition_test.rb
189
191
  - lib/producer/core/tests/file_contains.rb
190
192
  - lib/producer/core/tests/file_eq.rb
193
+ - lib/producer/core/tests/file_match.rb
191
194
  - lib/producer/core/tests/has_dir.rb
192
195
  - lib/producer/core/tests/has_env.rb
193
196
  - lib/producer/core/tests/has_executable.rb
@@ -223,6 +226,7 @@ files:
223
226
  - spec/producer/core/tests/condition_test_spec.rb
224
227
  - spec/producer/core/tests/file_contains_spec.rb
225
228
  - spec/producer/core/tests/file_eq_spec.rb
229
+ - spec/producer/core/tests/file_match_spec.rb
226
230
  - spec/producer/core/tests/has_dir_spec.rb
227
231
  - spec/producer/core/tests/has_env_spec.rb
228
232
  - spec/producer/core/tests/has_executable_spec.rb
@@ -293,12 +297,14 @@ test_files:
293
297
  - features/task_condition.feature
294
298
  - features/task_nested_tasks.feature
295
299
  - features/task_target.feature
300
+ - features/task_template.feature
296
301
  - features/test_dir.feature
297
302
  - features/test_env.feature
298
303
  - features/test_executable.feature
299
304
  - features/test_file.feature
300
305
  - features/test_file_contains.feature
301
306
  - features/test_file_eq.feature
307
+ - features/test_file_match.feature
302
308
  - features/test_shell_command_status.feature
303
309
  - spec/fixtures/recipes/empty.rb
304
310
  - spec/fixtures/recipes/raise.rb
@@ -327,6 +333,7 @@ test_files:
327
333
  - spec/producer/core/tests/condition_test_spec.rb
328
334
  - spec/producer/core/tests/file_contains_spec.rb
329
335
  - spec/producer/core/tests/file_eq_spec.rb
336
+ - spec/producer/core/tests/file_match_spec.rb
330
337
  - spec/producer/core/tests/has_dir_spec.rb
331
338
  - spec/producer/core/tests/has_env_spec.rb
332
339
  - spec/producer/core/tests/has_executable_spec.rb