producer-core 0.2.3 → 0.2.4
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 +7 -0
- data/features/cli/dry_run.feature +11 -0
- data/features/cli/usage.feature +1 -1
- data/features/cli/verbose.feature +42 -0
- data/features/steps/recipe_steps.rb +5 -0
- data/lib/producer/core.rb +1 -0
- data/lib/producer/core/action.rb +8 -0
- data/lib/producer/core/actions/echo.rb +4 -0
- data/lib/producer/core/actions/file_append.rb +4 -0
- data/lib/producer/core/actions/file_replace_content.rb +4 -0
- data/lib/producer/core/actions/file_writer.rb +4 -0
- data/lib/producer/core/actions/mkdir.rb +4 -0
- data/lib/producer/core/actions/shell_command.rb +4 -0
- data/lib/producer/core/cli.rb +28 -7
- data/lib/producer/core/env.rb +28 -3
- data/lib/producer/core/logger_formatter.rb +9 -0
- data/lib/producer/core/task.rb +4 -0
- data/lib/producer/core/version.rb +1 -1
- data/lib/producer/core/worker.rb +16 -1
- data/spec/producer/core/action_spec.rb +8 -0
- data/spec/producer/core/cli_spec.rb +76 -16
- data/spec/producer/core/env_spec.rb +61 -6
- data/spec/producer/core/logger_formatter_spec.rb +18 -0
- data/spec/producer/core/task_spec.rb +6 -0
- data/spec/producer/core/worker_spec.rb +41 -4
- data/spec/support/shared_action.rb +12 -0
- metadata +12 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a041918f9bce8b0f9b2e02f487f3f988a4a9f7d
|
4
|
+
data.tar.gz: bcbc76158d5d64315c987bf864f85710d91e40e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97ef8f650adc1065c930d87b20f2b03de4cc24086960752afcad1f0f455a24deaaeec2684037c3e732c3b5b6abc3092b8e90101c5e55a45f2addc6730cedd590
|
7
|
+
data.tar.gz: 3fc76e61d6eb8f70bafa2dcb7e175594d0db480fde82e9730e22290a9fe1fdd4ac7d51c5b16de640670fa640ba26117f36115e2635333e2b704aaa4d0f2cd689
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: CLI dry run option
|
2
|
+
|
3
|
+
Scenario: perfoms a trial run without applying actions
|
4
|
+
Given a recipe with:
|
5
|
+
"""
|
6
|
+
task :say_hello do
|
7
|
+
echo 'hello'
|
8
|
+
end
|
9
|
+
"""
|
10
|
+
When I successfully execute the recipe with option -n
|
11
|
+
Then the output must not contain "hello"
|
data/features/cli/usage.feature
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
Feature: CLI verbose option
|
2
|
+
|
3
|
+
Scenario: prints tasks name
|
4
|
+
Given a recipe with:
|
5
|
+
"""
|
6
|
+
task :say_hello do
|
7
|
+
end
|
8
|
+
"""
|
9
|
+
When I successfully execute the recipe with option -v
|
10
|
+
Then the output must match /Task:.+say_hello/
|
11
|
+
|
12
|
+
Scenario: prints whether condition is met
|
13
|
+
Given a recipe with:
|
14
|
+
"""
|
15
|
+
task :task_ok do
|
16
|
+
condition { true }
|
17
|
+
end
|
18
|
+
task :task_ko do
|
19
|
+
condition { false }
|
20
|
+
end
|
21
|
+
"""
|
22
|
+
When I successfully execute the recipe with option -v
|
23
|
+
Then the output must match /task_ok.+ condition: met.*task_ko.* condition: NOT met/
|
24
|
+
|
25
|
+
Scenario: prints actions info
|
26
|
+
Given a recipe with:
|
27
|
+
"""
|
28
|
+
task :say_hello do
|
29
|
+
echo 'hello message'
|
30
|
+
end
|
31
|
+
"""
|
32
|
+
When I successfully execute the recipe with option -v
|
33
|
+
Then the output must match /say_hello.+ action: echo/
|
34
|
+
|
35
|
+
Scenario: formats message with our simple logger
|
36
|
+
Given a recipe with:
|
37
|
+
"""
|
38
|
+
task :say_hello do
|
39
|
+
end
|
40
|
+
"""
|
41
|
+
When I successfully execute the recipe with option -v
|
42
|
+
Then the output must match /\ATask:.+say_hello.*\n.*condition/
|
@@ -11,6 +11,11 @@ When /^I successfully execute the recipe$/ do
|
|
11
11
|
assert_exit_status 0
|
12
12
|
end
|
13
13
|
|
14
|
+
When /^I successfully execute the recipe with option (-\w)$/ do |option|
|
15
|
+
run_simple "producer #{option} recipe.rb", false
|
16
|
+
assert_exit_status 0
|
17
|
+
end
|
18
|
+
|
14
19
|
When /^I execute the recipe interactively$/ do
|
15
20
|
run_interactive 'producer recipe.rb'
|
16
21
|
end
|
data/lib/producer/core.rb
CHANGED
@@ -28,6 +28,7 @@ require 'producer/core/condition'
|
|
28
28
|
require 'producer/core/condition/dsl'
|
29
29
|
require 'producer/core/env'
|
30
30
|
require 'producer/core/errors'
|
31
|
+
require 'producer/core/logger_formatter'
|
31
32
|
require 'producer/core/prompter'
|
32
33
|
require 'producer/core/recipe'
|
33
34
|
require 'producer/core/recipe/dsl'
|
data/lib/producer/core/action.rb
CHANGED
data/lib/producer/core/cli.rb
CHANGED
@@ -3,7 +3,7 @@ module Producer
|
|
3
3
|
class CLI
|
4
4
|
ArgumentError = Class.new(::ArgumentError)
|
5
5
|
|
6
|
-
USAGE = "Usage: #{File.basename $0} recipe_file"
|
6
|
+
USAGE = "Usage: #{File.basename $0} [-v] recipe_file"
|
7
7
|
|
8
8
|
EX_USAGE = 64
|
9
9
|
|
@@ -11,6 +11,7 @@ module Producer
|
|
11
11
|
def run!(arguments, output: $stderr)
|
12
12
|
begin
|
13
13
|
cli = new(arguments)
|
14
|
+
cli.parse_arguments!
|
14
15
|
rescue ArgumentError
|
15
16
|
output.puts USAGE
|
16
17
|
exit EX_USAGE
|
@@ -19,21 +20,41 @@ module Producer
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
attr_reader :arguments, :stdout, :recipe
|
23
|
+
attr_reader :arguments, :stdout, :env, :recipe
|
23
24
|
|
24
|
-
def initialize(
|
25
|
-
|
26
|
-
@arguments = arguments
|
25
|
+
def initialize(args, stdout: $stdout)
|
26
|
+
@arguments = args
|
27
27
|
@stdout = stdout
|
28
|
+
@env = Env.new(output: stdout)
|
28
29
|
end
|
29
30
|
|
30
|
-
def
|
31
|
+
def parse_arguments!
|
32
|
+
@arguments = arguments.inject([]) do |m, e|
|
33
|
+
case e
|
34
|
+
when '-v'
|
35
|
+
env.log_level = Logger::INFO
|
36
|
+
when '-n'
|
37
|
+
env.dry_run = true
|
38
|
+
else
|
39
|
+
m << e
|
40
|
+
end
|
41
|
+
m
|
42
|
+
end
|
43
|
+
|
44
|
+
raise ArgumentError unless arguments.any?
|
45
|
+
end
|
46
|
+
|
47
|
+
def run(worker: build_worker)
|
31
48
|
load_recipe
|
32
49
|
worker.process recipe.tasks
|
33
50
|
end
|
34
51
|
|
35
52
|
def load_recipe
|
36
|
-
@recipe = Recipe.evaluate_from_file(@arguments.first,
|
53
|
+
@recipe = Recipe.evaluate_from_file(@arguments.first, env)
|
54
|
+
end
|
55
|
+
|
56
|
+
def build_worker
|
57
|
+
Worker.new(env)
|
37
58
|
end
|
38
59
|
end
|
39
60
|
end
|
data/lib/producer/core/env.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module Producer
|
2
2
|
module Core
|
3
3
|
class Env
|
4
|
-
attr_reader :input, :output, :registry
|
5
|
-
attr_accessor :target
|
4
|
+
attr_reader :input, :output, :registry, :logger
|
5
|
+
attr_accessor :target, :dry_run
|
6
6
|
|
7
7
|
def initialize(input: $stdin, output: $stdout, remote: nil, registry: {})
|
8
8
|
@input = input
|
9
9
|
@output = output
|
10
10
|
@registry = registry
|
11
11
|
@remote = remote
|
12
|
-
@
|
12
|
+
@dry_run = false
|
13
13
|
end
|
14
14
|
|
15
15
|
def remote
|
@@ -23,6 +23,31 @@ module Producer
|
|
23
23
|
def []=(key, value)
|
24
24
|
@registry[key] = value
|
25
25
|
end
|
26
|
+
|
27
|
+
def logger
|
28
|
+
@logger ||= begin
|
29
|
+
logger = Logger.new(output)
|
30
|
+
logger.level = Logger::ERROR
|
31
|
+
logger.formatter = LoggerFormatter.new
|
32
|
+
logger
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def log(message)
|
37
|
+
logger.info message
|
38
|
+
end
|
39
|
+
|
40
|
+
def log_level
|
41
|
+
logger.level
|
42
|
+
end
|
43
|
+
|
44
|
+
def log_level=(level)
|
45
|
+
logger.level = level
|
46
|
+
end
|
47
|
+
|
48
|
+
def dry_run?
|
49
|
+
@dry_run
|
50
|
+
end
|
26
51
|
end
|
27
52
|
end
|
28
53
|
end
|
data/lib/producer/core/task.rb
CHANGED
data/lib/producer/core/worker.rb
CHANGED
@@ -1,12 +1,27 @@
|
|
1
1
|
module Producer
|
2
2
|
module Core
|
3
3
|
class Worker
|
4
|
+
attr_accessor :env
|
5
|
+
|
6
|
+
def initialize(env)
|
7
|
+
@env = env
|
8
|
+
end
|
9
|
+
|
4
10
|
def process(tasks)
|
5
11
|
tasks.each { |t| process_task t }
|
6
12
|
end
|
7
13
|
|
8
14
|
def process_task(task)
|
9
|
-
|
15
|
+
env.log "Task: #{task} applying"
|
16
|
+
if task.condition_met?
|
17
|
+
env.log ' condition: met'
|
18
|
+
task.actions.each do |e|
|
19
|
+
env.log " action: #{e} applying"
|
20
|
+
e.apply unless env.dry_run?
|
21
|
+
end
|
22
|
+
else
|
23
|
+
env.log ' condition: NOT met'
|
24
|
+
end
|
10
25
|
end
|
11
26
|
end
|
12
27
|
end
|
@@ -3,5 +3,13 @@ require 'spec_helper'
|
|
3
3
|
module Producer::Core
|
4
4
|
describe Action do
|
5
5
|
it_behaves_like 'action'
|
6
|
+
|
7
|
+
describe '#name' do
|
8
|
+
subject(:action) { described_class.new(double 'env') }
|
9
|
+
|
10
|
+
it 'infers action name from class name' do
|
11
|
+
expect(action.name).to eq 'action'
|
12
|
+
end
|
13
|
+
end
|
6
14
|
end
|
7
15
|
end
|
@@ -6,29 +6,41 @@ module Producer::Core
|
|
6
6
|
include FixturesHelpers
|
7
7
|
|
8
8
|
let(:recipe_file) { fixture_path_for 'recipes/some_recipe.rb' }
|
9
|
-
let(:
|
9
|
+
let(:options) { [] }
|
10
|
+
let(:arguments) { [*options, recipe_file] }
|
10
11
|
let(:stdout) { StringIO.new }
|
11
12
|
|
12
13
|
subject(:cli) { CLI.new(arguments, stdout: stdout) }
|
13
14
|
|
14
15
|
describe '.run!' do
|
16
|
+
let(:cli) { double('cli').as_null_object }
|
15
17
|
let(:output) { StringIO.new }
|
16
18
|
subject(:run) { described_class.run! arguments, output: output }
|
17
19
|
|
18
20
|
it 'builds a new CLI with given arguments' do
|
19
|
-
expect(
|
21
|
+
expect(described_class)
|
22
|
+
.to receive(:new).with(arguments).and_call_original
|
20
23
|
run
|
21
24
|
end
|
22
25
|
|
23
26
|
it 'runs the CLI' do
|
24
|
-
|
25
|
-
allow(CLI).to receive(:new) { cli }
|
27
|
+
allow(described_class).to receive(:new) { cli }
|
26
28
|
expect(cli).to receive :run
|
27
29
|
run
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
it 'parses CLI arguments' do
|
33
|
+
allow(described_class).to receive(:new) { cli }
|
34
|
+
expect(cli).to receive :parse_arguments!
|
35
|
+
run
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when an argument error is raised' do
|
39
|
+
before do
|
40
|
+
allow(described_class).to receive(:new) { cli }
|
41
|
+
allow(cli).to receive(:parse_arguments!)
|
42
|
+
.and_raise described_class::ArgumentError
|
43
|
+
end
|
32
44
|
|
33
45
|
it 'exits with a return status of 64' do
|
34
46
|
expect { run }.to raise_error(SystemExit) { |e|
|
@@ -44,17 +56,15 @@ module Producer::Core
|
|
44
56
|
end
|
45
57
|
|
46
58
|
describe '#initialize' do
|
47
|
-
|
48
|
-
|
49
|
-
it 'assigns $stdout as the default standard output' do
|
50
|
-
expect(cli.stdout).to be $stdout
|
59
|
+
it 'assigns the env with CLI output' do
|
60
|
+
expect(cli.env.output).to be stdout
|
51
61
|
end
|
52
62
|
|
53
|
-
context 'without
|
54
|
-
|
63
|
+
context 'without options' do
|
64
|
+
subject(:cli) { described_class.new(arguments) }
|
55
65
|
|
56
|
-
it '
|
57
|
-
expect
|
66
|
+
it 'assigns $stdout as the default standard output' do
|
67
|
+
expect(cli.stdout).to be $stdout
|
58
68
|
end
|
59
69
|
end
|
60
70
|
end
|
@@ -71,6 +81,40 @@ module Producer::Core
|
|
71
81
|
end
|
72
82
|
end
|
73
83
|
|
84
|
+
describe '#parse_arguments!' do
|
85
|
+
context 'with options' do
|
86
|
+
let(:options) { %w[-v] }
|
87
|
+
|
88
|
+
before { cli.parse_arguments! }
|
89
|
+
|
90
|
+
it 'removes options from arguments' do
|
91
|
+
expect(cli.arguments).to eq [recipe_file]
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'verbose' do
|
95
|
+
it 'sets env logger level to INFO' do
|
96
|
+
expect(cli.env.log_level).to eq Logger::INFO
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'dry run' do
|
101
|
+
let(:options) { %w[-n] }
|
102
|
+
|
103
|
+
it 'enables env dry run' do
|
104
|
+
expect(cli.env).to be_dry_run
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'without arguments' do
|
110
|
+
let(:arguments) { [] }
|
111
|
+
|
112
|
+
it 'raises the argument error exception' do
|
113
|
+
expect { cli.parse_arguments! }.to raise_error described_class::ArgumentError
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
74
118
|
describe '#run' do
|
75
119
|
it 'loads the recipe' do
|
76
120
|
cli.run
|
@@ -84,10 +128,16 @@ module Producer::Core
|
|
84
128
|
end
|
85
129
|
end
|
86
130
|
|
131
|
+
describe '#env' do
|
132
|
+
it 'returns an env' do
|
133
|
+
expect(cli.env).to be_an Env
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
87
137
|
describe '#load_recipe' do
|
88
|
-
it 'evaluates the recipe file with
|
138
|
+
it 'evaluates the recipe file with the CLI env' do
|
89
139
|
expect(Recipe)
|
90
|
-
.to receive(:evaluate_from_file).with(recipe_file,
|
140
|
+
.to receive(:evaluate_from_file).with(recipe_file, cli.env)
|
91
141
|
cli.load_recipe
|
92
142
|
end
|
93
143
|
|
@@ -96,5 +146,15 @@ module Producer::Core
|
|
96
146
|
expect(cli.recipe.tasks.count).to be 2
|
97
147
|
end
|
98
148
|
end
|
149
|
+
|
150
|
+
describe '#build_worker' do
|
151
|
+
it 'returns a worker' do
|
152
|
+
expect(cli.build_worker).to be_a Worker
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'assigns the CLI env' do
|
156
|
+
expect(cli.build_worker.env).to eq cli.env
|
157
|
+
end
|
158
|
+
end
|
99
159
|
end
|
100
160
|
end
|
@@ -2,17 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Producer::Core
|
4
4
|
describe Env do
|
5
|
-
|
5
|
+
let(:output) { StringIO.new }
|
6
|
+
subject(:env) { Env.new(output: output) }
|
6
7
|
|
7
8
|
describe '#initialize' do
|
8
9
|
it 'assigns $stdin as the default output' do
|
9
10
|
expect(env.input).to be $stdin
|
10
11
|
end
|
11
12
|
|
12
|
-
it 'assigns $stdout as the default output' do
|
13
|
-
expect(env.output).to be $stdout
|
14
|
-
end
|
15
|
-
|
16
13
|
it 'assigns no default target' do
|
17
14
|
expect(env.target).not_to be
|
18
15
|
end
|
@@ -21,6 +18,18 @@ module Producer::Core
|
|
21
18
|
expect(env.registry).to be_empty
|
22
19
|
end
|
23
20
|
|
21
|
+
it 'assigns dry run as false' do
|
22
|
+
expect(env.dry_run).to be false
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when output is not given as argument' do
|
26
|
+
subject(:env) { Env.new }
|
27
|
+
|
28
|
+
it 'assigns $stdout as the default output' do
|
29
|
+
expect(env.output).to be $stdout
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
24
33
|
context 'when input is given as argument' do
|
25
34
|
let(:input) { double 'input' }
|
26
35
|
subject(:env) { described_class.new(input: input) }
|
@@ -31,7 +40,6 @@ module Producer::Core
|
|
31
40
|
end
|
32
41
|
|
33
42
|
context 'when output is given as argument' do
|
34
|
-
let(:output) { double 'output' }
|
35
43
|
subject(:env) { described_class.new(output: output) }
|
36
44
|
|
37
45
|
it 'assigns the given output' do
|
@@ -58,6 +66,25 @@ module Producer::Core
|
|
58
66
|
end
|
59
67
|
end
|
60
68
|
|
69
|
+
describe '#logger' do
|
70
|
+
it 'returns a logger' do
|
71
|
+
expect(env.logger).to be_a Logger
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'uses env output' do
|
75
|
+
env.logger.error 'some message'
|
76
|
+
expect(output.string).to include 'some message'
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'has a log level of ERROR' do
|
80
|
+
expect(env.log_level).to eq Logger::ERROR
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'uses our formatter' do
|
84
|
+
expect(env.logger.formatter).to be_a LoggerFormatter
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
61
88
|
describe '#remote' do
|
62
89
|
it 'builds a Remote with the current target' do
|
63
90
|
env.target = 'some_hostname.example'
|
@@ -90,5 +117,33 @@ module Producer::Core
|
|
90
117
|
expect(env[:some_key]).to eq :some_value
|
91
118
|
end
|
92
119
|
end
|
120
|
+
|
121
|
+
describe '#log' do
|
122
|
+
it 'logs an info message through the assigned logger' do
|
123
|
+
expect(env.logger).to receive(:info).with 'message'
|
124
|
+
env.log 'message'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '#log_level' do
|
129
|
+
it 'returns the logger level' do
|
130
|
+
expect(env.log_level).to eq env.logger.level
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#log_level=' do
|
135
|
+
it 'sets the logger level' do
|
136
|
+
env.log_level = Logger::DEBUG
|
137
|
+
expect(env.logger.level).to eq Logger::DEBUG
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#dry_run?' do
|
142
|
+
before { env.dry_run = true }
|
143
|
+
|
144
|
+
it 'returns true when dry run is enabled' do
|
145
|
+
expect(env.dry_run?).to be true
|
146
|
+
end
|
147
|
+
end
|
93
148
|
end
|
94
149
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Producer::Core
|
4
|
+
describe LoggerFormatter do
|
5
|
+
describe '#call' do
|
6
|
+
let(:severity) { double 'severity' }
|
7
|
+
let(:datetime) { double 'datetime' }
|
8
|
+
let(:progname) { double 'progname' }
|
9
|
+
let(:message) { 'some message' }
|
10
|
+
|
11
|
+
subject { described_class.new.call(severity, datetime, progname, message) }
|
12
|
+
|
13
|
+
it 'returns the given message with a line separator' do
|
14
|
+
expect(subject).to eq "#{message}\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -61,6 +61,12 @@ module Producer::Core
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
describe '#to_s' do
|
65
|
+
it 'includes the task name' do
|
66
|
+
expect(task.to_s).to include name.to_s
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
64
70
|
describe '#condition_met?' do
|
65
71
|
context 'when condition is truthy' do
|
66
72
|
let(:condition) { Condition.new([], true) }
|
@@ -2,7 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Producer::Core
|
4
4
|
describe Worker do
|
5
|
-
|
5
|
+
let(:env) { double 'env', log: nil, dry_run?: false }
|
6
|
+
subject(:worker) { described_class.new(env) }
|
6
7
|
|
7
8
|
describe '#process' do
|
8
9
|
it 'processes each task' do
|
@@ -12,23 +13,59 @@ module Producer::Core
|
|
12
13
|
end
|
13
14
|
|
14
15
|
describe '#process_task' do
|
15
|
-
let(:action)
|
16
|
-
let(:
|
16
|
+
let(:action) { double('action', to_s: 'echo').as_null_object }
|
17
|
+
let(:task_name) { 'some_task' }
|
18
|
+
let(:task) { Task.new(task_name, [action]) }
|
19
|
+
|
20
|
+
it 'logs task info' do
|
21
|
+
expect(env).to receive(:log).with /\ATask: #{task_name}/
|
22
|
+
worker.process_task task
|
23
|
+
end
|
17
24
|
|
18
25
|
context 'when task condition is met' do
|
19
26
|
it 'applies the actions' do
|
20
27
|
expect(action).to receive :apply
|
21
28
|
worker.process_task task
|
22
29
|
end
|
30
|
+
|
31
|
+
it 'logs condition info' do
|
32
|
+
expect(env).to receive(:log).with(' condition: met')
|
33
|
+
worker.process_task task
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'logs action info' do
|
37
|
+
expect(env).to receive(:log).with /\A action: echo/
|
38
|
+
worker.process_task task
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when dry run is enabled' do
|
42
|
+
before { allow(env).to receive(:dry_run?) { true } }
|
43
|
+
|
44
|
+
it 'does not apply the actions' do
|
45
|
+
expect(action).not_to receive :apply
|
46
|
+
worker.process_task task
|
47
|
+
end
|
48
|
+
end
|
23
49
|
end
|
24
50
|
|
25
51
|
context 'when task condition is not met' do
|
26
|
-
|
52
|
+
let(:task) { Task.new(task_name, [action], false) }
|
27
53
|
|
28
54
|
it 'does not apply the actions' do
|
29
55
|
expect(action).not_to receive :apply
|
30
56
|
worker.process_task task
|
31
57
|
end
|
58
|
+
|
59
|
+
it 'logs condition info' do
|
60
|
+
expect(env).to receive(:log).with(' condition: NOT met')
|
61
|
+
worker.process_task task
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#env' do
|
67
|
+
it 'returns the assigned env' do
|
68
|
+
expect(worker.env).to be env
|
32
69
|
end
|
33
70
|
end
|
34
71
|
end
|
@@ -40,5 +40,17 @@ module Producer::Core
|
|
40
40
|
expect(action.fs).to be env.remote.fs
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
describe '#name' do
|
45
|
+
it 'returns a word' do
|
46
|
+
expect(action.name).to match /\A\w+\z/
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#to_s' do
|
51
|
+
it 'returns a word' do
|
52
|
+
expect(action.to_s).to eq action.name
|
53
|
+
end
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: producer-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Thibault Jouan
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: net-ssh
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: net-sftp
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: cucumber
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,7 +69,6 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: aruba
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - "~>"
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,7 +76,6 @@ dependencies:
|
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - "~>"
|
92
81
|
- !ruby/object:Gem::Version
|
@@ -94,7 +83,6 @@ dependencies:
|
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: cucumber-sshd
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
87
|
- - "~>"
|
100
88
|
- !ruby/object:Gem::Version
|
@@ -102,7 +90,6 @@ dependencies:
|
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
94
|
- - "~>"
|
108
95
|
- !ruby/object:Gem::Version
|
@@ -110,7 +97,6 @@ dependencies:
|
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: rake
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
101
|
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
@@ -118,7 +104,6 @@ dependencies:
|
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
108
|
- - "~>"
|
124
109
|
- !ruby/object:Gem::Version
|
@@ -143,7 +128,9 @@ files:
|
|
143
128
|
- features/actions/file_write.feature
|
144
129
|
- features/actions/mkdir.feature
|
145
130
|
- features/actions/sh.feature
|
131
|
+
- features/cli/dry_run.feature
|
146
132
|
- features/cli/usage.feature
|
133
|
+
- features/cli/verbose.feature
|
147
134
|
- features/recipes/ask.feature
|
148
135
|
- features/recipes/evaluation.feature
|
149
136
|
- features/recipes/macro.feature
|
@@ -183,6 +170,7 @@ files:
|
|
183
170
|
- lib/producer/core/condition/dsl.rb
|
184
171
|
- lib/producer/core/env.rb
|
185
172
|
- lib/producer/core/errors.rb
|
173
|
+
- lib/producer/core/logger_formatter.rb
|
186
174
|
- lib/producer/core/prompter.rb
|
187
175
|
- lib/producer/core/recipe.rb
|
188
176
|
- lib/producer/core/recipe/dsl.rb
|
@@ -217,6 +205,7 @@ files:
|
|
217
205
|
- spec/producer/core/condition/dsl_spec.rb
|
218
206
|
- spec/producer/core/condition_spec.rb
|
219
207
|
- spec/producer/core/env_spec.rb
|
208
|
+
- spec/producer/core/logger_formatter_spec.rb
|
220
209
|
- spec/producer/core/prompter_spec.rb
|
221
210
|
- spec/producer/core/recipe/dsl_spec.rb
|
222
211
|
- spec/producer/core/recipe_spec.rb
|
@@ -243,27 +232,26 @@ files:
|
|
243
232
|
- spec/support/test_env_helpers.rb
|
244
233
|
homepage: https://rubygems.org/gems/producer-core
|
245
234
|
licenses: []
|
235
|
+
metadata: {}
|
246
236
|
post_install_message:
|
247
237
|
rdoc_options: []
|
248
238
|
require_paths:
|
249
239
|
- lib
|
250
240
|
required_ruby_version: !ruby/object:Gem::Requirement
|
251
|
-
none: false
|
252
241
|
requirements:
|
253
242
|
- - ">="
|
254
243
|
- !ruby/object:Gem::Version
|
255
244
|
version: '0'
|
256
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
|
-
none: false
|
258
246
|
requirements:
|
259
247
|
- - ">="
|
260
248
|
- !ruby/object:Gem::Version
|
261
249
|
version: '0'
|
262
250
|
requirements: []
|
263
251
|
rubyforge_project:
|
264
|
-
rubygems_version:
|
252
|
+
rubygems_version: 2.2.2
|
265
253
|
signing_key:
|
266
|
-
specification_version:
|
254
|
+
specification_version: 4
|
267
255
|
summary: Provisioning tool
|
268
256
|
test_files:
|
269
257
|
- features/actions/echo.feature
|
@@ -272,7 +260,9 @@ test_files:
|
|
272
260
|
- features/actions/file_write.feature
|
273
261
|
- features/actions/mkdir.feature
|
274
262
|
- features/actions/sh.feature
|
263
|
+
- features/cli/dry_run.feature
|
275
264
|
- features/cli/usage.feature
|
265
|
+
- features/cli/verbose.feature
|
276
266
|
- features/recipes/ask.feature
|
277
267
|
- features/recipes/evaluation.feature
|
278
268
|
- features/recipes/macro.feature
|
@@ -313,6 +303,7 @@ test_files:
|
|
313
303
|
- spec/producer/core/condition/dsl_spec.rb
|
314
304
|
- spec/producer/core/condition_spec.rb
|
315
305
|
- spec/producer/core/env_spec.rb
|
306
|
+
- spec/producer/core/logger_formatter_spec.rb
|
316
307
|
- spec/producer/core/prompter_spec.rb
|
317
308
|
- spec/producer/core/recipe/dsl_spec.rb
|
318
309
|
- spec/producer/core/recipe_spec.rb
|