do_snapshot 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/do_snapshot +2 -2
- data/lib/do_snapshot/adapter/abstract.rb +5 -5
- data/lib/do_snapshot/adapter/digitalocean.rb +8 -9
- data/lib/do_snapshot/adapter/digitalocean_v2.rb +10 -10
- data/lib/do_snapshot/cli.rb +41 -23
- data/lib/do_snapshot/command.rb +15 -16
- data/lib/do_snapshot/configuration.rb +19 -0
- data/lib/do_snapshot/helpers.rb +29 -0
- data/lib/do_snapshot/log.rb +47 -42
- data/lib/do_snapshot/mail.rb +58 -75
- data/lib/do_snapshot/runner.rb +59 -0
- data/lib/do_snapshot/version.rb +1 -1
- data/lib/do_snapshot.rb +37 -4
- data/spec/do_snapshot/adapter/abstract_spec.rb +0 -7
- data/spec/do_snapshot/adapter/digitalocean_spec.rb +7 -13
- data/spec/do_snapshot/adapter/digitalocean_v2_spec.rb +7 -13
- data/spec/do_snapshot/command_spec.rb +8 -8
- data/spec/do_snapshot/configuration_spec.rb +11 -0
- data/spec/do_snapshot/log_spec.rb +88 -0
- data/spec/do_snapshot/mail_spec.rb +18 -4
- data/spec/do_snapshot/runner_spec.rb +334 -0
- data/spec/{do_snapshots_spec.rb → do_snapshot_spec.rb} +4 -12
- data/spec/shared/api_v2_helpers.rb +2 -1
- data/spec/shared/environment.rb +41 -26
- data/spec/spec_helper.rb +3 -2
- data/spec/support/aruba.rb +7 -0
- data/spec/support/matchers.rb +17 -0
- metadata +17 -4
@@ -0,0 +1,334 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe DoSnapshot::Runner, type: :aruba do
|
5
|
+
include_context 'spec'
|
6
|
+
|
7
|
+
context 'commands' do
|
8
|
+
context '.snap' do
|
9
|
+
RSpec.shared_examples '.snap methods' do
|
10
|
+
it 'with error' do
|
11
|
+
run 'do_snapshot snap --some-param=5'
|
12
|
+
|
13
|
+
expect(all_stderr).to match(/ERROR: ".*" was called with arguments \["--some-param=5"\]/)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'with exclude' do
|
17
|
+
excluded_droplets = %w( 100824 )
|
18
|
+
stub_all_api(%w(100825 100823))
|
19
|
+
hash_attribute_eq_no_stub(exclude: excluded_droplets, only: %w())
|
20
|
+
|
21
|
+
expect(all_stdout).to be_found_n_times(t_snapshot_created(snapshot_name), 2)
|
22
|
+
expect(all_stdout).not_to include('100824')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'with only' do
|
26
|
+
selected_droplets = %w( 100823 )
|
27
|
+
stub_all_api(selected_droplets)
|
28
|
+
hash_attribute_eq_no_stub(only: selected_droplets)
|
29
|
+
expect(last_command).to have_exit_status(0)
|
30
|
+
|
31
|
+
expect(all_stdout).to be_found_n_times(t_snapshot_created(snapshot_name), 1)
|
32
|
+
expect(all_stdout).not_to include('100825')
|
33
|
+
expect(all_stdout).not_to include('100824')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'with 1 delay' do
|
37
|
+
aruba.config.exit_timeout = 1
|
38
|
+
|
39
|
+
hash_attribute_eq delay: 1, timeout: timeout
|
40
|
+
expect(last_command).to have_exit_status(0)
|
41
|
+
expect(last_command).to have_finished_in_time
|
42
|
+
|
43
|
+
aruba.config.exit_timeout = 15
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'with 0 delay' do
|
47
|
+
hash_attribute_eq delay: 0, timeout: timeout
|
48
|
+
|
49
|
+
expect(last_command).to have_exit_status(0)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'with custom timeout' do
|
53
|
+
aruba.config.exit_timeout = 1
|
54
|
+
|
55
|
+
hash_attribute_eq timeout: 1, delay: 2
|
56
|
+
|
57
|
+
expect(last_command).to have_exit_status(0)
|
58
|
+
expect(last_command).to have_finished_in_time
|
59
|
+
|
60
|
+
aruba.config.exit_timeout = 15
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'with keep' do
|
64
|
+
attribute_eq 'keep', 7
|
65
|
+
|
66
|
+
expect(last_command).to have_exit_status(0)
|
67
|
+
expect(all_stdout).not_to include(t_is_reached)
|
68
|
+
expect(all_stdout).not_to include(t_snapshots_cleaning(droplet_id))
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'with no keep' do
|
72
|
+
attribute_eq 'keep', 3
|
73
|
+
|
74
|
+
expect(last_command).to have_exit_status(0)
|
75
|
+
expect(all_stdout).to be_found_n_times(t_is_reached, 2)
|
76
|
+
expect(all_stdout).to include(t_snapshots_cleaning(droplet_id))
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'with quiet' do
|
80
|
+
attribute_eq 'quiet', true
|
81
|
+
|
82
|
+
expect(last_command).to have_exit_status(0)
|
83
|
+
expect(all_stdout).to eq('')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'with no quiet' do
|
87
|
+
attribute_eq 'quiet', false
|
88
|
+
|
89
|
+
expect(last_command).to have_exit_status(0)
|
90
|
+
expect(all_stdout).not_to eq('')
|
91
|
+
expect(all_stdout).to include(t_finished)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'with stop' do
|
95
|
+
attribute_eq 'stop', true
|
96
|
+
|
97
|
+
expect(last_command).to have_exit_status(0)
|
98
|
+
expect(all_stdout).not_to include(t_droplet_shutdown)
|
99
|
+
expect(all_stdout).not_to include(t_wait_until_create)
|
100
|
+
expect(all_stdout).not_to include(t_snapshot_created(snapshot_name))
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'with no stop' do
|
104
|
+
attribute_eq 'stop', false
|
105
|
+
|
106
|
+
expect(last_command).to have_exit_status(0)
|
107
|
+
expect(all_stdout).to include(t_droplet_shutdown)
|
108
|
+
expect(all_stdout).to include(t_wait_until_create)
|
109
|
+
expect(all_stdout).to include(t_snapshot_created(snapshot_name))
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'with clean' do
|
113
|
+
attribute_eq 'clean', true
|
114
|
+
|
115
|
+
expect(last_command).to have_exit_status(0)
|
116
|
+
expect(all_stdout).to include(t_snapshots_cleaning(droplet_id))
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'with no clean' do
|
120
|
+
attribute_eq 'clean', false
|
121
|
+
|
122
|
+
expect(last_command).to have_exit_status(0)
|
123
|
+
expect(all_stdout).not_to include(t_snapshots_cleaning(droplet_id))
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'with mail' do
|
127
|
+
hash_attribute_eq(mail: mail_options)
|
128
|
+
|
129
|
+
expect(last_command).to have_exit_status(0)
|
130
|
+
expect(all_stdout).to include(t_sending_email)
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'with no mail' do
|
134
|
+
hash_attribute_eq
|
135
|
+
|
136
|
+
expect(last_command).to have_exit_status(0)
|
137
|
+
expect(all_stdout).to include(t_sending_email)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'with smtp' do
|
141
|
+
hash_attribute_eq(smtp: smtp_options)
|
142
|
+
|
143
|
+
expect(last_command).to have_exit_status(0)
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'with no smtp' do
|
147
|
+
hash_attribute_eq
|
148
|
+
|
149
|
+
expect(last_command).to have_exit_status(0)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'with log' do
|
153
|
+
FileUtils.remove_file(log_path, true)
|
154
|
+
hash_attribute_eq(log)
|
155
|
+
|
156
|
+
expect(last_command).to have_exit_status(0)
|
157
|
+
expect(File.exist?(log_path)).to be_truthy
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'with no log' do
|
161
|
+
FileUtils.remove_file(log_path, true)
|
162
|
+
hash_attribute_eq
|
163
|
+
|
164
|
+
expect(last_command).to have_exit_status(0)
|
165
|
+
expect(File.exist?(log_path)).to be_falsey
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'API V2' do
|
170
|
+
let(:default_options_cli) { default_options.reject { |key, _| %w( droplets threads ).include?(key.to_s) }.merge(protocol: 2) }
|
171
|
+
let(:event_id) { '7499' }
|
172
|
+
let(:snapshot_name) { "example.com_#{DateTime.now.strftime('%Y_%m_%d')}" }
|
173
|
+
|
174
|
+
include_context 'api_v2_helpers'
|
175
|
+
it_behaves_like '.snap methods'
|
176
|
+
|
177
|
+
context 'when no credentials' do
|
178
|
+
it 'with warning about digitalocean credentials' do
|
179
|
+
with_environment(cli_env_nil) do
|
180
|
+
run "do_snapshot snap #{options_line}"
|
181
|
+
|
182
|
+
expect(last_command).to have_exit_status(1)
|
183
|
+
expect(all_stdout)
|
184
|
+
.to include(t_wrong_keys('digital_ocean_access_token'))
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when different credentials' do
|
190
|
+
let(:api_access_token) { "Bearer #{cli_keys_other[:digital_ocean_access_token]}" }
|
191
|
+
|
192
|
+
it 'with no warning' do
|
193
|
+
hash_attribute_eq(cli_keys_other)
|
194
|
+
|
195
|
+
expect(last_command).to have_exit_status(0)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'API V1' do
|
201
|
+
include_context 'api_v1_helpers'
|
202
|
+
it_behaves_like '.snap methods'
|
203
|
+
|
204
|
+
context 'when no credentials' do
|
205
|
+
it 'with warning about digitalocean credentials' do
|
206
|
+
with_environment(cli_env_nil) do
|
207
|
+
run "do_snapshot snap #{options_line}"
|
208
|
+
|
209
|
+
expect(last_command).to have_exit_status(1)
|
210
|
+
expect(all_stdout)
|
211
|
+
.to include(t_wrong_keys(%w( digital_ocean_client_id digital_ocean_api_key ).join(', ')))
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context 'when different credentials' do
|
217
|
+
let(:keys_uri) { "api_key=#{cli_keys_other[:digital_ocean_api_key]}&client_id=#{cli_keys_other[:digital_ocean_client_id]}" }
|
218
|
+
|
219
|
+
it 'with no warning' do
|
220
|
+
hash_attribute_eq(cli_keys_other)
|
221
|
+
|
222
|
+
expect(last_command).to have_exit_status(0)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context '.help' do
|
229
|
+
it 'shows a help message' do
|
230
|
+
run 'do_snapshot help'
|
231
|
+
expect(all_stdout)
|
232
|
+
.to match('Commands:')
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'shows a help message for specific commands' do
|
236
|
+
run 'do_snapshot help snap'
|
237
|
+
expect(all_stdout).to include('`do_snapshot` able to create and cleanup snapshots on your droplets.')
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'sure no warning about credentials' do
|
241
|
+
with_environment(cli_env_nil) do
|
242
|
+
run 'do_snapshot help snap'
|
243
|
+
|
244
|
+
expect(last_command).to have_exit_status(0)
|
245
|
+
expect(all_stdout)
|
246
|
+
.not_to include(t_wrong_keys(%w( digital_ocean_client_id digital_ocean_api_key ).join(', ')))
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context '.version' do
|
252
|
+
it 'with right version' do
|
253
|
+
run 'do_snapshot version'
|
254
|
+
expect(all_stdout).to include(DoSnapshot::VERSION)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def t_snapshot_created(name = snapshot_name)
|
259
|
+
"Snapshot name: #{name} created successfully."
|
260
|
+
end
|
261
|
+
|
262
|
+
def t_snapshots_cleaning(id = droplet_id)
|
263
|
+
"Cleaning up snapshots for droplet id: #{id}"
|
264
|
+
end
|
265
|
+
|
266
|
+
def t_droplet_shutdown
|
267
|
+
'Shutting down droplet.'
|
268
|
+
end
|
269
|
+
|
270
|
+
def t_wait_until_create
|
271
|
+
'Wait until snapshot will be created.'
|
272
|
+
end
|
273
|
+
|
274
|
+
def t_finished
|
275
|
+
'All operations has been finished.'
|
276
|
+
end
|
277
|
+
|
278
|
+
def t_is_reached
|
279
|
+
'of snapshots is reached'
|
280
|
+
end
|
281
|
+
|
282
|
+
def t_sending_email
|
283
|
+
'Sending e-mail notification'
|
284
|
+
end
|
285
|
+
|
286
|
+
def t_wrong_keys(keys)
|
287
|
+
"You must have #{keys.upcase} in environment or set it via options."
|
288
|
+
end
|
289
|
+
|
290
|
+
def attribute_eq(name, value)
|
291
|
+
stub_all_api
|
292
|
+
options = default_options_cli.merge(Hash[cli_keys].symbolize_keys).merge(:"#{name}" => value)
|
293
|
+
run "do_snapshot snap #{options_line(options)}"
|
294
|
+
end
|
295
|
+
|
296
|
+
def hash_attribute_eq(hash = {})
|
297
|
+
stub_all_api
|
298
|
+
options = default_options_cli.merge(Hash[cli_keys].symbolize_keys).merge(hash)
|
299
|
+
run "do_snapshot snap #{options_line(options)}"
|
300
|
+
end
|
301
|
+
|
302
|
+
def hash_attribute_eq_no_stub(hash)
|
303
|
+
options = default_options_cli.merge(Hash[cli_keys].symbolize_keys).merge(hash)
|
304
|
+
run "do_snapshot snap #{options_line(options)}"
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
def options_line(options = default_options_cli) # rubocop:disable Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
|
309
|
+
options.map do |key, value|
|
310
|
+
if value.is_a?(String)
|
311
|
+
"--#{key}=#{value}"
|
312
|
+
elsif value.is_a?(FalseClass)
|
313
|
+
"--no-#{key}"
|
314
|
+
elsif value.is_a?(Numeric)
|
315
|
+
"--#{key}=#{value}"
|
316
|
+
elsif value.is_a?(Array)
|
317
|
+
if value.size > 0
|
318
|
+
"--#{key}=#{value.join(' ')}"
|
319
|
+
else
|
320
|
+
nil
|
321
|
+
end
|
322
|
+
elsif value.is_a?(Hash)
|
323
|
+
if value.size > 0
|
324
|
+
items = value.map { |param, setting| "#{param}:#{setting}" }.join(' ')
|
325
|
+
"--#{key}=#{items}"
|
326
|
+
else
|
327
|
+
nil
|
328
|
+
end
|
329
|
+
else
|
330
|
+
"--#{key}"
|
331
|
+
end
|
332
|
+
end.compact.join(' ')
|
333
|
+
end
|
334
|
+
end
|
@@ -4,14 +4,12 @@ require 'spec_helper'
|
|
4
4
|
describe DoSnapshot do
|
5
5
|
include_context 'spec'
|
6
6
|
|
7
|
-
subject(:log) { DoSnapshot::Log }
|
8
|
-
|
9
7
|
describe DoSnapshot::DropletFindError do
|
10
8
|
subject(:error) { described_class }
|
11
9
|
|
12
10
|
it 'should work' do
|
13
11
|
error.new
|
14
|
-
expect(
|
12
|
+
expect(DoSnapshot.logger.buffer)
|
15
13
|
.to include 'Droplet Not Found'
|
16
14
|
end
|
17
15
|
end
|
@@ -21,7 +19,7 @@ describe DoSnapshot do
|
|
21
19
|
|
22
20
|
it 'should work' do
|
23
21
|
error.new
|
24
|
-
expect(
|
22
|
+
expect(DoSnapshot.logger.buffer)
|
25
23
|
.to include 'Droplet Listing is failed to retrieve'
|
26
24
|
end
|
27
25
|
end
|
@@ -40,7 +38,7 @@ describe DoSnapshot do
|
|
40
38
|
|
41
39
|
it 'should work' do
|
42
40
|
error.new(droplet_id)
|
43
|
-
expect(
|
41
|
+
expect(DoSnapshot.logger.buffer)
|
44
42
|
.to include "Droplet id: #{droplet_id} is Failed to Power Off."
|
45
43
|
end
|
46
44
|
end
|
@@ -50,14 +48,8 @@ describe DoSnapshot do
|
|
50
48
|
|
51
49
|
it 'should work' do
|
52
50
|
error.new(droplet_id)
|
53
|
-
expect(
|
51
|
+
expect(DoSnapshot.logger.buffer)
|
54
52
|
.to include "Droplet id: #{droplet_id} is Failed to Snapshot."
|
55
53
|
end
|
56
54
|
end
|
57
|
-
|
58
|
-
before(:each) do
|
59
|
-
log.buffer = %w()
|
60
|
-
log.verbose = false
|
61
|
-
log.quiet = true
|
62
|
-
end
|
63
55
|
end
|
@@ -4,6 +4,7 @@ require 'spec_helper'
|
|
4
4
|
shared_context 'api_v2_helpers' do
|
5
5
|
let(:api_base) { 'https://api.digitalocean.com/v2' }
|
6
6
|
let(:droplets_api_base) { "#{api_base}/droplets" }
|
7
|
+
let(:api_access_token) { "Bearer #{access_token}" }
|
7
8
|
let(:events_api_base) { "#{api_base}/droplets/[droplet_id]/actions" }
|
8
9
|
let(:actions_api_base) { "#{api_base}/actions" }
|
9
10
|
let(:images_api_base) { "#{api_base}/images" }
|
@@ -145,7 +146,7 @@ shared_context 'api_v2_helpers' do
|
|
145
146
|
# Body Helpers
|
146
147
|
#
|
147
148
|
def stub_request_body(type, request, body)
|
148
|
-
stub_response = stub_request(type, request)
|
149
|
+
stub_response = stub_request(type, request).with(headers: { 'Authorization' => api_access_token })
|
149
150
|
return stub_response.with(body: body) if body
|
150
151
|
stub_response
|
151
152
|
end
|
data/spec/shared/environment.rb
CHANGED
@@ -5,34 +5,38 @@ shared_context 'spec' do
|
|
5
5
|
include_context 'api_helpers'
|
6
6
|
|
7
7
|
def do_not_send_email
|
8
|
-
allow(Pony).to receive(:deliver)
|
8
|
+
allow(Pony).to receive(:deliver) { |mail| mail }
|
9
9
|
end
|
10
10
|
|
11
|
-
let(:client_key)
|
12
|
-
let(:api_key)
|
13
|
-
let(:access_token)
|
14
|
-
let(:event_id)
|
15
|
-
let(:droplet_id)
|
16
|
-
let(:image_id)
|
17
|
-
let(:image_id2)
|
18
|
-
let(:
|
19
|
-
let(:
|
20
|
-
let(:
|
21
|
-
let(:
|
22
|
-
let(:
|
23
|
-
let(:
|
24
|
-
let(:
|
25
|
-
let(:
|
26
|
-
let(:
|
27
|
-
let(:
|
28
|
-
let(:
|
29
|
-
let(:
|
30
|
-
let(:
|
31
|
-
let(:
|
32
|
-
let(:
|
33
|
-
let(:
|
34
|
-
let(:
|
35
|
-
let(:
|
11
|
+
let(:client_key) { 'foo' }
|
12
|
+
let(:api_key) { 'bar' }
|
13
|
+
let(:access_token) { 'sometoken' }
|
14
|
+
let(:event_id) { '7501' }
|
15
|
+
let(:droplet_id) { '100823' }
|
16
|
+
let(:image_id) { '5019770' }
|
17
|
+
let(:image_id2) { '5019903' }
|
18
|
+
let(:cli_env_nil) { Hash['DIGITAL_OCEAN_CLIENT_ID' => nil, 'DIGITAL_OCEAN_API_KEY' => nil, 'DIGITAL_OCEAN_ACCESS_TOKEN' => nil] }
|
19
|
+
let(:cli_keys) { Thor::CoreExt::HashWithIndifferentAccess.new(digital_ocean_client_id: client_key, digital_ocean_api_key: api_key, digital_ocean_access_token: access_token) }
|
20
|
+
let(:cli_keys_other) { Thor::CoreExt::HashWithIndifferentAccess.new(digital_ocean_client_id: 'NOTFOO', digital_ocean_api_key: 'NOTBAR', digital_ocean_access_token: 'NOTTOK') }
|
21
|
+
let(:snapshot_name) { "foo_#{DateTime.now.strftime('%Y_%m_%d')}" }
|
22
|
+
let(:default_options) { Hash[protocol: 1, only: %w( 100823 ), exclude: %w(), keep: 3, stop: false, trace: true, clean: true, delay: 0, timeout: 600, droplets: nil, threads: []] }
|
23
|
+
let(:default_options_cli) { default_options.reject { |key, _| %w( droplets threads ).include?(key.to_s) } }
|
24
|
+
let(:no_exclude) { [] }
|
25
|
+
let(:exclude) { %w( 100824 100825 ) }
|
26
|
+
let(:no_only) { [] }
|
27
|
+
let(:only) { %w( 100823 100824 ) }
|
28
|
+
let(:stop) { true }
|
29
|
+
let(:no_stop) { false }
|
30
|
+
let(:quiet) { true }
|
31
|
+
let(:no_quiet) { false }
|
32
|
+
let(:clean) { true }
|
33
|
+
let(:no_clean) { false }
|
34
|
+
let(:timeout) { 600 }
|
35
|
+
let(:delay) { 0 }
|
36
|
+
let(:log_path) { "#{project_path}/log/test.log" }
|
37
|
+
let(:mail_options) { Thor::CoreExt::HashWithIndifferentAccess.new(to: 'mail@somehost.com', from: 'from@host.com') }
|
38
|
+
let(:smtp_options) { Thor::CoreExt::HashWithIndifferentAccess.new(address: 'smtp.gmail.com', port: '25', user_name: 'someuser', password: 'somepassword') }
|
39
|
+
let(:log) { Thor::CoreExt::HashWithIndifferentAccess.new(log: log_path) }
|
36
40
|
|
37
41
|
def stub_all_api(droplets = nil, active = false)
|
38
42
|
drops = []
|
@@ -89,6 +93,16 @@ shared_context 'spec' do
|
|
89
93
|
ENV['DIGITAL_OCEAN_ACCESS_TOKEN'] = access_token
|
90
94
|
end
|
91
95
|
|
96
|
+
def reset_singletons
|
97
|
+
DoSnapshot.configure do |config|
|
98
|
+
# config.logger = Logger.new($stdout)
|
99
|
+
config.verbose = false
|
100
|
+
config.quiet = true
|
101
|
+
end
|
102
|
+
DoSnapshot.logger = DoSnapshot::Log.new
|
103
|
+
DoSnapshot.mailer = DoSnapshot.config.mailer
|
104
|
+
end
|
105
|
+
|
92
106
|
before(:all) do
|
93
107
|
WebMock.reset!
|
94
108
|
end
|
@@ -96,5 +110,6 @@ shared_context 'spec' do
|
|
96
110
|
before(:each) do
|
97
111
|
do_not_send_email
|
98
112
|
set_api_keys
|
113
|
+
reset_singletons
|
99
114
|
end
|
100
115
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,7 @@ end
|
|
6
6
|
|
7
7
|
require 'do_snapshot/cli'
|
8
8
|
require 'webmock/rspec'
|
9
|
+
require 'fileutils'
|
9
10
|
require 'digitalocean_c'
|
10
11
|
require_relative 'shared/api_helpers'
|
11
12
|
require_relative 'shared/api_v1_helpers'
|
@@ -17,6 +18,8 @@ require 'do_snapshot/core_ext/hash'
|
|
17
18
|
WebMock.disable_net_connect!(allow_localhost: true)
|
18
19
|
WebMock.disable!(except: [:net_http])
|
19
20
|
|
21
|
+
Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
|
22
|
+
|
20
23
|
RSpec.configure do |config|
|
21
24
|
# Pretty tests
|
22
25
|
config.color = true
|
@@ -33,5 +36,3 @@ end
|
|
33
36
|
def fixture(fixture_name)
|
34
37
|
Pathname.new(project_path + '/spec/fixtures/digitalocean/').join("#{fixture_name}.json").read
|
35
38
|
end
|
36
|
-
|
37
|
-
Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each { |f| require f }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
RSpec::Matchers.define :be_found_n_times do |str, times|
|
2
|
+
match do |output|
|
3
|
+
matches = output.scan(str)
|
4
|
+
@size = matches.size
|
5
|
+
@size == times
|
6
|
+
end
|
7
|
+
|
8
|
+
failure_message do |actual|
|
9
|
+
"was found #{size} times\nexpected that '#{str}' would be found #{times} times in:\n#{actual}"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def size
|
15
|
+
@size || 0
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: do_snapshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Merkulov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -98,10 +98,13 @@ files:
|
|
98
98
|
- lib/do_snapshot/adapter/digitalocean_v2.rb
|
99
99
|
- lib/do_snapshot/cli.rb
|
100
100
|
- lib/do_snapshot/command.rb
|
101
|
+
- lib/do_snapshot/configuration.rb
|
101
102
|
- lib/do_snapshot/core_ext/hash.rb
|
102
103
|
- lib/do_snapshot/distribution.rb
|
104
|
+
- lib/do_snapshot/helpers.rb
|
103
105
|
- lib/do_snapshot/log.rb
|
104
106
|
- lib/do_snapshot/mail.rb
|
107
|
+
- lib/do_snapshot/runner.rb
|
105
108
|
- lib/do_snapshot/version.rb
|
106
109
|
- spec/.keep
|
107
110
|
- spec/do_snapshot/adapter/abstract_spec.rb
|
@@ -109,8 +112,11 @@ files:
|
|
109
112
|
- spec/do_snapshot/adapter/digitalocean_v2_spec.rb
|
110
113
|
- spec/do_snapshot/cli_spec.rb
|
111
114
|
- spec/do_snapshot/command_spec.rb
|
115
|
+
- spec/do_snapshot/configuration_spec.rb
|
116
|
+
- spec/do_snapshot/log_spec.rb
|
112
117
|
- spec/do_snapshot/mail_spec.rb
|
113
|
-
- spec/
|
118
|
+
- spec/do_snapshot/runner_spec.rb
|
119
|
+
- spec/do_snapshot_spec.rb
|
114
120
|
- spec/fixtures/digitalocean/v1/error_message.json
|
115
121
|
- spec/fixtures/digitalocean/v1/response_event.json
|
116
122
|
- spec/fixtures/digitalocean/v1/show_droplet.json
|
@@ -138,6 +144,8 @@ files:
|
|
138
144
|
- spec/shared/environment.rb
|
139
145
|
- spec/shared/uri_helpers.rb
|
140
146
|
- spec/spec_helper.rb
|
147
|
+
- spec/support/aruba.rb
|
148
|
+
- spec/support/matchers.rb
|
141
149
|
homepage: http://dosnapshot.merqlove.ru/
|
142
150
|
licenses:
|
143
151
|
- MIT
|
@@ -170,8 +178,11 @@ test_files:
|
|
170
178
|
- spec/do_snapshot/adapter/digitalocean_v2_spec.rb
|
171
179
|
- spec/do_snapshot/cli_spec.rb
|
172
180
|
- spec/do_snapshot/command_spec.rb
|
181
|
+
- spec/do_snapshot/configuration_spec.rb
|
182
|
+
- spec/do_snapshot/log_spec.rb
|
173
183
|
- spec/do_snapshot/mail_spec.rb
|
174
|
-
- spec/
|
184
|
+
- spec/do_snapshot/runner_spec.rb
|
185
|
+
- spec/do_snapshot_spec.rb
|
175
186
|
- spec/fixtures/digitalocean/v1/error_message.json
|
176
187
|
- spec/fixtures/digitalocean/v1/response_event.json
|
177
188
|
- spec/fixtures/digitalocean/v1/show_droplet.json
|
@@ -199,3 +210,5 @@ test_files:
|
|
199
210
|
- spec/shared/environment.rb
|
200
211
|
- spec/shared/uri_helpers.rb
|
201
212
|
- spec/spec_helper.rb
|
213
|
+
- spec/support/aruba.rb
|
214
|
+
- spec/support/matchers.rb
|