do_snapshot 0.0.13 → 0.0.14
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 +4 -4
- data/lib/do_snapshot/cli.rb +2 -3
- data/lib/do_snapshot/version.rb +1 -1
- data/spec/do_snapshot/cli_spec.rb +167 -137
- data/spec/shared/environment.rb +11 -2
- metadata +2 -156
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5378c837dccf17028be844060295b82be0349b8
|
4
|
+
data.tar.gz: 4c548fa5590fb87b696c7dba43a6fa5330e2dc32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f97a8affb32bd8e371df9ec8646cc46ac6ef66f624bc9939bc156a6ce703b7055096ab0b4cfc15c1c162e25a55abf333578ce977bb0afdaee6ca662dfa11b643
|
7
|
+
data.tar.gz: b67bd75db1fe228f4e1cbd624a5ba4b2fa0f3e0c8e827e1cdcac2f8af38dab941bfb68f970a8ff2b9faaf097acb5fef9c62e33ee3d65c97a60217d6b54001bf7
|
data/lib/do_snapshot/cli.rb
CHANGED
@@ -26,8 +26,6 @@ module DoSnapshot
|
|
26
26
|
%w( digital_ocean_client_id digital_ocean_api_key ).each do |key|
|
27
27
|
ENV[key.upcase] = options[key] if options.include? key
|
28
28
|
end
|
29
|
-
|
30
|
-
try_keys_first
|
31
29
|
end
|
32
30
|
|
33
31
|
desc 'c / s / snap / create', 'DEFAULT. Create and cleanup snapshot\'s'
|
@@ -137,6 +135,7 @@ module DoSnapshot
|
|
137
135
|
desc: 'DIGITAL_OCEAN_API_KEY. if you can\'t use environment.'
|
138
136
|
|
139
137
|
def snap
|
138
|
+
try_keys_first
|
140
139
|
Command.load_options options, %w( log mail smtp trace digital_ocean_client_id digital_ocean_api_key )
|
141
140
|
Command.snap
|
142
141
|
rescue => e
|
@@ -188,7 +187,7 @@ module DoSnapshot
|
|
188
187
|
def try_keys_first
|
189
188
|
Log.debug 'Checking DigitalOcean Id\'s.'
|
190
189
|
%w( DIGITAL_OCEAN_CLIENT_ID DIGITAL_OCEAN_API_KEY ).each do |key|
|
191
|
-
Log.
|
190
|
+
Log.error "You must have #{key} in environment or set it via options." if ENV[key].blank?
|
192
191
|
end
|
193
192
|
end
|
194
193
|
end
|
data/lib/do_snapshot/version.rb
CHANGED
@@ -8,182 +8,212 @@ describe DoSnapshot::CLI do
|
|
8
8
|
subject(:command) { DoSnapshot::Command }
|
9
9
|
subject(:api) { DoSnapshot::API }
|
10
10
|
|
11
|
-
describe '.
|
12
|
-
it 'with
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
describe '.initialize' do
|
12
|
+
it 'with args & options' do
|
13
|
+
dev_null do
|
14
|
+
cli_obj = cli.new(%w(help snap), cli_keys)
|
15
|
+
expect(cli_obj.args)
|
16
|
+
.to include('help')
|
17
|
+
expect(cli_obj.options)
|
18
|
+
.to include('digital_ocean_client_id')
|
19
|
+
end
|
19
20
|
end
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
context 'commands' do
|
24
|
+
context '.snap' do
|
25
|
+
it 'with exclude' do
|
26
|
+
excluded_droplets = %w( 100824 )
|
27
|
+
stub_all_api(%w(100825 100823))
|
28
|
+
hash_attribute_eq_no_stub(exclude: excluded_droplets, only: %w())
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
30
|
+
expect(command.send('exclude'))
|
31
|
+
.to eq excluded_droplets
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'with only' do
|
35
|
+
selected_droplets = %w( 100823 )
|
36
|
+
stub_all_api(selected_droplets)
|
37
|
+
hash_attribute_eq_no_stub(only: selected_droplets)
|
38
|
+
|
39
|
+
expect(command.send('only'))
|
40
|
+
.to eq selected_droplets
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'with 1 delay' do
|
44
|
+
set_api_attribute(delay: 1, timeout: timeout)
|
45
|
+
attribute_eq 'delay', 1
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'with 0 delay' do
|
49
|
+
set_api_attribute(delay: 0, timeout: timeout)
|
50
|
+
attribute_eq 'delay', 0
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'with custom timeout' do
|
54
|
+
set_api_attribute(timeout: 1, delay: delay)
|
55
|
+
attribute_eq 'timeout', 1
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'with keep' do
|
59
|
+
attribute_eq 'keep', 7
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'with quiet' do
|
63
|
+
attribute_eq 'quiet', true
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'with no quiet' do
|
67
|
+
attribute_eq 'quiet', false
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'with stop' do
|
71
|
+
attribute_eq 'stop', true
|
72
|
+
end
|
29
73
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
74
|
+
it 'with no stop' do
|
75
|
+
attribute_eq 'stop', false
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'with clean' do
|
79
|
+
attribute_eq 'clean', true
|
80
|
+
end
|
34
81
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
82
|
+
it 'with no clean' do
|
83
|
+
attribute_eq 'clean', false
|
84
|
+
end
|
39
85
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
86
|
+
it 'with digital ocean credentials' do
|
87
|
+
with_hash_attribute_eq(cli_keys)
|
88
|
+
end
|
44
89
|
|
45
|
-
|
46
|
-
|
47
|
-
|
90
|
+
it 'with no digital ocean credentials' do
|
91
|
+
without_hash_attribute_eq(cli_keys)
|
92
|
+
end
|
48
93
|
|
49
|
-
|
50
|
-
|
51
|
-
|
94
|
+
it 'with mail' do
|
95
|
+
hash_attribute_eq(mail_options)
|
96
|
+
end
|
52
97
|
|
53
|
-
|
54
|
-
|
55
|
-
|
98
|
+
it 'with no mail' do
|
99
|
+
without_hash_attribute_eq(mail_options)
|
100
|
+
end
|
56
101
|
|
57
|
-
|
58
|
-
|
59
|
-
|
102
|
+
it 'with smtp' do
|
103
|
+
hash_attribute_eq(smtp_options)
|
104
|
+
end
|
60
105
|
|
61
|
-
|
62
|
-
|
63
|
-
|
106
|
+
it 'with no smtp' do
|
107
|
+
without_hash_attribute_eq(smtp_options)
|
108
|
+
end
|
64
109
|
|
65
|
-
|
66
|
-
|
67
|
-
|
110
|
+
it 'with log' do
|
111
|
+
hash_attribute_eq(log)
|
112
|
+
end
|
68
113
|
|
69
|
-
|
70
|
-
|
114
|
+
it 'with no log' do
|
115
|
+
without_hash_attribute_eq(log)
|
116
|
+
end
|
71
117
|
end
|
72
118
|
|
73
|
-
|
74
|
-
|
75
|
-
|
119
|
+
context '.version' do
|
120
|
+
it 'shows the correct version' do
|
121
|
+
@cli.options = @cli.options.merge(version: true)
|
122
|
+
@cli.version
|
76
123
|
|
77
|
-
|
78
|
-
|
124
|
+
expect($stdout.string.chomp)
|
125
|
+
.to eq("#{DoSnapshot::VERSION}")
|
126
|
+
end
|
79
127
|
end
|
80
128
|
|
81
|
-
|
82
|
-
|
83
|
-
|
129
|
+
context '.help' do
|
130
|
+
it 'shows a help message' do
|
131
|
+
@cli.help
|
132
|
+
expect($stdout.string)
|
133
|
+
.to match('Commands:')
|
134
|
+
end
|
84
135
|
|
85
|
-
|
86
|
-
|
87
|
-
|
136
|
+
it 'shows a help message for specific commands' do
|
137
|
+
@cli.help 'snap'
|
138
|
+
expect($stdout.string)
|
139
|
+
.to match('Usage:')
|
140
|
+
end
|
88
141
|
|
89
|
-
|
90
|
-
|
142
|
+
it 'without API keys' do
|
143
|
+
reset_api_keys
|
144
|
+
cli.new.help
|
145
|
+
expect($stdout.string)
|
146
|
+
.not_to match('You must have DIGITAL_OCEAN_CLIENT_ID in environment')
|
147
|
+
set_api_keys
|
148
|
+
end
|
91
149
|
end
|
92
150
|
|
93
|
-
|
94
|
-
|
95
|
-
|
151
|
+
def attribute_eq(name, value)
|
152
|
+
stub_all_api
|
153
|
+
options = default_options.merge!(:"#{name}" => value)
|
154
|
+
@cli.options = @cli.options.merge(options)
|
155
|
+
@cli.snap
|
96
156
|
|
97
|
-
|
98
|
-
|
157
|
+
expect(command.send(name))
|
158
|
+
.to eq value
|
99
159
|
end
|
100
160
|
|
101
|
-
|
102
|
-
|
161
|
+
def hash_attribute_eq(hash)
|
162
|
+
stub_all_api
|
163
|
+
options = default_options.merge!(hash)
|
164
|
+
@cli.options = @cli.options.merge(options)
|
165
|
+
@cli.snap
|
103
166
|
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe '.version' do
|
107
|
-
it 'shows the correct version' do
|
108
|
-
@cli.options = @cli.options.merge(version: true)
|
109
|
-
@cli.version
|
110
167
|
|
111
|
-
|
112
|
-
|
168
|
+
def with_hash_attribute_eq(hash)
|
169
|
+
hash_attribute_eq hash
|
170
|
+
expect(@cli.options)
|
171
|
+
.to include(hash)
|
113
172
|
end
|
114
|
-
end
|
115
173
|
|
116
|
-
|
117
|
-
|
118
|
-
@cli.
|
119
|
-
|
120
|
-
.to match('Commands:')
|
174
|
+
def without_hash_attribute_eq(hash)
|
175
|
+
hash_attribute_eq({})
|
176
|
+
expect(@cli.options)
|
177
|
+
.not_to include(hash)
|
121
178
|
end
|
122
179
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
180
|
+
def hash_attribute_eq_no_stub(hash)
|
181
|
+
options = default_options.merge!(hash)
|
182
|
+
@cli.options = @cli.options.merge(options)
|
183
|
+
@cli.snap
|
127
184
|
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def attribute_eq(name, value)
|
131
|
-
stub_all_api
|
132
|
-
options = default_options.merge!(:"#{name}" => value)
|
133
|
-
@cli.options = @cli.options.merge(options)
|
134
|
-
@cli.snap
|
135
|
-
|
136
|
-
expect(command.send(name))
|
137
|
-
.to eq value
|
138
|
-
end
|
139
|
-
|
140
|
-
def hash_attribute_eq(hash)
|
141
|
-
stub_all_api
|
142
|
-
options = default_options.merge!(hash)
|
143
|
-
@cli.options = @cli.options.merge(options)
|
144
|
-
@cli.snap
|
145
|
-
end
|
146
|
-
|
147
|
-
def with_hash_attribute_eq(hash)
|
148
|
-
hash_attribute_eq hash
|
149
|
-
expect(@cli.options)
|
150
|
-
.to include(hash)
|
151
|
-
end
|
152
|
-
|
153
|
-
def without_hash_attribute_eq(hash)
|
154
|
-
hash_attribute_eq({})
|
155
|
-
expect(@cli.options)
|
156
|
-
.not_to include(hash)
|
157
|
-
end
|
158
185
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
@cli.snap
|
163
|
-
end
|
186
|
+
def set_api_attribute(options = { delay: delay, timeout: timeout }) # rubocop:disable Style/AccessorMethodName
|
187
|
+
command.send('api=', api.new(options))
|
188
|
+
end
|
164
189
|
|
165
|
-
|
166
|
-
|
167
|
-
|
190
|
+
before(:each) do
|
191
|
+
$stdout.sync = true
|
192
|
+
$stderr.sync = true
|
168
193
|
|
169
|
-
|
170
|
-
$stdout.sync = true
|
171
|
-
$stderr.sync = true
|
194
|
+
@cli = cli.new
|
172
195
|
|
173
|
-
|
196
|
+
# Keep track of the old stderr / out
|
197
|
+
@orig_stderr = $stderr
|
198
|
+
@orig_stdout = $stdout
|
174
199
|
|
175
|
-
|
176
|
-
|
177
|
-
|
200
|
+
# Make them strings so we can manipulate and compare.
|
201
|
+
$stderr = StringIO.new
|
202
|
+
$stdout = StringIO.new
|
203
|
+
end
|
178
204
|
|
179
|
-
|
180
|
-
|
181
|
-
|
205
|
+
after(:each) do
|
206
|
+
# Reassign the stderr / out so rspec can have it back.
|
207
|
+
$stderr = @orig_stderr
|
208
|
+
$stdout = @orig_stdout
|
209
|
+
end
|
182
210
|
end
|
183
211
|
|
184
|
-
|
185
|
-
|
186
|
-
$
|
187
|
-
|
212
|
+
def dev_null
|
213
|
+
orig_stdout = $stdout.dup # does a dup2() internally
|
214
|
+
$stdout.reopen('/dev/null', 'w')
|
215
|
+
yield
|
216
|
+
ensure
|
217
|
+
$stdout.reopen(orig_stdout)
|
188
218
|
end
|
189
219
|
end
|
data/spec/shared/environment.rb
CHANGED
@@ -84,12 +84,21 @@ shared_context 'spec' do
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
def reset_api_keys
|
88
|
+
ENV['DIGITAL_OCEAN_API_KEY'] = nil
|
89
|
+
ENV['DIGITAL_OCEAN_CLIENT_ID'] = nil
|
90
|
+
end
|
91
|
+
|
92
|
+
def set_api_keys
|
93
|
+
ENV['DIGITAL_OCEAN_API_KEY'] = api_key
|
94
|
+
ENV['DIGITAL_OCEAN_CLIENT_ID'] = client_key
|
95
|
+
end
|
96
|
+
|
87
97
|
before(:all) do
|
88
98
|
WebMock.reset!
|
89
99
|
end
|
90
100
|
|
91
101
|
before(:each) do
|
92
|
-
|
93
|
-
ENV['DIGITAL_OCEAN_CLIENT_ID'] = client_key
|
102
|
+
set_api_keys
|
94
103
|
end
|
95
104
|
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.0.
|
4
|
+
version: 0.0.14
|
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-01-
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: digitalocean
|
@@ -52,160 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.1'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.8.7
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.8.7
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: json
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
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
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.24'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0.24'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '3.1'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '3.1'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rspec-core
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '3.1'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '3.1'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rspec-expectations
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '3.1'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '3.1'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: rspec-mocks
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '3.1'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '3.1'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: webmock
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '1.18'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '1.18'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: coveralls
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - ">="
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '0.7'
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - ">="
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '0.7'
|
181
|
-
- !ruby/object:Gem::Dependency
|
182
|
-
name: rubyzip
|
183
|
-
requirement: !ruby/object:Gem::Requirement
|
184
|
-
requirements:
|
185
|
-
- - ">="
|
186
|
-
- !ruby/object:Gem::Version
|
187
|
-
version: '0'
|
188
|
-
type: :development
|
189
|
-
prerelease: false
|
190
|
-
version_requirements: !ruby/object:Gem::Requirement
|
191
|
-
requirements:
|
192
|
-
- - ">="
|
193
|
-
- !ruby/object:Gem::Version
|
194
|
-
version: '0'
|
195
|
-
- !ruby/object:Gem::Dependency
|
196
|
-
name: s3
|
197
|
-
requirement: !ruby/object:Gem::Requirement
|
198
|
-
requirements:
|
199
|
-
- - ">="
|
200
|
-
- !ruby/object:Gem::Version
|
201
|
-
version: '0'
|
202
|
-
type: :development
|
203
|
-
prerelease: false
|
204
|
-
version_requirements: !ruby/object:Gem::Requirement
|
205
|
-
requirements:
|
206
|
-
- - ">="
|
207
|
-
- !ruby/object:Gem::Version
|
208
|
-
version: '0'
|
209
55
|
description: Snapshot creator for Digital Ocean droplets. Multi-threading inside.
|
210
56
|
Auto-cleanup feature. No matter how much droplets you have. Cron optimized.
|
211
57
|
email:
|