producer-core 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +4 -3
- data/features/actions/file_replace_content.feature +31 -0
- data/features/recipes/registry.feature +21 -0
- data/features/steps/remote_steps.rb +8 -0
- data/features/tasks/registry.feature +13 -0
- data/features/tests/file_contains.feature +28 -0
- data/lib/producer/core/action.rb +0 -2
- data/lib/producer/core/actions/file_replace_content.rb +27 -0
- data/lib/producer/core/condition/dsl.rb +4 -3
- data/lib/producer/core/env.rb +15 -5
- data/lib/producer/core/recipe/dsl.rb +8 -0
- data/lib/producer/core/remote/environment.rb +0 -2
- data/lib/producer/core/remote/fs.rb +9 -9
- data/lib/producer/core/remote.rb +1 -4
- data/lib/producer/core/task/dsl.rb +7 -2
- data/lib/producer/core/test.rb +0 -2
- data/lib/producer/core/testing/mock_remote.rb +25 -0
- data/lib/producer/core/testing.rb +1 -0
- data/lib/producer/core/tests/file_contains.rb +18 -0
- data/lib/producer/core/version.rb +1 -1
- data/lib/producer/core.rb +9 -0
- data/producer-core.gemspec +2 -2
- data/spec/producer/core/action_spec.rb +1 -42
- data/spec/producer/core/actions/echo_spec.rb +11 -8
- data/spec/producer/core/actions/file_replace_content_spec.rb +49 -0
- data/spec/producer/core/actions/file_writer_spec.rb +20 -17
- data/spec/producer/core/actions/mkdir_spec.rb +15 -13
- data/spec/producer/core/actions/shell_command_spec.rb +16 -14
- data/spec/producer/core/condition/dsl_spec.rb +53 -51
- data/spec/producer/core/env_spec.rb +30 -2
- data/spec/producer/core/prompter_spec.rb +0 -1
- data/spec/producer/core/recipe/dsl_spec.rb +82 -66
- data/spec/producer/core/remote/environment_spec.rb +32 -30
- data/spec/producer/core/remote/fs_spec.rb +100 -104
- data/spec/producer/core/remote_spec.rb +4 -13
- data/spec/producer/core/task/dsl_spec.rb +82 -72
- data/spec/producer/core/task_spec.rb +1 -1
- data/spec/producer/core/test_spec.rb +1 -77
- data/spec/producer/core/testing/mock_remote_spec.rb +46 -0
- data/spec/producer/core/tests/file_contains_spec.rb +46 -0
- data/spec/producer/core/tests/has_dir_spec.rb +15 -18
- data/spec/producer/core/tests/has_env_spec.rb +34 -34
- data/spec/producer/core/tests/has_file_spec.rb +15 -18
- data/spec/spec_helper.rb +3 -3
- data/spec/support/shared_action.rb +44 -0
- data/spec/support/shared_test.rb +82 -0
- data/spec/support/test_env_helpers.rb +34 -0
- metadata +33 -9
@@ -1,22 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Producer::Core
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module Actions
|
5
|
+
describe ShellCommand, :env do
|
6
|
+
let(:command_args) { 'hello from remote host' }
|
7
|
+
let(:command) { "echo #{command_args}" }
|
8
|
+
subject(:sh) { ShellCommand.new(env, command) }
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
it_behaves_like 'action'
|
11
|
+
|
12
|
+
describe '#apply' do
|
13
|
+
it 'executes the remote command' do
|
14
|
+
expect_execution(command)
|
15
|
+
sh.apply
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
it 'writes the returned output with a record separator' do
|
19
|
+
sh.apply
|
20
|
+
expect(output).to eq "#{command_args}\n"
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -1,76 +1,78 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Producer::Core
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class Condition
|
5
|
+
describe DSL do
|
6
|
+
let(:block) { proc { :some_condition_code } }
|
7
|
+
let(:env) { double 'env' }
|
8
|
+
subject(:dsl) { DSL.new(env, &block) }
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
%w[file_contains has_dir has_env has_file].each do |test|
|
11
|
+
it "has `#{test}' test defined" do
|
12
|
+
expect(dsl).to respond_to test.to_sym
|
13
|
+
end
|
12
14
|
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '.define_test' do
|
16
|
-
let(:some_test_class) { Test }
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
it 'defines a new test keyword' do
|
21
|
-
expect(dsl).to respond_to :some_test
|
22
|
-
end
|
16
|
+
describe '.define_test' do
|
17
|
+
let(:some_test_class) { Test }
|
23
18
|
|
24
|
-
|
25
|
-
expect(dsl).to respond_to :no_some_test
|
26
|
-
end
|
19
|
+
before { described_class.define_test(:some_test, some_test_class) }
|
27
20
|
|
28
|
-
|
29
|
-
|
30
|
-
expect { dsl.some_test }.to change { dsl.tests.count }.by 1
|
21
|
+
it 'defines a new test keyword' do
|
22
|
+
expect(dsl).to respond_to :some_test
|
31
23
|
end
|
32
24
|
|
33
|
-
it '
|
34
|
-
dsl.
|
35
|
-
expect(dsl.tests.first.env).to be env
|
25
|
+
it 'defines the negated test' do
|
26
|
+
expect(dsl).to respond_to :no_some_test
|
36
27
|
end
|
37
28
|
|
38
|
-
|
39
|
-
|
40
|
-
|
29
|
+
context 'when a test keyword is called' do
|
30
|
+
it 'registers the test' do
|
31
|
+
expect { dsl.some_test }.to change { dsl.tests.count }.by 1
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'registers the test with current env' do
|
35
|
+
dsl.some_test
|
36
|
+
expect(dsl.tests.first.env).to be env
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'registers the test with given arguments' do
|
40
|
+
dsl.some_test :some, :args
|
41
|
+
expect(dsl.tests.first.arguments).to eq [:some, :args]
|
42
|
+
end
|
41
43
|
end
|
42
|
-
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
context 'when a negated test keyword is called' do
|
46
|
+
it 'registers a negated test' do
|
47
|
+
dsl.no_some_test
|
48
|
+
expect(dsl.tests.first).to be_negated
|
49
|
+
end
|
48
50
|
end
|
49
51
|
end
|
50
|
-
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
describe '#initialize' do
|
54
|
+
it 'assigns the env' do
|
55
|
+
expect(dsl.env).to be env
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
it 'assigns the code' do
|
59
|
+
expect(dsl.block).to be block
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
62
|
+
it 'assigns no test' do
|
63
|
+
expect(dsl.tests).to be_empty
|
64
|
+
end
|
63
65
|
end
|
64
|
-
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
describe '#evaluate' do
|
68
|
+
it 'evaluates its code' do
|
69
|
+
dsl = described_class.new(env) { throw :condition_code }
|
70
|
+
expect { dsl.evaluate }.to throw_symbol :condition_code
|
71
|
+
end
|
71
72
|
|
72
|
-
|
73
|
-
|
73
|
+
it 'returns the value returned by the assigned block' do
|
74
|
+
expect(dsl.evaluate).to eq block.call
|
75
|
+
end
|
74
76
|
end
|
75
77
|
end
|
76
78
|
end
|
@@ -17,12 +17,16 @@ module Producer::Core
|
|
17
17
|
expect(env.target).not_to be
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'assigns an empty registry' do
|
21
|
+
expect(env.registry).to be_empty
|
22
|
+
end
|
23
|
+
|
20
24
|
context 'when input is given as argument' do
|
21
25
|
let(:input) { double 'input' }
|
22
26
|
subject(:env) { described_class.new(input: input) }
|
23
27
|
|
24
28
|
it 'assigns the given input' do
|
25
|
-
expect(env.input).to
|
29
|
+
expect(env.input).to be input
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
@@ -31,7 +35,16 @@ module Producer::Core
|
|
31
35
|
subject(:env) { described_class.new(output: output) }
|
32
36
|
|
33
37
|
it 'assigns the given output' do
|
34
|
-
expect(env.output).to
|
38
|
+
expect(env.output).to be output
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when remote is given as argument' do
|
43
|
+
let(:remote) { double 'remote' }
|
44
|
+
subject(:env) { described_class.new(remote: remote) }
|
45
|
+
|
46
|
+
it 'assigns the given remote' do
|
47
|
+
expect(env.remote).to be remote
|
35
48
|
end
|
36
49
|
end
|
37
50
|
end
|
@@ -62,5 +75,20 @@ module Producer::Core
|
|
62
75
|
expect(env.remote).to be env.remote
|
63
76
|
end
|
64
77
|
end
|
78
|
+
|
79
|
+
describe '#[]' do
|
80
|
+
subject(:env) { Env.new(registry: { some_key: :some_value }) }
|
81
|
+
|
82
|
+
it 'returns the value indexed by given key from the registry' do
|
83
|
+
expect(env[:some_key]).to eq :some_value
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#[]=' do
|
88
|
+
it 'registers given value at given index in the registry' do
|
89
|
+
env[:some_key] = :some_value
|
90
|
+
expect(env[:some_key]).to eq :some_value
|
91
|
+
end
|
92
|
+
end
|
65
93
|
end
|
66
94
|
end
|
@@ -1,102 +1,118 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Producer::Core
|
4
|
-
|
5
|
-
|
4
|
+
class Recipe
|
5
|
+
describe DSL do
|
6
|
+
include FixturesHelpers
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
let(:code) { proc { :some_recipe_code } }
|
9
|
+
let(:env) { Env.new }
|
10
|
+
subject(:dsl) { DSL.new(env, &code) }
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
describe '#initialize' do
|
13
|
+
it 'assigns the given env' do
|
14
|
+
expect(dsl.env).to be env
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
it 'assigns no task' do
|
18
|
+
expect(dsl.tasks).to be_empty
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
context 'when a string of code is given as argument' do
|
22
|
+
let(:code) { 'some_code' }
|
23
|
+
subject(:dsl) { described_class.new(env, code) }
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
it 'assigns the string of code' do
|
26
|
+
expect(dsl.code).to eq code
|
27
|
+
end
|
26
28
|
end
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
context 'when a code block is given as argument' do
|
31
|
+
it 'assigns the code block' do
|
32
|
+
expect(dsl.block).to be code
|
33
|
+
end
|
32
34
|
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
describe '#tasks' do
|
38
|
+
let(:code) { proc { task(:some_task) {} } }
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
it 'returns registered tasks' do
|
41
|
+
dsl.evaluate
|
42
|
+
expect(dsl.tasks[0].name).to eq :some_task
|
43
|
+
end
|
42
44
|
end
|
43
|
-
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
describe '#evaluate' do
|
47
|
+
it 'evaluates its code' do
|
48
|
+
dsl = described_class.new(env) { throw :recipe_code }
|
49
|
+
expect { dsl.evaluate }.to throw_symbol :recipe_code
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
it 'returns itself' do
|
53
|
+
expect(dsl.evaluate).to eq dsl
|
54
|
+
end
|
53
55
|
end
|
54
|
-
end
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
describe '#source' do
|
58
|
+
let(:filepath) { fixture_path_for 'recipes/throw' }
|
58
59
|
|
59
|
-
|
60
|
-
|
60
|
+
it 'sources the recipe given as argument' do
|
61
|
+
expect { dsl.source filepath }.to throw_symbol :recipe_code
|
62
|
+
end
|
61
63
|
end
|
62
|
-
end
|
63
64
|
|
64
|
-
|
65
|
-
|
65
|
+
describe '#target' do
|
66
|
+
let(:host) { 'some_host.example' }
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
it 'registers the target host in the env' do
|
69
|
+
dsl.target host
|
70
|
+
expect(env.target).to eq host
|
71
|
+
end
|
70
72
|
end
|
71
|
-
end
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
describe '#task' do
|
75
|
+
it 'registers a new evaluated task' do
|
76
|
+
expect { dsl.task(:some_task) { :some_task_code } }
|
77
|
+
.to change { dsl.tasks.count }.by 1
|
78
|
+
end
|
77
79
|
end
|
78
|
-
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
describe '#macro' do
|
82
|
+
it 'defines the new recipe keyword' do
|
83
|
+
dsl.macro :hello
|
84
|
+
expect(dsl).to respond_to(:hello)
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when a defined macro is called' do
|
88
|
+
before { dsl.macro(:hello) { :some_macro_code } }
|
89
|
+
|
90
|
+
it 'registers the new task' do
|
91
|
+
expect { dsl.hello }.to change { dsl.tasks.count }.by 1
|
92
|
+
end
|
93
|
+
end
|
85
94
|
|
86
|
-
|
87
|
-
|
95
|
+
context 'when a defined macro is called with arguments' do
|
96
|
+
before { dsl.macro(:hello) { |a, b| echo a, b } }
|
88
97
|
|
89
|
-
|
90
|
-
|
98
|
+
it 'evaluates task code with arguments' do
|
99
|
+
dsl.hello :some, :args
|
100
|
+
expect(dsl.tasks.first.actions.first.arguments).to eq [:some, :args]
|
101
|
+
end
|
91
102
|
end
|
92
103
|
end
|
93
104
|
|
94
|
-
|
95
|
-
|
105
|
+
describe '#set' do
|
106
|
+
it 'registers a key/value pair in env registry' do
|
107
|
+
dsl.set :some_key, :some_value
|
108
|
+
expect(env[:some_key]).to eq :some_value
|
109
|
+
end
|
110
|
+
end
|
96
111
|
|
97
|
-
|
98
|
-
|
99
|
-
|
112
|
+
describe '#get' do
|
113
|
+
it 'fetches a value from the registry at given index' do
|
114
|
+
dsl.set :some_key, :some_value
|
115
|
+
expect(dsl.get :some_key).to eq :some_value
|
100
116
|
end
|
101
117
|
end
|
102
118
|
end
|
@@ -1,48 +1,50 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Producer::Core
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
class Remote
|
5
|
+
describe Environment do
|
6
|
+
let(:variables) { { 'FOO' => 'bar', 'BAZ' => 'qux' } }
|
7
|
+
let(:string) { "FOO=bar\nBAZ=qux" }
|
8
|
+
let(:argument) { variables }
|
9
|
+
subject(:environment) { Environment.new(argument) }
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
describe '.string_to_hash' do
|
12
|
+
it 'converts key=value pairs separated by new lines to a hash' do
|
13
|
+
expect(described_class.string_to_hash(string)).to eq variables
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
describe '.new_from_string' do
|
18
|
+
it 'returns a new instance with converted keys and values' do
|
19
|
+
environment = described_class.new_from_string string
|
20
|
+
expect(environment.variables).to eq variables
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
describe '#initialize' do
|
25
|
+
it 'assigns the key/value pairs' do
|
26
|
+
expect(environment.variables).to eq variables
|
27
|
+
end
|
26
28
|
end
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
describe '#key?' do
|
31
|
+
context 'when key is defined' do
|
32
|
+
it 'returns true' do
|
33
|
+
expect(environment.key? 'FOO').to be true
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
context 'when key is not defined' do
|
38
|
+
it 'returns false' do
|
39
|
+
expect(environment.key? 'INEXISTENT_KEY').to be false
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
|
-
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
describe '#[]' do
|
45
|
+
it 'returns the value indexed by given key' do
|
46
|
+
expect(environment['FOO']).to eq 'bar'
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|