producer-core 0.1.13 → 0.1.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5075625b8dd7462b61363dfca8186442ecf2df57
4
- data.tar.gz: fa274fc269efe57af84d363b116d248778b60756
3
+ metadata.gz: 1c2475905b4f530aaa6299d8ff7a85c05c588bb3
4
+ data.tar.gz: f2cfa1b86883199dee6760ae43dfbed5e8dcbe70
5
5
  SHA512:
6
- metadata.gz: 7cebd961ba388776c216f61c5c7acbeb1b764b9140e59dffe4ea14d0859e446e0ff7b9b56d643b671bcc364333d2d62dc8b110ce20d8fd257e33958684815e29
7
- data.tar.gz: 501ed6a4b3782ea91b689331a99b7fade6037e0e5bf0120dfb1f95384b3d8544e2dc69916ee4083fdc7788cd4b5ce597b8be57abd1a766a33e676cd981745502
6
+ metadata.gz: 6b7b4f2e271d4731f99256bc3f44be758e821b1ec44c82ace19cf3c59b846ef1d77dc7bb433159ba2686fdd5acf7aad632b6269e520202725a790770cf373d7d
7
+ data.tar.gz: 7dda9db4a723a9d479ff4e589bb9d3dbb9295d8dc939320287021b35b42468e12e22d4f5a8a91da590bd28983e89fe37dcf54c105fe99c5749095b922af98511
@@ -0,0 +1,17 @@
1
+ @sshd
2
+ Feature: `file_append' task action
3
+
4
+ Background:
5
+ Given a remote file named "some_file" with "some content"
6
+
7
+ Scenario: appends given content to requested file
8
+ Given a recipe with:
9
+ """
10
+ target 'some_host.test'
11
+
12
+ task :append_content_to_file do
13
+ file_append 'some_file', ' added'
14
+ end
15
+ """
16
+ When I successfully execute the recipe
17
+ Then the remote file "some_file" must contain exactly "some content added"
@@ -4,7 +4,7 @@ Feature: `file_replace_content' task action
4
4
  Background:
5
5
  Given a remote file named "some_file" with "some content"
6
6
 
7
- Scenario: replace a string by another in the requested file
7
+ Scenario: replaces a string by another in the requested file
8
8
  Given a recipe with:
9
9
  """
10
10
  target 'some_host.test'
@@ -13,19 +13,17 @@ Feature: `file_replace_content' task action
13
13
  file_replace_content 'some_file', 'content', 'other content'
14
14
  end
15
15
  """
16
- When I execute the recipe
17
- Then the exit status must be 0
16
+ When I successfully execute the recipe
18
17
  And the remote file "some_file" must contain exactly "some other content"
19
18
 
20
- Scenario: replace a regular expression by a string in the requested file
19
+ Scenario: replaces a regular expression by a string in the requested file
21
20
  Given a recipe with:
22
21
  """
23
22
  target 'some_host.test'
24
23
 
25
- task :replace_string_in_file do
24
+ task :replace_regexp_in_file do
26
25
  file_replace_content 'some_file', /\w+\z/, 'other content'
27
26
  end
28
27
  """
29
- When I execute the recipe
30
- Then the exit status must be 0
28
+ When I successfully execute the recipe
31
29
  And the remote file "some_file" must contain exactly "some other content"
@@ -10,6 +10,5 @@ Feature: `file_write' task action
10
10
  file_write 'some_file', 'some_content'
11
11
  end
12
12
  """
13
- When I execute the recipe
14
- Then the exit status must be 0
13
+ When I successfully execute the recipe
15
14
  And the remote file "some_file" must contain "some_content"
@@ -0,0 +1,23 @@
1
+ module Producer
2
+ module Core
3
+ module Actions
4
+ class FileAppend < Action
5
+ def apply
6
+ fs.file_write path, combined_content
7
+ end
8
+
9
+ def path
10
+ arguments[0]
11
+ end
12
+
13
+ def content
14
+ arguments[1]
15
+ end
16
+
17
+ def combined_content
18
+ fs.file_read(path) + content
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -3,7 +3,8 @@ module Producer
3
3
  module Actions
4
4
  class ShellCommand < Action
5
5
  def apply
6
- output.puts remote.execute(arguments.first)
6
+ remote.execute(arguments.first, output)
7
+ output.puts
7
8
  end
8
9
  end
9
10
  end
@@ -23,9 +23,8 @@ module Producer
23
23
  @fs ||= Remote::FS.new(session.sftp.connect)
24
24
  end
25
25
 
26
- def execute(command)
27
- output = ''
28
- session.open_channel do |channel|
26
+ def execute(command, output = '')
27
+ channel = session.open_channel do |channel|
29
28
  channel.exec command do |ch, success|
30
29
  ch.on_data do |c, data|
31
30
  output << data
@@ -37,7 +36,7 @@ module Producer
37
36
  end
38
37
  end
39
38
  end
40
- session.loop
39
+ channel.wait
41
40
  output
42
41
  end
43
42
 
@@ -13,9 +13,11 @@ module Producer
13
13
  define_action :echo, Actions::Echo
14
14
  define_action :sh, Actions::ShellCommand
15
15
 
16
- define_action :mkdir, Actions::Mkdir
17
- define_action :file_write, Actions::FileWriter
16
+ define_action :mkdir, Actions::Mkdir
17
+
18
+ define_action :file_append, Actions::FileAppend
18
19
  define_action :file_replace_content, Actions::FileReplaceContent
20
+ define_action :file_write, Actions::FileWriter
19
21
 
20
22
  attr_reader :env, :block, :actions
21
23
 
@@ -6,18 +6,20 @@ module Producer
6
6
  raise 'no session for mock remote!'
7
7
  end
8
8
 
9
- def execute(command)
9
+ def execute(command, output = '')
10
10
  tokens = command.split
11
11
  program = tokens.shift
12
12
 
13
13
  case program
14
14
  when 'echo'
15
- tokens.join ' '
15
+ output << tokens.join(' ')
16
16
  when 'true'
17
- ''
17
+ output << ''
18
18
  when 'false'
19
19
  raise RemoteCommandExecutionError
20
20
  end
21
+
22
+ output
21
23
  end
22
24
  end
23
25
  end
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Core
3
- VERSION = '0.1.13'
3
+ VERSION = '0.1.14'
4
4
  end
5
5
  end
data/lib/producer/core.rb CHANGED
@@ -10,6 +10,7 @@ require 'producer/core/action'
10
10
  require 'producer/core/actions/echo'
11
11
  require 'producer/core/actions/shell_command'
12
12
  require 'producer/core/actions/mkdir'
13
+ require 'producer/core/actions/file_append'
13
14
  require 'producer/core/actions/file_replace_content'
14
15
  require 'producer/core/actions/file_writer'
15
16
 
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ module Producer::Core
4
+ module Actions
5
+ describe FileAppend, :env do
6
+ let(:path) { 'some_path' }
7
+ let(:content) { 'some content' }
8
+ let(:added_content) { ' added' }
9
+ subject(:action) { FileAppend.new(env, path, added_content) }
10
+
11
+ it_behaves_like 'action'
12
+
13
+ before { allow(remote_fs).to receive(:file_read).with(path) { content } }
14
+
15
+ describe '#apply' do
16
+ it 'appends given content to requested file on remote filesystem' do
17
+ expect(remote_fs)
18
+ .to receive(:file_write).with(path, action.combined_content)
19
+ action.apply
20
+ end
21
+ end
22
+
23
+ describe '#path' do
24
+ it 'returns the file path' do
25
+ expect(action.path).to eq path
26
+ end
27
+ end
28
+
29
+ describe '#content' do
30
+ it 'returns the content to append' do
31
+ expect(action.content).to eq added_content
32
+ end
33
+ end
34
+
35
+ describe '#combined_content' do
36
+ it 'returns original content and added content combined' do
37
+ expect(action.combined_content).to eq 'some content added'
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -79,6 +79,7 @@ module Producer::Core
79
79
  describe '#execute', :ssh do
80
80
  let(:arguments) { 'some remote command' }
81
81
  let(:command) { "echo #{arguments}" }
82
+ let(:output) { StringIO.new }
82
83
 
83
84
  it 'executes the given command in a new channel' do
84
85
  story_with_new_channel do |ch|
@@ -88,7 +89,7 @@ module Producer::Core
88
89
  expect_story_completed { remote.execute command }
89
90
  end
90
91
 
91
- it 'returns the output' do
92
+ it 'returns the command standard output output' do
92
93
  story_with_new_channel do |ch|
93
94
  ch.sends_exec command
94
95
  ch.gets_data arguments
@@ -96,6 +97,15 @@ module Producer::Core
96
97
  expect(remote.execute command).to eq arguments
97
98
  end
98
99
 
100
+ it 'writes command standard output to provided output' do
101
+ story_with_new_channel do |ch|
102
+ ch.sends_exec command
103
+ ch.gets_data arguments
104
+ end
105
+ remote.execute command, output
106
+ expect(output.string).to eq arguments
107
+ end
108
+
99
109
  it 'raises an exception when the exit status code is not 0' do
100
110
  story_with_new_channel do |ch|
101
111
  ch.sends_exec command
@@ -7,7 +7,14 @@ module Producer::Core
7
7
  let(:env) { Env.new }
8
8
  subject(:dsl) { DSL.new(env, &block) }
9
9
 
10
- %w[echo sh mkdir file_write file_replace_content].each do |action|
10
+ %w[
11
+ echo
12
+ sh
13
+ mkdir
14
+ file_append
15
+ file_replace_content
16
+ file_write
17
+ ].each do |action|
11
18
  it "has `#{action}' action defined" do
12
19
  expect(dsl).to respond_to action.to_sym
13
20
  end
@@ -15,7 +15,9 @@ module TestEnvHelpers
15
15
 
16
16
  def expect_execution(command)
17
17
  opts = { expected_from: caller.first }
18
- RSpec::Mocks.expect_message(env.remote, :execute, opts).with(command)
18
+ RSpec::Mocks
19
+ .expect_message(env.remote, :execute, opts)
20
+ .with(command, env.output)
19
21
  end
20
22
 
21
23
 
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.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
@@ -109,6 +109,7 @@ files:
109
109
  - Rakefile
110
110
  - bin/producer
111
111
  - features/actions/echo.feature
112
+ - features/actions/file_append.feature
112
113
  - features/actions/file_replace_content.feature
113
114
  - features/actions/file_write.feature
114
115
  - features/actions/mkdir.feature
@@ -139,6 +140,7 @@ files:
139
140
  - lib/producer/core.rb
140
141
  - lib/producer/core/action.rb
141
142
  - lib/producer/core/actions/echo.rb
143
+ - lib/producer/core/actions/file_append.rb
142
144
  - lib/producer/core/actions/file_replace_content.rb
143
145
  - lib/producer/core/actions/file_writer.rb
144
146
  - lib/producer/core/actions/mkdir.rb
@@ -171,6 +173,7 @@ files:
171
173
  - spec/fixtures/recipes/throw.rb
172
174
  - spec/producer/core/action_spec.rb
173
175
  - spec/producer/core/actions/echo_spec.rb
176
+ - spec/producer/core/actions/file_append_spec.rb
174
177
  - spec/producer/core/actions/file_replace_content_spec.rb
175
178
  - spec/producer/core/actions/file_writer_spec.rb
176
179
  - spec/producer/core/actions/mkdir_spec.rb
@@ -226,6 +229,7 @@ specification_version: 4
226
229
  summary: Provisioning tool
227
230
  test_files:
228
231
  - features/actions/echo.feature
232
+ - features/actions/file_append.feature
229
233
  - features/actions/file_replace_content.feature
230
234
  - features/actions/file_write.feature
231
235
  - features/actions/mkdir.feature
@@ -258,6 +262,7 @@ test_files:
258
262
  - spec/fixtures/recipes/throw.rb
259
263
  - spec/producer/core/action_spec.rb
260
264
  - spec/producer/core/actions/echo_spec.rb
265
+ - spec/producer/core/actions/file_append_spec.rb
261
266
  - spec/producer/core/actions/file_replace_content_spec.rb
262
267
  - spec/producer/core/actions/file_writer_spec.rb
263
268
  - spec/producer/core/actions/mkdir_spec.rb