producer-core 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/features/cli_dry_run.feature +7 -1
- data/lib/producer/core/env.rb +3 -3
- data/lib/producer/core/logger_formatter.rb +8 -1
- data/lib/producer/core/version.rb +1 -1
- data/lib/producer/core/worker.rb +5 -0
- data/spec/producer/core/env_spec.rb +9 -2
- data/spec/producer/core/logger_formatter_spec.rb +8 -0
- data/spec/producer/core/worker_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0288c1cd99933e1e53201413bc0d8c90a6229204
|
4
|
+
data.tar.gz: 5d7aaef70745ce1b3396d775adfa94328a092151
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ca8cfca02bec39f6732bf697a2d9111119864c4e7a96176fb87669f0fc5215bb8ffd319cf5e39b90fdf984fb7edb3cfe22f75200f9e464ea89a73585cb60dac
|
7
|
+
data.tar.gz: 4786539f7a836eee916c4e278ba8b4206d32b5a6349c5c98e85609c638ce86b99300aa3295fab4d80e5c77cd8f8926a2fa32618beaa638b2fde8bed8c4a5011d
|
@@ -1,11 +1,17 @@
|
|
1
1
|
Feature: CLI dry run option
|
2
2
|
|
3
|
-
|
3
|
+
Background:
|
4
4
|
Given a recipe with:
|
5
5
|
"""
|
6
6
|
task :say_hello do
|
7
7
|
echo 'hello'
|
8
8
|
end
|
9
9
|
"""
|
10
|
+
|
11
|
+
Scenario: perfoms a trial run without applying actions
|
10
12
|
When I successfully execute the recipe with option -n
|
11
13
|
Then the output must not contain "hello"
|
14
|
+
|
15
|
+
Scenario: prints a warning before any output
|
16
|
+
When I successfully execute the recipe with option -n
|
17
|
+
Then the output must match /\AWarning: running in dry run mode, actions will NOT be applied/
|
data/lib/producer/core/env.rb
CHANGED
@@ -27,14 +27,14 @@ module Producer
|
|
27
27
|
def logger
|
28
28
|
@logger ||= begin
|
29
29
|
logger = Logger.new(output)
|
30
|
-
logger.level = verbose? ? Logger::INFO : Logger::
|
30
|
+
logger.level = verbose? ? Logger::INFO : Logger::WARN
|
31
31
|
logger.formatter = LoggerFormatter.new
|
32
32
|
logger
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def log(message)
|
37
|
-
logger.
|
36
|
+
def log(message, severity = :info)
|
37
|
+
logger.send severity, message
|
38
38
|
end
|
39
39
|
|
40
40
|
def verbose?
|
@@ -2,7 +2,14 @@ module Producer
|
|
2
2
|
module Core
|
3
3
|
class LoggerFormatter < Logger::Formatter
|
4
4
|
def call(severity, datetime, progname, message)
|
5
|
-
message + "\n"
|
5
|
+
prefix(severity) + message + "\n"
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def prefix(severity)
|
12
|
+
severity == 'WARN' ? 'Warning: ' : ''
|
6
13
|
end
|
7
14
|
end
|
8
15
|
end
|
data/lib/producer/core/worker.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Producer
|
2
2
|
module Core
|
3
3
|
class Worker
|
4
|
+
DRY_RUN_WARNING =
|
5
|
+
'running in dry run mode, actions will NOT be applied'.freeze
|
6
|
+
|
4
7
|
attr_accessor :env
|
5
8
|
|
6
9
|
def initialize(env)
|
@@ -8,6 +11,8 @@ module Producer
|
|
8
11
|
end
|
9
12
|
|
10
13
|
def process(tasks)
|
14
|
+
env.log DRY_RUN_WARNING, :warn if env.dry_run?
|
15
|
+
|
11
16
|
tasks.each { |t| process_task t }
|
12
17
|
end
|
13
18
|
|
@@ -113,8 +113,8 @@ module Producer::Core
|
|
113
113
|
expect(output.string).to include 'some message'
|
114
114
|
end
|
115
115
|
|
116
|
-
it 'has a log level of
|
117
|
-
expect(env.logger.level).to eq Logger::
|
116
|
+
it 'has a log level of WARN' do
|
117
|
+
expect(env.logger.level).to eq Logger::WARN
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'uses our formatter' do
|
@@ -135,6 +135,13 @@ module Producer::Core
|
|
135
135
|
expect(env.logger).to receive(:info).with 'message'
|
136
136
|
env.log 'message'
|
137
137
|
end
|
138
|
+
|
139
|
+
context 'when second argument is :warn' do
|
140
|
+
it 'logs a warning message through the assigned logger' do
|
141
|
+
expect(env.logger).to receive(:warn).with 'message'
|
142
|
+
env.log 'message', :warn
|
143
|
+
end
|
144
|
+
end
|
138
145
|
end
|
139
146
|
|
140
147
|
describe '#verbose?' do
|
@@ -13,6 +13,14 @@ module Producer::Core
|
|
13
13
|
it 'returns the given message with a line separator' do
|
14
14
|
expect(subject).to eq "#{message}\n"
|
15
15
|
end
|
16
|
+
|
17
|
+
context 'when severity is WARN' do
|
18
|
+
let(:severity) { 'WARN' }
|
19
|
+
|
20
|
+
it 'prefix the message with `Warning:\'' do
|
21
|
+
expect(subject).to match /\AWarning: #{message}/
|
22
|
+
end
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
end
|
@@ -10,6 +10,18 @@ module Producer::Core
|
|
10
10
|
expect(worker).to receive(:process_task).with(:some_task)
|
11
11
|
worker.process [:some_task]
|
12
12
|
end
|
13
|
+
|
14
|
+
context 'when dry run is enabled' do
|
15
|
+
before { allow(env).to receive(:dry_run?) { true } }
|
16
|
+
|
17
|
+
it 'warns dry run is enabled' do
|
18
|
+
expect(env).to receive(:log).with(
|
19
|
+
/\Arunning in dry run mode, actions will NOT be applied\z/,
|
20
|
+
:warn
|
21
|
+
)
|
22
|
+
worker.process []
|
23
|
+
end
|
24
|
+
end
|
13
25
|
end
|
14
26
|
|
15
27
|
describe '#process_task' do
|