producer-core 0.1.5 → 0.1.6

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: 2806c20d86e7d0aa08f72a3005b5ee5456cad346
4
- data.tar.gz: 4c75c67cd9815e30849302aeb9021dcbaf4721a7
3
+ metadata.gz: 69bc1d881cfd85eea00037b60c396d9b09bf7bdd
4
+ data.tar.gz: 6d440b7bd0beb137b073d00c2096222bb7f2b58a
5
5
  SHA512:
6
- metadata.gz: 4cddfc09e41207a5d9f01a9e04bac5c7ec7f841e89ce1e225d073923e5555460461b92f93b2978508c1003d8bdd24c92f9f106e947226190ca165ef78ae10b75
7
- data.tar.gz: 3bace5c3bbba48e3727e380f96d5f4a31f11fd29e9a319a7c09b2e284c400c2b105352bca4b3ae4ebfcabb5159faba99b9d88fa4e47153dfd4ff747b92b70d92
6
+ metadata.gz: 837737ed2a5bc77959a9c0e7c8295acdc7a997884a63fd286035cb9d811191ac7097d93ed5fb3e24c0c8c0afe22db4d05ca6b45afefcc4f5a69af34da3595e74
7
+ data.tar.gz: 098654fa4620affd4eac4b89fb8906a57537c13b134b9ab8c1a47e48cff83cce96d48b8cdbeed4cd50df2de4e95fbdfa7cd9589c4f5be04dedee3810630cc26d
@@ -0,0 +1,15 @@
1
+ @sshd
2
+ Feature: `file_write' task action
3
+
4
+ Scenario: writes given data to given file path
5
+ Given a recipe with:
6
+ """
7
+ target 'some_host.test'
8
+
9
+ task :write_some_data do
10
+ file_write 'some_file', 'some_content'
11
+ end
12
+ """
13
+ When I execute the recipe
14
+ Then the exit status must be 0
15
+ And the remote file "some_file" must contain "some_content"
@@ -1,3 +1,7 @@
1
- Given(/^a remote file named "(.*?)"$/) do |file_name|
1
+ Given /^a remote file named "([^"]+)"$/ do |file_name|
2
2
  write_file file_name, ''
3
3
  end
4
+
5
+ Then /^the remote file "([^"]+)" should contain "([^"]+)"/ do |path, content|
6
+ check_file_content path, content, true
7
+ end
@@ -0,0 +1,19 @@
1
+ module Producer
2
+ module Core
3
+ module Actions
4
+ class FileWriter < Action
5
+ def apply
6
+ env.remote.fs.file_write path, content
7
+ end
8
+
9
+ def path
10
+ arguments[0]
11
+ end
12
+
13
+ def content
14
+ arguments[1]
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -17,6 +17,12 @@ module Producer
17
17
  rescue Net::SFTP::StatusException
18
18
  false
19
19
  end
20
+
21
+ def file_write(path, content)
22
+ sftp.file.open path, 'w' do |f|
23
+ f.write content
24
+ end
25
+ end
20
26
  end
21
27
  end
22
28
  end
@@ -19,6 +19,8 @@ module Producer
19
19
  define_action :echo, Actions::Echo
20
20
  define_action :sh, Actions::ShellCommand
21
21
 
22
+ define_action :file_write, Actions::FileWriter
23
+
22
24
  attr_accessor :actions
23
25
 
24
26
  def initialize(&block)
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Core
3
- VERSION = '0.1.5'
3
+ VERSION = '0.1.6'
4
4
  end
5
5
  end
data/lib/producer/core.rb CHANGED
@@ -2,6 +2,7 @@
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/file_writer'
5
6
 
6
7
  # condition tests (need to be defined before the condition DSL)
7
8
  require 'producer/core/test'
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module Producer::Core
4
+ describe Actions::FileWriter do
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
+
10
+ describe '#apply' do
11
+ it 'delegates the call to env.remote.fs.file_write method' do
12
+ expect(env.remote.fs).to receive(:file_write).with(path, content)
13
+ writer.apply
14
+ end
15
+ end
16
+
17
+ describe '#path' do
18
+ it 'returns the path' do
19
+ expect(writer.path).to eq path
20
+ end
21
+ end
22
+
23
+ describe '#content' do
24
+ it 'returns the content' do
25
+ expect(writer.content).to eq content
26
+ end
27
+ end
28
+ end
29
+ end
@@ -34,7 +34,7 @@ module Producer::Core
34
34
  # FIXME: We rely a lot on mocking net-sftp heavily, while we already use a
35
35
  # part of net-ssh story helpers, which are more close to integration tests.
36
36
  describe '#has_file?', :ssh do
37
- let(:file_path) { "some_file_path" }
37
+ let(:file_path) { 'some_file_path' }
38
38
  let(:stat) { double 'stat' }
39
39
 
40
40
  before do
@@ -72,5 +72,30 @@ module Producer::Core
72
72
  end
73
73
  end
74
74
  end
75
+
76
+ describe '#file_write' do
77
+ let(:sftp) { double('sftp').as_null_object }
78
+ let(:file) { double('sftp').as_null_object }
79
+ let(:path) { 'some_file_path' }
80
+ let(:content) { 'some_content' }
81
+
82
+ before do
83
+ allow(fs).to receive(:sftp) { sftp }
84
+ allow(sftp).to receive(:file) { file }
85
+ end
86
+
87
+ it 'opens the file' do
88
+ expect(file).to receive(:open).with(path, 'w')
89
+ fs.file_write path, content
90
+ end
91
+
92
+ it 'writes the content' do
93
+ expect(file).to receive(:open).with(any_args) do |&b|
94
+ expect(file).to receive(:write).with(content)
95
+ b.call file
96
+ end
97
+ fs.file_write path, content
98
+ end
99
+ end
75
100
  end
76
101
  end
@@ -94,8 +94,7 @@ module Producer::Core
94
94
  ch.sends_exec command
95
95
  ch.gets_data arguments
96
96
  end
97
- remote.execute command
98
- expect(story_completed?).to be
97
+ expect_story_completed { remote.execute command }
99
98
  end
100
99
 
101
100
  it 'returns the output' do
@@ -6,7 +6,7 @@ module Producer::Core
6
6
  let(:env) { double 'env' }
7
7
  subject(:dsl) { Task::DSL.new(&block) }
8
8
 
9
- %w[echo sh].each do |action|
9
+ %w[echo sh 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
@@ -29,10 +29,6 @@ module NetSSHStoryHelpers
29
29
  end
30
30
  end
31
31
 
32
- def story_completed?
33
- socket.script.events.empty?
34
- end
35
-
36
32
  def sftp_story
37
33
  story do |session|
38
34
  ch = session.opens_channel
@@ -48,4 +44,11 @@ module NetSSHStoryHelpers
48
44
  yield ch if block_given?
49
45
  end
50
46
  end
47
+
48
+ def expect_story_completed
49
+ raise 'there is no story to expect' if socket.script.events.empty?
50
+ yield
51
+ expect(socket.script.events)
52
+ .to be_empty, "#{socket.script.events.count} story events still pending"
53
+ end
51
54
  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.5
4
+ version: 0.1.6
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_write.feature
112
113
  - features/actions/sh.feature
113
114
  - features/cli/usage.feature
114
115
  - features/recipes/env.feature
@@ -131,6 +132,7 @@ files:
131
132
  - lib/producer/core.rb
132
133
  - lib/producer/core/action.rb
133
134
  - lib/producer/core/actions/echo.rb
135
+ - lib/producer/core/actions/file_writer.rb
134
136
  - lib/producer/core/actions/shell_command.rb
135
137
  - lib/producer/core/cli.rb
136
138
  - lib/producer/core/condition.rb
@@ -154,6 +156,7 @@ files:
154
156
  - spec/fixtures/recipes/throw.rb
155
157
  - spec/producer/core/action_spec.rb
156
158
  - spec/producer/core/actions/echo_spec.rb
159
+ - spec/producer/core/actions/file_writer_spec.rb
157
160
  - spec/producer/core/actions/shell_command_spec.rb
158
161
  - spec/producer/core/cli_spec.rb
159
162
  - spec/producer/core/condition/dsl_spec.rb
@@ -197,9 +200,10 @@ rubyforge_project:
197
200
  rubygems_version: 2.4.5
198
201
  signing_key:
199
202
  specification_version: 4
200
- summary: producer-core-0.1.5
203
+ summary: producer-core-0.1.6
201
204
  test_files:
202
205
  - features/actions/echo.feature
206
+ - features/actions/file_write.feature
203
207
  - features/actions/sh.feature
204
208
  - features/cli/usage.feature
205
209
  - features/recipes/env.feature
@@ -223,6 +227,7 @@ test_files:
223
227
  - spec/fixtures/recipes/throw.rb
224
228
  - spec/producer/core/action_spec.rb
225
229
  - spec/producer/core/actions/echo_spec.rb
230
+ - spec/producer/core/actions/file_writer_spec.rb
226
231
  - spec/producer/core/actions/shell_command_spec.rb
227
232
  - spec/producer/core/cli_spec.rb
228
233
  - spec/producer/core/condition/dsl_spec.rb