borg-rb 0.0.5 → 0.1.0
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 +8 -8
- data/CHANGELOG.md +2 -12
- data/bin/borg +2 -17
- data/borg.gemspec +13 -12
- data/cap/initializers/performance.rb +6 -7
- data/cap/initializers/role_reset.rb +1 -1
- data/cap/initializers/sigint.rb +2 -4
- data/lib/borg-rb.rb +2 -9
- data/lib/borg.rb +15 -0
- data/lib/borg/cli.rb +28 -0
- data/lib/borg/cli/applications.rb +4 -6
- data/lib/borg/cli/assimilator.rb +1 -3
- data/lib/borg/configuration.rb +17 -0
- data/lib/borg/configuration/applications.rb +5 -8
- data/lib/borg/configuration/assimilator.rb +6 -7
- data/lib/borg/configuration/stages.rb +1 -3
- data/lib/borg/version.rb +1 -1
- data/spec/acceptance/borgify_plugin_spec.rb +4 -4
- data/spec/acceptance/borgify_spec.rb +11 -11
- data/spec/lib/borg/cli/applications_spec.rb +83 -50
- data/spec/lib/borg/cli_spec.rb +187 -0
- data/spec/lib/borg/configuration/applications_spec.rb +31 -34
- data/spec/lib/borg/configuration/assimilator_spec.rb +34 -20
- data/spec/lib/borg/configuration/stages_spec.rb +33 -36
- data/spec/lib/borg/configuration_spec.rb +19 -0
- data/spec/support/shared_examples/application_configuration.rb +14 -0
- metadata +12 -5
- data/cap/applications/app1.rb +0 -15
- data/cap/initializers/output.rb +0 -4
@@ -2,87 +2,123 @@ require 'spec_helper'
|
|
2
2
|
require 'borg/cli/applications'
|
3
3
|
|
4
4
|
describe Borg::CLI::Applications do
|
5
|
-
before :
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
before :all do
|
6
|
+
class MockCLI < Capistrano::CLI
|
7
|
+
include Borg::CLI::Applications
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
after :all do
|
12
|
+
Object.send(:remove_const, :MockCLI)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:app_config) { <<-RUBY.gsub(/^ {4}/, '')
|
16
|
+
application :app1 do
|
17
|
+
puts 'application = app1'
|
18
|
+
end
|
19
|
+
|
20
|
+
stage :app1, :prd do
|
21
|
+
puts 'stage = prd'
|
22
|
+
end
|
23
|
+
|
24
|
+
stage :app1, :stg do
|
25
|
+
puts 'stage = stg'
|
26
|
+
end
|
27
|
+
|
28
|
+
stage :app1, :alf do
|
29
|
+
puts 'stage = alf'
|
30
|
+
end
|
31
|
+
RUBY
|
32
|
+
}
|
33
|
+
|
34
|
+
before :all do
|
35
|
+
@env = Support::IsolatedEnvironment.new
|
36
|
+
@env.create_file('cap/applications/app.rb', app_config)
|
37
|
+
@app_config_path = @env.workdir_path.join('cap/applications/app.rb')
|
38
|
+
@files = [@app_config_path]
|
39
|
+
end
|
40
|
+
|
41
|
+
after :all do
|
42
|
+
@env.close
|
10
43
|
end
|
11
44
|
|
12
|
-
|
45
|
+
before do
|
46
|
+
Dir.stub('[]').and_return(@files)
|
47
|
+
@cli = MockCLI.new([])
|
48
|
+
@config = double('config1')
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#load_applications' do
|
13
52
|
before do
|
14
53
|
@files.each { |f| @config.should_receive(:load).with(f) }
|
15
54
|
end
|
16
55
|
|
17
|
-
it
|
56
|
+
it 'loads files in ./cap/applications/**/*.rb' do
|
18
57
|
@cli.send :load_applications, @config
|
19
58
|
end
|
20
59
|
|
21
|
-
context
|
60
|
+
context 'when already invoked in the past' do
|
22
61
|
before do
|
23
62
|
@cli.send :load_applications, @config
|
24
|
-
@config2 = double("config2")
|
25
|
-
@files.each { |f| @config2.should_not_receive(:load).with(f) }
|
26
63
|
end
|
27
64
|
|
28
|
-
it
|
65
|
+
it 'does not load files in ./cap/applications/**/*.rb anymore' do
|
66
|
+
@config2 = double('config2')
|
29
67
|
@cli.send :load_applications, @config2
|
68
|
+
@files.each { |f| @config2.should_not_receive(:load).with(f) }
|
30
69
|
end
|
31
70
|
end
|
32
71
|
end
|
33
72
|
|
34
|
-
|
73
|
+
describe '#separate_actions_and_applications' do
|
35
74
|
before do
|
36
75
|
@cli.instance_eval do
|
37
76
|
@options = {}
|
38
77
|
@options[:actions] = %w{app1 app2:stg1 app2:stg3 test test2}
|
39
78
|
end
|
40
|
-
@config.stub(:applications).
|
41
|
-
|
42
|
-
app2: double("app2")
|
43
|
-
})
|
79
|
+
@config.stub(:applications).
|
80
|
+
and_return({app1: double('app1'), app2: double('app2')})
|
44
81
|
@config.applications[:app1].stub(:stages).and_return({})
|
45
|
-
@config.applications[:app2].stub(:stages).
|
46
|
-
|
47
|
-
stg2: double("stg2")
|
48
|
-
})
|
82
|
+
@config.applications[:app2].stub(:stages).
|
83
|
+
and_return({stg1: double('stg1'),stg2: double('stg2')})
|
49
84
|
end
|
50
|
-
it
|
85
|
+
it 'removes all applications from actions' do
|
51
86
|
@cli.send :separate_actions_and_applications, @config
|
52
|
-
@cli.options[:actions].
|
53
|
-
@cli.options[:applications].
|
54
|
-
|
55
|
-
|
56
|
-
|
87
|
+
expect(@cli.options[:actions]).to eq %w{app2:stg3 test test2}
|
88
|
+
expect(@cli.options[:applications]).to eq [
|
89
|
+
@config.applications[:app1],
|
90
|
+
@config.applications[:app2].stages[:stg1]
|
91
|
+
]
|
57
92
|
end
|
58
93
|
|
59
|
-
it
|
94
|
+
it 'queues both stages if app2' do
|
60
95
|
@cli.instance_eval do
|
61
96
|
@options[:actions] = %w{app1 app2 test test2}
|
62
97
|
end
|
63
98
|
|
64
99
|
@cli.send :separate_actions_and_applications, @config
|
65
100
|
|
66
|
-
@cli.options[:actions].
|
67
|
-
@cli.options[:applications].
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
101
|
+
expect(@cli.options[:actions]).to eq %w{test test2}
|
102
|
+
expect(@cli.options[:applications]).to eq [
|
103
|
+
@config.applications[:app1],
|
104
|
+
@config.applications[:app2].stages[:stg1],
|
105
|
+
@config.applications[:app2].stages[:stg2]
|
106
|
+
]
|
72
107
|
end
|
73
108
|
|
74
|
-
it
|
109
|
+
it 'raises an exception when configs are not isolated to start of the actions list' do
|
75
110
|
@cli.instance_eval do
|
76
|
-
@options[:actions] <<
|
111
|
+
@options[:actions] << 'app2:stg2'
|
77
112
|
end
|
78
|
-
expect{
|
113
|
+
expect{
|
114
|
+
@cli.send(:separate_actions_and_applications, @config)
|
115
|
+
}.to raise_error(ArgumentError, 'Can not have non application configs between application configs')
|
79
116
|
end
|
80
117
|
|
81
118
|
end
|
82
119
|
|
83
|
-
|
120
|
+
describe '#execute_requested_actions_with_applications' do
|
84
121
|
before do
|
85
|
-
|
86
122
|
@cli.instance_eval do
|
87
123
|
@apps_loaded = true
|
88
124
|
@options = {}
|
@@ -90,27 +126,25 @@ describe Borg::CLI::Applications do
|
|
90
126
|
@options[:applications] = []
|
91
127
|
end
|
92
128
|
@config.stub(:applications).and_return({})
|
93
|
-
|
94
129
|
@cli.stub(:execute_requested_actions_without_applications)
|
95
|
-
|
96
130
|
end
|
97
131
|
|
98
|
-
it
|
132
|
+
it 'loads applications' do
|
99
133
|
@cli.should_receive(:load_applications).with(@config)
|
100
134
|
@cli.execute_requested_actions_with_applications @config
|
101
135
|
end
|
102
136
|
|
103
|
-
it
|
137
|
+
it 'separates actions and applications' do
|
104
138
|
@cli.should_receive(:separate_actions_and_applications).with(@config)
|
105
139
|
@cli.execute_requested_actions_with_applications @config
|
106
140
|
end
|
107
141
|
|
108
|
-
it
|
142
|
+
it 'calls #execute_requested_actions_without_applications when there is an empty applications list' do
|
109
143
|
@cli.should_receive(:execute_requested_actions_without_applications).with(@config)
|
110
144
|
@cli.execute_requested_actions_with_applications @config
|
111
145
|
end
|
112
146
|
|
113
|
-
context
|
147
|
+
context 'when applications exist' do
|
114
148
|
before do
|
115
149
|
apps = [double(:app1), double(:app2)]
|
116
150
|
apps[0].stub(:name).and_return(:app1)
|
@@ -125,23 +159,23 @@ describe Borg::CLI::Applications do
|
|
125
159
|
Thread.current[:borg_application] = nil
|
126
160
|
end
|
127
161
|
|
128
|
-
it
|
162
|
+
it 'calls execute! for each application' do
|
129
163
|
@cli.stub(:load_applications)
|
130
164
|
@cli.stub(:separate_actions_and_applications)
|
131
165
|
@cli.should_receive(:execute!).with().twice
|
132
166
|
@cli.execute_requested_actions_with_applications @config
|
133
167
|
end
|
134
168
|
|
135
|
-
it
|
169
|
+
it 'sets Thread.current[:borg_application]' do
|
136
170
|
@cli.stub(:load_applications)
|
137
171
|
@cli.stub(:separate_actions_and_applications)
|
138
172
|
@cli.stub(:execute!) do
|
139
|
-
@cli.options[:applications].
|
173
|
+
expect(@cli.options[:applications]).to include Thread.current[:borg_application]
|
140
174
|
end
|
141
175
|
@cli.execute_requested_actions_with_applications @config
|
142
176
|
end
|
143
177
|
|
144
|
-
it
|
178
|
+
it 'calls #execute_requested_actions_without_applications when Thread.current[:borg_application] is set' do
|
145
179
|
Thread.current[:borg_application] = @cli.options[:applications][0]
|
146
180
|
@cli.stub(:load_applications)
|
147
181
|
@cli.stub(:separate_actions_and_applications)
|
@@ -150,7 +184,7 @@ describe Borg::CLI::Applications do
|
|
150
184
|
@cli.execute_requested_actions_with_applications @config
|
151
185
|
end
|
152
186
|
|
153
|
-
it
|
187
|
+
it 'loads the application config when Thread.current[:borg_application] is set' do
|
154
188
|
Thread.current[:borg_application] = @cli.options[:applications][0]
|
155
189
|
@cli.stub(:load_applications)
|
156
190
|
@cli.stub(:separate_actions_and_applications)
|
@@ -158,7 +192,6 @@ describe Borg::CLI::Applications do
|
|
158
192
|
@cli.options[:applications][0].should_receive(:load_into)
|
159
193
|
@cli.execute_requested_actions_with_applications @config
|
160
194
|
end
|
161
|
-
|
162
195
|
end
|
163
196
|
end
|
164
197
|
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'borg/cli'
|
3
|
+
|
4
|
+
describe Borg::CLI do
|
5
|
+
let(:app_config) { <<-RUBY.gsub(/^ {4}/, '')
|
6
|
+
application :app1 do
|
7
|
+
puts 'application = app1'
|
8
|
+
end
|
9
|
+
|
10
|
+
stage :app1, :prd do
|
11
|
+
puts 'stage = prd'
|
12
|
+
end
|
13
|
+
|
14
|
+
stage :app1, :stg do
|
15
|
+
puts 'stage = stg'
|
16
|
+
end
|
17
|
+
|
18
|
+
stage :app1, :alf do
|
19
|
+
puts 'stage = alf'
|
20
|
+
end
|
21
|
+
RUBY
|
22
|
+
}
|
23
|
+
|
24
|
+
before :all do
|
25
|
+
@env = Support::IsolatedEnvironment.new
|
26
|
+
@env.create_file('cap/applications/app.rb', app_config)
|
27
|
+
@app_config_path = @env.workdir_path.join('cap/applications/app.rb')
|
28
|
+
@files = [@app_config_path]
|
29
|
+
end
|
30
|
+
|
31
|
+
after :all do
|
32
|
+
@env.close
|
33
|
+
end
|
34
|
+
|
35
|
+
before do
|
36
|
+
Dir.stub('[]').and_return(@files)
|
37
|
+
@cli = Borg::CLI.new([])
|
38
|
+
@config = double('config1')
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#load_applications' do
|
42
|
+
before do
|
43
|
+
@files.each { |f| @config.should_receive(:load).with(f) }
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'loads files in ./cap/applications/**/*.rb' do
|
47
|
+
@cli.send :load_applications, @config
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when already invoked in the past' do
|
51
|
+
before do
|
52
|
+
@cli.send :load_applications, @config
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'does not load files in ./cap/applications/**/*.rb anymore' do
|
56
|
+
@config2 = double('config2')
|
57
|
+
@cli.send :load_applications, @config2
|
58
|
+
@files.each { |f| @config2.should_not_receive(:load).with(f) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#separate_actions_and_applications' do
|
64
|
+
before do
|
65
|
+
@cli.instance_eval do
|
66
|
+
@options = {}
|
67
|
+
@options[:actions] = %w{app1 app2:stg1 app2:stg3 test test2}
|
68
|
+
end
|
69
|
+
@config.stub(:applications).
|
70
|
+
and_return({app1: double('app1'), app2: double('app2')})
|
71
|
+
@config.applications[:app1].stub(:stages).and_return({})
|
72
|
+
@config.applications[:app2].stub(:stages).
|
73
|
+
and_return({stg1: double('stg1'),stg2: double('stg2')})
|
74
|
+
end
|
75
|
+
it 'removes all applications from actions' do
|
76
|
+
@cli.send :separate_actions_and_applications, @config
|
77
|
+
expect(@cli.options[:actions]).to eq %w{app2:stg3 test test2}
|
78
|
+
expect(@cli.options[:applications]).to eq [
|
79
|
+
@config.applications[:app1],
|
80
|
+
@config.applications[:app2].stages[:stg1]
|
81
|
+
]
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'queues both stages if app2' do
|
85
|
+
@cli.instance_eval do
|
86
|
+
@options[:actions] = %w{app1 app2 test test2}
|
87
|
+
end
|
88
|
+
|
89
|
+
@cli.send :separate_actions_and_applications, @config
|
90
|
+
|
91
|
+
expect(@cli.options[:actions]).to eq %w{test test2}
|
92
|
+
expect(@cli.options[:applications]).to eq [
|
93
|
+
@config.applications[:app1],
|
94
|
+
@config.applications[:app2].stages[:stg1],
|
95
|
+
@config.applications[:app2].stages[:stg2]
|
96
|
+
]
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'raises an exception when configs are not isolated to start of the actions list' do
|
100
|
+
@cli.instance_eval do
|
101
|
+
@options[:actions] << 'app2:stg2'
|
102
|
+
end
|
103
|
+
expect{
|
104
|
+
@cli.send(:separate_actions_and_applications, @config)
|
105
|
+
}.to raise_error(ArgumentError, 'Can not have non application configs between application configs')
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#execute_requested_actions_with_applications' do
|
111
|
+
before do
|
112
|
+
@cli.instance_eval do
|
113
|
+
@apps_loaded = true
|
114
|
+
@options = {}
|
115
|
+
@options[:actions] = %w{app1 app2:stg1 app2:stg3 test test2}
|
116
|
+
@options[:applications] = []
|
117
|
+
end
|
118
|
+
@config.stub(:applications).and_return({})
|
119
|
+
@cli.stub(:execute_requested_actions_without_applications)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'loads applications' do
|
123
|
+
@cli.should_receive(:load_applications).with(@config)
|
124
|
+
@cli.execute_requested_actions_with_applications @config
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'separates actions and applications' do
|
128
|
+
@cli.should_receive(:separate_actions_and_applications).with(@config)
|
129
|
+
@cli.execute_requested_actions_with_applications @config
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'calls #execute_requested_actions_without_applications when there is an empty applications list' do
|
133
|
+
@cli.should_receive(:execute_requested_actions_without_applications).with(@config)
|
134
|
+
@cli.execute_requested_actions_with_applications @config
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when applications exist' do
|
138
|
+
before do
|
139
|
+
apps = [double(:app1), double(:app2)]
|
140
|
+
apps[0].stub(:name).and_return(:app1)
|
141
|
+
apps[1].stub(:name).and_return(:app2)
|
142
|
+
@cli.instance_eval do
|
143
|
+
@options[:applications] = apps
|
144
|
+
end
|
145
|
+
@cli.stub(:puts)
|
146
|
+
end
|
147
|
+
|
148
|
+
after do
|
149
|
+
Thread.current[:borg_application] = nil
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'calls execute! for each application' do
|
153
|
+
@cli.stub(:load_applications)
|
154
|
+
@cli.stub(:separate_actions_and_applications)
|
155
|
+
@cli.should_receive(:execute!).with().twice
|
156
|
+
@cli.execute_requested_actions_with_applications @config
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'sets Thread.current[:borg_application]' do
|
160
|
+
@cli.stub(:load_applications)
|
161
|
+
@cli.stub(:separate_actions_and_applications)
|
162
|
+
@cli.stub(:execute!) do
|
163
|
+
expect(@cli.options[:applications]).to include Thread.current[:borg_application]
|
164
|
+
end
|
165
|
+
@cli.execute_requested_actions_with_applications @config
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'calls #execute_requested_actions_without_applications when Thread.current[:borg_application] is set' do
|
169
|
+
Thread.current[:borg_application] = @cli.options[:applications][0]
|
170
|
+
@cli.stub(:load_applications)
|
171
|
+
@cli.stub(:separate_actions_and_applications)
|
172
|
+
@cli.should_receive(:execute_requested_actions_without_applications).with(@config)
|
173
|
+
@cli.options[:applications][0].stub(:load_into)
|
174
|
+
@cli.execute_requested_actions_with_applications @config
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'loads the application config when Thread.current[:borg_application] is set' do
|
178
|
+
Thread.current[:borg_application] = @cli.options[:applications][0]
|
179
|
+
@cli.stub(:load_applications)
|
180
|
+
@cli.stub(:separate_actions_and_applications)
|
181
|
+
@cli.stub(:execute_requested_actions_without_applications)
|
182
|
+
@cli.options[:applications][0].should_receive(:load_into)
|
183
|
+
@cli.execute_requested_actions_with_applications @config
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -2,66 +2,63 @@ require 'spec_helper'
|
|
2
2
|
require 'borg/configuration/applications'
|
3
3
|
|
4
4
|
describe Borg::Configuration::Applications do
|
5
|
-
|
6
|
-
|
5
|
+
before :all do
|
6
|
+
class MockConfiguration < Capistrano::Configuration
|
7
|
+
include Borg::Configuration::Applications
|
8
|
+
end
|
7
9
|
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
after :all do
|
12
|
+
Object.send(:remove_const, :MockConfiguration)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:config) { MockConfiguration.new }
|
16
|
+
|
17
|
+
it 'initializes the applications hash' do
|
18
|
+
expect(config.applications.class).to eq Hash
|
14
19
|
end
|
15
20
|
|
16
|
-
context
|
21
|
+
context 'when applications are defined' do
|
17
22
|
before do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
config.load do
|
24
|
+
application 'app1' do
|
25
|
+
test_notice 'You have called app1'
|
26
|
+
|
22
27
|
end
|
23
28
|
end
|
24
29
|
end
|
25
|
-
subject { @config }
|
26
30
|
|
27
|
-
|
28
|
-
expect(subject.applications[:app1].name).to eq :app1
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should create a namespace app1 with task default and a description" do
|
32
|
-
expect(subject.namespaces[:app1]).to be_true
|
33
|
-
expect(subject.namespaces[:app1].tasks[:default]).to be_true
|
34
|
-
expect(subject.namespaces[:app1].tasks[:default].desc).to be_true
|
35
|
-
end
|
31
|
+
it_behaves_like 'an application configuration'
|
36
32
|
|
37
|
-
it
|
38
|
-
expect(
|
39
|
-
expect(subject.applications[:app1].execution_blocks.count).to eq 1
|
33
|
+
it 'creates an execution block for the application' do
|
34
|
+
expect(config.applications[:app1].execution_blocks.count).to eq 1
|
40
35
|
end
|
41
36
|
end
|
37
|
+
|
42
38
|
end
|
43
39
|
|
44
40
|
describe Borg::Configuration::Applications::Application do
|
45
|
-
it
|
46
|
-
app1 = Borg::Configuration::Applications::Application.new(:app1, double(
|
41
|
+
it 'initializes: stage, name, and execution_blocks' do
|
42
|
+
app1 = Borg::Configuration::Applications::Application.new(:app1, double('namespace app1'))
|
47
43
|
expect(app1.stages).to eq({})
|
48
44
|
expect(app1.name).to eq(:app1)
|
49
45
|
expect(app1.execution_blocks).to eq([])
|
50
46
|
end
|
51
47
|
|
52
|
-
context
|
48
|
+
context 'an applications with 2 blocks' do
|
53
49
|
before do
|
54
|
-
@app1 = Borg::Configuration::Applications::Application.new(:app1, double(
|
50
|
+
@app1 = Borg::Configuration::Applications::Application.new(:app1, double('namespace app1'))
|
55
51
|
@app1.execution_blocks << -> {
|
56
|
-
raise
|
52
|
+
raise 'block 1 called'
|
57
53
|
}
|
58
54
|
@app1.execution_blocks << -> {
|
59
|
-
raise
|
55
|
+
raise 'block 2 called'
|
60
56
|
}
|
61
57
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
|
59
|
+
context 'when #load_into is called' do
|
60
|
+
it 'loads all blocks into the provided config' do
|
61
|
+
config = double('test config')
|
65
62
|
config.should_receive(:load).twice
|
66
63
|
@app1.load_into config
|
67
64
|
end
|