do_snapshot 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd8a67c728fd77180645b3ea87ee37db50ab627e
4
- data.tar.gz: e3196ed56ad208a890c3be2f55bb02cb7499a06f
3
+ metadata.gz: d5378c837dccf17028be844060295b82be0349b8
4
+ data.tar.gz: 4c548fa5590fb87b696c7dba43a6fa5330e2dc32
5
5
  SHA512:
6
- metadata.gz: 1f91dd0dc2e68e03eb59a48e7e2077893d2d4574d6f2fc2900070adcaa1c9c580b9d001ece9283d34da67fdbe4ec93e0ed8894d0f74e446b774f3837ed4f1a44
7
- data.tar.gz: 7a27ff1d46bc31ffd257ae77f0e474408172d4dc6dd755615215dedf280e842f88c1fe543b099ca522bf552a8ec070744d4d7ee661a712638e9d0211495aafbb
6
+ metadata.gz: f97a8affb32bd8e371df9ec8646cc46ac6ef66f624bc9939bc156a6ce703b7055096ab0b4cfc15c1c162e25a55abf333578ce977bb0afdaee6ca662dfa11b643
7
+ data.tar.gz: b67bd75db1fe228f4e1cbd624a5ba4b2fa0f3e0c8e827e1cdcac2f8af38dab941bfb68f970a8ff2b9faaf097acb5fef9c62e33ee3d65c97a60217d6b54001bf7
@@ -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.fail Thor::Error, "You must have #{key} in environment or set it via options." if !ENV[key] || ENV[key].empty?
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
@@ -2,5 +2,5 @@
2
2
  # Current version
3
3
  #
4
4
  module DoSnapshot
5
- VERSION = '0.0.13'
5
+ VERSION = '0.0.14'
6
6
  end
@@ -8,182 +8,212 @@ describe DoSnapshot::CLI do
8
8
  subject(:command) { DoSnapshot::Command }
9
9
  subject(:api) { DoSnapshot::API }
10
10
 
11
- describe '.snap' do
12
- it 'with exclude' do
13
- excluded_droplets = %w( 100824 )
14
- stub_all_api(%w(100825 100823))
15
- hash_attribute_eq_no_stub(exclude: excluded_droplets, only: %w())
16
-
17
- expect(command.send('exclude'))
18
- .to eq excluded_droplets
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
- it 'with only' do
22
- selected_droplets = %w( 100823 )
23
- stub_all_api(selected_droplets)
24
- hash_attribute_eq_no_stub(only: selected_droplets)
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
- expect(command.send('only'))
27
- .to eq selected_droplets
28
- end
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
- it 'with 1 delay' do
31
- set_api_attribute(delay: 1, timeout: timeout)
32
- attribute_eq 'delay', 1
33
- end
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
- it 'with 0 delay' do
36
- set_api_attribute(delay: 0, timeout: timeout)
37
- attribute_eq 'delay', 0
38
- end
82
+ it 'with no clean' do
83
+ attribute_eq 'clean', false
84
+ end
39
85
 
40
- it 'with custom timeout' do
41
- set_api_attribute(timeout: 1, delay: delay)
42
- attribute_eq 'timeout', 1
43
- end
86
+ it 'with digital ocean credentials' do
87
+ with_hash_attribute_eq(cli_keys)
88
+ end
44
89
 
45
- it 'with keep' do
46
- attribute_eq 'keep', 7
47
- end
90
+ it 'with no digital ocean credentials' do
91
+ without_hash_attribute_eq(cli_keys)
92
+ end
48
93
 
49
- it 'with quiet' do
50
- attribute_eq 'quiet', true
51
- end
94
+ it 'with mail' do
95
+ hash_attribute_eq(mail_options)
96
+ end
52
97
 
53
- it 'with no quiet' do
54
- attribute_eq 'quiet', false
55
- end
98
+ it 'with no mail' do
99
+ without_hash_attribute_eq(mail_options)
100
+ end
56
101
 
57
- it 'with stop' do
58
- attribute_eq 'stop', true
59
- end
102
+ it 'with smtp' do
103
+ hash_attribute_eq(smtp_options)
104
+ end
60
105
 
61
- it 'with no stop' do
62
- attribute_eq 'stop', false
63
- end
106
+ it 'with no smtp' do
107
+ without_hash_attribute_eq(smtp_options)
108
+ end
64
109
 
65
- it 'with clean' do
66
- attribute_eq 'clean', true
67
- end
110
+ it 'with log' do
111
+ hash_attribute_eq(log)
112
+ end
68
113
 
69
- it 'with no clean' do
70
- attribute_eq 'clean', false
114
+ it 'with no log' do
115
+ without_hash_attribute_eq(log)
116
+ end
71
117
  end
72
118
 
73
- it 'with digital ocean credentials' do
74
- with_hash_attribute_eq(cli_keys)
75
- end
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
- it 'with no digital ocean credentials' do
78
- without_hash_attribute_eq(cli_keys)
124
+ expect($stdout.string.chomp)
125
+ .to eq("#{DoSnapshot::VERSION}")
126
+ end
79
127
  end
80
128
 
81
- it 'with mail' do
82
- hash_attribute_eq(mail_options)
83
- end
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
- it 'with no mail' do
86
- without_hash_attribute_eq(mail_options)
87
- end
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
- it 'with smtp' do
90
- hash_attribute_eq(smtp_options)
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
- it 'with no smtp' do
94
- without_hash_attribute_eq(smtp_options)
95
- end
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
- it 'with log' do
98
- hash_attribute_eq(log)
157
+ expect(command.send(name))
158
+ .to eq value
99
159
  end
100
160
 
101
- it 'with no log' do
102
- without_hash_attribute_eq(log)
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
- expect($stdout.string.chomp)
112
- .to eq("#{DoSnapshot::VERSION}")
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
- describe '.help' do
117
- it 'shows a help message' do
118
- @cli.help
119
- expect($stdout.string)
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
- it 'shows a help message for specific commands' do
124
- @cli.help 'snap'
125
- expect($stdout.string)
126
- .to match('Usage:')
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
- def hash_attribute_eq_no_stub(hash)
160
- options = default_options.merge!(hash)
161
- @cli.options = @cli.options.merge(options)
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
- def set_api_attribute(options = { delay: delay, timeout: timeout }) # rubocop:disable Style/AccessorMethodName
166
- command.send('api=', api.new(options))
167
- end
190
+ before(:each) do
191
+ $stdout.sync = true
192
+ $stderr.sync = true
168
193
 
169
- before(:each) do
170
- $stdout.sync = true
171
- $stderr.sync = true
194
+ @cli = cli.new
172
195
 
173
- @cli = cli.new
196
+ # Keep track of the old stderr / out
197
+ @orig_stderr = $stderr
198
+ @orig_stdout = $stdout
174
199
 
175
- # Keep track of the old stderr / out
176
- @orig_stderr = $stderr
177
- @orig_stdout = $stdout
200
+ # Make them strings so we can manipulate and compare.
201
+ $stderr = StringIO.new
202
+ $stdout = StringIO.new
203
+ end
178
204
 
179
- # Make them strings so we can manipulate and compare.
180
- $stderr = StringIO.new
181
- $stdout = StringIO.new
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
- after(:each) do
185
- # Reassign the stderr / out so rspec can have it back.
186
- $stderr = @orig_stderr
187
- $stdout = @orig_stdout
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
@@ -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
- ENV['DIGITAL_OCEAN_API_KEY'] = api_key
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.13
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-10 00:00:00.000000000 Z
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: