do_snapshot 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,114 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ shared_context 'spec' do
5
+ include_context 'api_helpers'
6
+
7
+ let(:client_key) { 'foo' }
8
+ let(:api_key) { 'bar' }
9
+ let(:event_id) { '7501' }
10
+ let(:droplet_id) { '100823' }
11
+ let(:image_id) { '5019770' }
12
+ let(:image_id2) { '5019903' }
13
+ let(:cli_keys) { Thor::CoreExt::HashWithIndifferentAccess.new(digital_ocean_client_id: 'NOTFOO', digital_ocean_client_bar: 'NOTBAR') }
14
+ let(:snapshot_name) { "foo_#{DateTime.now.strftime('%Y_%m_%d')}" }
15
+ let(:default_options) { Hash[only: %w( 100823 ), exclude: %w(), keep: 3, trace: true, clean: true, delay: 0, timeout: 180] }
16
+ let(:no_exclude) { [] }
17
+ let(:exclude) { %w( 100824 100825 ) }
18
+ let(:no_only) { [] }
19
+ let(:only) { %w( 100823 100824 ) }
20
+ let(:stop) { true }
21
+ let(:no_stop) { false }
22
+ let(:quiet) { true }
23
+ let(:no_quiet) { false }
24
+ let(:clean) { true }
25
+ let(:no_clean) { false }
26
+ let(:timeout) { 180 }
27
+ let(:delay) { 0 }
28
+ let(:mail_options) { Thor::CoreExt::HashWithIndifferentAccess.new(to: 'mail@somehost.com', from: 'from@host.com') }
29
+ let(:smtp_options) { Thor::CoreExt::HashWithIndifferentAccess.new(address: 'smtp.gmail.com', port: '25', user_name: 'someuser', password: 'somepassword') }
30
+ let(:log) { Thor::CoreExt::HashWithIndifferentAccess.new(log: "#{project_path}/log/test.log") }
31
+ let(:api_base) { 'https://api.digitalocean.com/v1' }
32
+ let(:keys_uri) { "api_key=#{api_key}&client_id=#{client_key}" }
33
+ let(:droplets_api_base) { "#{api_base}/droplets" }
34
+ let(:events_api_base) { "#{api_base}/events" }
35
+ let(:images_api_base) { "#{api_base}/images" }
36
+ let(:image_destroy_uri) { "#{images_api_base}/[id]/destroy/?#{keys_uri}" }
37
+ let(:droplets_uri) { "#{droplets_api_base}/?#{keys_uri}" }
38
+ let(:droplet_find_uri) { "#{droplets_api_base}/[id]?#{keys_uri}" }
39
+ let(:droplet_stop_uri) { "#{droplets_api_base}/[id]/power_off/?#{keys_uri}" }
40
+ let(:droplet_start_uri) { "#{droplets_api_base}/[id]/power_on/?#{keys_uri}" }
41
+ let(:snapshot_uri) { "#{droplets_api_base}/[id]/snapshot/?name=[name]&#{keys_uri}" }
42
+ let(:event_find_uri) { "#{events_api_base}/[id]/?#{keys_uri}" }
43
+
44
+ before(:each) do
45
+ $stdout.sync = true
46
+ $stderr.sync = true
47
+
48
+ ENV['DIGITAL_OCEAN_API_KEY'] = api_key
49
+ ENV['DIGITAL_OCEAN_CLIENT_ID'] = client_key
50
+
51
+ @cli = DoSnapshot::CLI.new
52
+
53
+ # Keep track of the old stderr / out
54
+ @orig_stderr = $stderr
55
+ @orig_stdout = $stdout
56
+
57
+ # Make them strings so we can manipulate and compare.
58
+ $stderr = StringIO.new
59
+ $stdout = StringIO.new
60
+ end
61
+
62
+ after(:each) do
63
+ # Reassign the stderr / out so rspec can have it back.
64
+ $stderr = @orig_stderr
65
+ $stdout = @orig_stdout
66
+ end
67
+
68
+ def stub_all_api(droplets = nil, active = false) # rubocop:disable MethodLength
69
+ drops = []
70
+ droplets ||= [droplet_id]
71
+ droplets.each do |droplet|
72
+ drops.push Hash[
73
+ stub_droplet: (active ? stub_droplet(droplet) : stub_droplet_inactive(droplet))
74
+ ].merge(stub_droplet_api(droplet))
75
+ end
76
+ stubs = Hash[drops: drops]
77
+ @stubs = stubs.merge(default_stub_api)
78
+ end
79
+
80
+ def stub_droplet_api(droplet)
81
+ {
82
+ stub_droplet_stop: stub_droplet_stop(droplet),
83
+ stub_droplet_start: stub_droplet_start(droplet),
84
+ stub_droplet_snapshot: stub_droplet_snapshot(droplet, snapshot_name)
85
+ }
86
+ end
87
+
88
+ def default_stub_api
89
+ {
90
+ stub_event_done: stub_event_done(event_id),
91
+ stub_droplets: stub_droplets,
92
+ stub_image_destroy1: stub_image_destroy(image_id),
93
+ stub_image_destroy2: stub_image_destroy(image_id2)
94
+ }
95
+ end
96
+
97
+ def stub_cleanup
98
+ @stubs ||= {}
99
+ @stubs.each_pair do |_k, v|
100
+ remove_request_stub(v) if v.class == WebMock::RequestStub
101
+ next unless v.class == Array
102
+
103
+ v.each do |d|
104
+ d.each_pair do |_dk, dv|
105
+ remove_request_stub(dv) if v.class == WebMock::RequestStub
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ before(:all) do
112
+ WebMock.reset!
113
+ end
114
+ end
@@ -0,0 +1,12 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ shared_context 'uri_helpers' do
5
+ let(:droplet_url) { url_with_id(droplet_find_uri, droplet_id) }
6
+ let(:droplet_stop_url) { url_with_id(droplet_stop_uri, droplet_id) }
7
+ let(:droplet_start_url) { url_with_id(droplet_start_uri, droplet_id) }
8
+ let(:event_find_url) { url_with_id(event_find_uri, event_id) }
9
+ let(:image_destroy_url) { url_with_id(image_destroy_uri, image_id) }
10
+ let(:image_destroy2_url) { url_with_id(image_destroy_uri, image_id2) }
11
+ let(:droplet_snapshot_url) { url_with_id_name(snapshot_uri, droplet_id, snapshot_name) }
12
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'coveralls'
3
+ Coveralls.wear! do
4
+ add_filter '/spec/*'
5
+ end
6
+
7
+ require 'do_snapshot/cli'
8
+ require 'webmock/rspec'
9
+ require 'digitalocean'
10
+ require 'shared/api_helpers'
11
+ require 'shared/uri_helpers'
12
+ require 'shared/environment'
13
+ require 'shared/uri_helpers'
14
+ require 'do_snapshot/core_ext/hash'
15
+
16
+ RSpec.configure do |config|
17
+ # Pretty tests
18
+ config.color = true
19
+
20
+ config.order = :random
21
+ config.mock_with :rspec do |mocks|
22
+ mocks.verify_doubled_constant_names = true
23
+ end
24
+ end
25
+
26
+ def project_path
27
+ File.expand_path('../..', __FILE__)
28
+ end
29
+
30
+ def fixture(fixture_name)
31
+ File.new(project_path + "/spec/fixtures/#{fixture_name}.json")
32
+ end
33
+
34
+ Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each { |f| require f }
data/tmp/.keep ADDED
File without changes
metadata CHANGED
@@ -1,85 +1,169 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do_snapshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Merkulov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: digitalocean
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: thor
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.19.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.19.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pony
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.6'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.6'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - ! '>='
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-core
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-expectations
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 3.0.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 3.0.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-mocks
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 3.0.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 3.0.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 1.18.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: 1.18.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: coveralls
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: 0.7.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: 0.7.0
83
167
  description: Snapshot creator for Digital Ocean droplets. Multi-threading inside.
84
168
  Auto-cleanup feature. No matter how much droplets you have. Cron optimized.
85
169
  email:
@@ -89,9 +173,10 @@ executables:
89
173
  extensions: []
90
174
  extra_rdoc_files: []
91
175
  files:
92
- - ".gitignore"
93
- - ".rubocop.yml"
94
- - ".ruby-version"
176
+ - .gitignore
177
+ - .rubocop.yml
178
+ - .ruby-version
179
+ - .travis.yml
95
180
  - Gemfile
96
181
  - LICENSE.txt
97
182
  - README.md
@@ -99,11 +184,32 @@ files:
99
184
  - bin/do_snapshot
100
185
  - do_snapshot.gemspec
101
186
  - lib/do_snapshot.rb
187
+ - lib/do_snapshot/api.rb
102
188
  - lib/do_snapshot/cli.rb
103
189
  - lib/do_snapshot/command.rb
104
190
  - lib/do_snapshot/core_ext/hash.rb
191
+ - lib/do_snapshot/log.rb
192
+ - lib/do_snapshot/mail.rb
105
193
  - lib/do_snapshot/version.rb
106
- - test/.keep
194
+ - log/.keep
195
+ - spec/.keep
196
+ - spec/do_snapshot/api_spec.rb
197
+ - spec/do_snapshot/cli_spec.rb
198
+ - spec/do_snapshot/command_spec.rb
199
+ - spec/do_snapshots_spec.rb
200
+ - spec/fixtures/error_message.json
201
+ - spec/fixtures/response_event.json
202
+ - spec/fixtures/show_droplet.json
203
+ - spec/fixtures/show_droplet_inactive.json
204
+ - spec/fixtures/show_droplets.json
205
+ - spec/fixtures/show_droplets_empty.json
206
+ - spec/fixtures/show_event_done.json
207
+ - spec/fixtures/show_event_start.json
208
+ - spec/shared/api_helpers.rb
209
+ - spec/shared/environment.rb
210
+ - spec/shared/uri_helpers.rb
211
+ - spec/spec_helper.rb
212
+ - tmp/.keep
107
213
  homepage: http://github.com/merqlove/do_snapshot
108
214
  licenses:
109
215
  - MIT
@@ -114,12 +220,12 @@ require_paths:
114
220
  - lib
115
221
  required_ruby_version: !ruby/object:Gem::Requirement
116
222
  requirements:
117
- - - ">="
223
+ - - ! '>='
118
224
  - !ruby/object:Gem::Version
119
225
  version: '0'
120
226
  required_rubygems_version: !ruby/object:Gem::Requirement
121
227
  requirements:
122
- - - ">="
228
+ - - ! '>='
123
229
  - !ruby/object:Gem::Version
124
230
  version: '0'
125
231
  requirements: []
@@ -130,4 +236,20 @@ specification_version: 4
130
236
  summary: Snapshot creator for Digital Ocean droplets. Multi-threading. Auto-cleanup.
131
237
  Cron optimized.
132
238
  test_files:
133
- - test/.keep
239
+ - spec/.keep
240
+ - spec/do_snapshot/api_spec.rb
241
+ - spec/do_snapshot/cli_spec.rb
242
+ - spec/do_snapshot/command_spec.rb
243
+ - spec/do_snapshots_spec.rb
244
+ - spec/fixtures/error_message.json
245
+ - spec/fixtures/response_event.json
246
+ - spec/fixtures/show_droplet.json
247
+ - spec/fixtures/show_droplet_inactive.json
248
+ - spec/fixtures/show_droplets.json
249
+ - spec/fixtures/show_droplets_empty.json
250
+ - spec/fixtures/show_event_done.json
251
+ - spec/fixtures/show_event_start.json
252
+ - spec/shared/api_helpers.rb
253
+ - spec/shared/environment.rb
254
+ - spec/shared/uri_helpers.rb
255
+ - spec/spec_helper.rb