vmfloaty 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'logger'
2
4
 
3
5
  class FloatyLogger < ::Logger
@@ -19,22 +21,23 @@ class FloatyLogger < ::Logger
19
21
 
20
22
  def self.setlevel=(level)
21
23
  level = level.downcase
22
- if level == "debug"
23
- self.logger.level = ::Logger::DEBUG
24
- elsif level == "info"
25
- self.logger.level = ::Logger::INFO
26
- elsif level == "error"
27
- self.logger.level = ::Logger::ERROR
24
+ case level
25
+ when 'debug'
26
+ logger.level = ::Logger::DEBUG
27
+ when 'info'
28
+ logger.level = ::Logger::INFO
29
+ when 'error'
30
+ logger.level = ::Logger::ERROR
28
31
  else
29
- error("set loglevel to debug, info or error")
32
+ error('set loglevel to debug, info or error')
30
33
  end
31
34
  end
32
35
 
33
36
  def initialize
34
- super(STDERR)
37
+ super($stderr)
35
38
  self.level = ::Logger::INFO
36
- self.formatter = proc do |severity, datetime, progname, msg|
37
- "#{msg}\n"
39
+ self.formatter = proc do |_severity, _datetime, _progname, msg|
40
+ "#{msg}\n"
38
41
  end
39
42
  end
40
43
  end
@@ -22,7 +22,7 @@ class NonstandardPooler
22
22
  status['reserved_hosts'] || []
23
23
  end
24
24
 
25
- def self.retrieve(verbose, os_type, token, url, _user, _options, ondemand = nil, _continue = nil)
25
+ def self.retrieve(verbose, os_type, token, url, _user, _options, _ondemand = nil, _continue = nil)
26
26
  conn = Http.get_conn(verbose, url)
27
27
  conn.headers['X-AUTH-TOKEN'] = token if token
28
28
 
@@ -46,7 +46,8 @@ class NonstandardPooler
46
46
  raise TokenError, 'Token provided was nil; Request cannot be made to modify VM' if token.nil?
47
47
 
48
48
  modify_hash.each do |key, _value|
49
- raise ModifyError, "Configured service type does not support modification of #{key}" unless %i[reason reserved_for_reason].include? key
49
+ raise ModifyError, "Configured service type does not support modification of #{key}" unless %i[reason
50
+ reserved_for_reason].include? key
50
51
  end
51
52
 
52
53
  if modify_hash[:reason]
@@ -12,13 +12,11 @@ class Pooler
12
12
  response = conn.get 'vm'
13
13
  response_body = JSON.parse(response.body)
14
14
 
15
- hosts = if os_filter
16
- response_body.select { |i| i[/#{os_filter}/] }
17
- else
18
- response_body
19
- end
20
-
21
- hosts
15
+ if os_filter
16
+ response_body.select { |i| i[/#{os_filter}/] }
17
+ else
18
+ response_body
19
+ end
22
20
  end
23
21
 
24
22
  def self.list_active(verbose, url, token, _user)
@@ -50,7 +48,10 @@ class Pooler
50
48
  elsif response.status == 403
51
49
  raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. Request exceeds the configured per pool maximum. #{res_body}"
52
50
  else
53
- raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. #{res_body}" unless ondemand
51
+ unless ondemand
52
+ raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. #{res_body}"
53
+ end
54
+
54
55
  raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/ondemandvm/#{os_string}. #{res_body}"
55
56
  end
56
57
  end
@@ -63,7 +64,7 @@ class Pooler
63
64
  FloatyLogger.info "waiting for request #{request_id} to be fulfilled"
64
65
  sleep 5
65
66
  end
66
- FloatyLogger.info "The request has been fulfilled"
67
+ FloatyLogger.info 'The request has been fulfilled'
67
68
  check_ondemandvm(verbose, request_id, url)
68
69
  end
69
70
 
@@ -84,8 +85,9 @@ class Pooler
84
85
  def self.modify(verbose, url, hostname, token, modify_hash)
85
86
  raise TokenError, 'Token provided was nil. Request cannot be made to modify vm' if token.nil?
86
87
 
87
- modify_hash.keys.each do |key|
88
- raise ModifyError, "Configured service type does not support modification of #{key}." unless %i[tags lifetime disk].include? key
88
+ modify_hash.each_key do |key|
89
+ raise ModifyError, "Configured service type does not support modification of #{key}." unless %i[tags lifetime
90
+ disk].include? key
89
91
  end
90
92
 
91
93
  conn = Http.get_conn(verbose, url)
@@ -120,8 +122,7 @@ class Pooler
120
122
 
121
123
  response = conn.post "vm/#{hostname}/disk/#{disk}"
122
124
 
123
- res_body = JSON.parse(response.body)
124
- res_body
125
+ JSON.parse(response.body)
125
126
  end
126
127
 
127
128
  def self.delete(verbose, url, hosts, token, _user)
@@ -146,25 +147,21 @@ class Pooler
146
147
  conn = Http.get_conn(verbose, url)
147
148
 
148
149
  response = conn.get '/status'
149
- res_body = JSON.parse(response.body)
150
- res_body
150
+ JSON.parse(response.body)
151
151
  end
152
152
 
153
153
  def self.summary(verbose, url)
154
154
  conn = Http.get_conn(verbose, url)
155
155
 
156
156
  response = conn.get '/summary'
157
- res_body = JSON.parse(response.body)
158
- res_body
157
+ JSON.parse(response.body)
159
158
  end
160
159
 
161
160
  def self.query(verbose, url, hostname)
162
161
  conn = Http.get_conn(verbose, url)
163
162
 
164
163
  response = conn.get "vm/#{hostname}"
165
- res_body = JSON.parse(response.body)
166
-
167
- res_body
164
+ JSON.parse(response.body)
168
165
  end
169
166
 
170
167
  def self.snapshot(verbose, url, hostname, token)
@@ -174,8 +171,7 @@ class Pooler
174
171
  conn.headers['X-AUTH-TOKEN'] = token
175
172
 
176
173
  response = conn.post "vm/#{hostname}/snapshot"
177
- res_body = JSON.parse(response.body)
178
- res_body
174
+ JSON.parse(response.body)
179
175
  end
180
176
 
181
177
  def self.revert(verbose, url, hostname, token, snapshot_sha)
@@ -187,7 +183,6 @@ class Pooler
187
183
  raise "Snapshot SHA provided was nil, could not revert #{hostname}" if snapshot_sha.nil?
188
184
 
189
185
  response = conn.post "vm/#{hostname}/snapshot/#{snapshot_sha}"
190
- res_body = JSON.parse(response.body)
191
- res_body
186
+ JSON.parse(response.body)
192
187
  end
193
188
  end
@@ -39,7 +39,7 @@ class Service
39
39
  def user
40
40
  unless @config['user']
41
41
  FloatyLogger.info "Enter your #{@config['url']} service username:"
42
- @config['user'] = STDIN.gets.chomp
42
+ @config['user'] = $stdin.gets.chomp
43
43
  end
44
44
  @config['user']
45
45
  end
@@ -140,8 +140,8 @@ class Service
140
140
  # some methods do not exist for ABS, and if possible should target the Pooler service
141
141
  def maybe_use_vmpooler
142
142
  if @service_object == ABS # this is not an instance
143
- if !self.silent
144
- FloatyLogger.info "The service in use is ABS, but the requested method should run against vmpooler directly, using fallback_vmpooler config from ~/.vmfloaty.yml"
143
+ unless silent
144
+ FloatyLogger.info 'The service in use is ABS, but the requested method should run against vmpooler directly, using fallback_vmpooler config from ~/.vmfloaty.yml'
145
145
  self.silent = true
146
146
  end
147
147
 
@@ -39,7 +39,10 @@ class Utils
39
39
  # "engine"=>"vmpooler"
40
40
  # }
41
41
 
42
- raise ArgumentError, "Bad GET response passed to format_hosts: #{response_body.to_json}" unless response_body.delete('ok')
42
+ unless response_body.delete('ok')
43
+ raise ArgumentError,
44
+ "Bad GET response passed to format_hosts: #{response_body.to_json}"
45
+ end
43
46
 
44
47
  # vmpooler reports the domain separately from the hostname
45
48
  domain = response_body.delete('domain')
@@ -50,7 +53,7 @@ class Utils
50
53
  abs_job_id = response_body.delete('job_id')
51
54
  result['job_id'] = abs_job_id unless abs_job_id.nil?
52
55
 
53
- filtered_response_body = response_body.reject { |key, _| key == 'request_id' || key == 'ready' }
56
+ filtered_response_body = response_body.reject { |key, _| %w[request_id ready].include?(key) }
54
57
  filtered_response_body.each do |os, value|
55
58
  hostnames = Array(value['hostname'])
56
59
  hostnames.map! { |host| "#{host}.#{domain}" } if domain
@@ -106,7 +109,7 @@ class Utils
106
109
  def self.pretty_print_hosts(verbose, service, hostnames = [], print_to_stderr = false, indent = 0)
107
110
  output_target = print_to_stderr ? $stderr : $stdout
108
111
 
109
- fetched_data = self.get_host_data(verbose, service, hostnames)
112
+ fetched_data = get_host_data(verbose, service, hostnames)
110
113
  fetched_data.each do |hostname, host_data|
111
114
  case service.type
112
115
  when 'ABS'
@@ -116,13 +119,14 @@ class Utils
116
119
 
117
120
  output_target.puts "- [JobID:#{host_data['request']['job']['id']}] <#{host_data['state']}>"
118
121
  host_data['allocated_resources'].each do |allocated_resources, _i|
119
- if (allocated_resources['engine'] == "vmpooler" || allocated_resources['engine'] == 'ondemand') && service.config["vmpooler_fallback"]
122
+ if (allocated_resources['engine'] == 'vmpooler' || allocated_resources['engine'] == 'ondemand') && service.config['vmpooler_fallback']
120
123
  vmpooler_service = service.clone
121
124
  vmpooler_service.silent = true
122
125
  vmpooler_service.maybe_use_vmpooler
123
- self.pretty_print_hosts(verbose, vmpooler_service, allocated_resources['hostname'].split('.')[0], print_to_stderr, indent+2)
126
+ pretty_print_hosts(verbose, vmpooler_service, allocated_resources['hostname'].split('.')[0],
127
+ print_to_stderr, indent + 2)
124
128
  else
125
- #TODO we could add more specific metadata for the other services, nspooler and aws
129
+ # TODO: we could add more specific metadata for the other services, nspooler and aws
126
130
  output_target.puts " - #{allocated_resources['hostname']} (#{allocated_resources['type']})"
127
131
  end
128
132
  end
@@ -132,7 +136,7 @@ class Utils
132
136
  duration = "#{host_data['running']}/#{host_data['lifetime']} hours"
133
137
  metadata = [host_data['state'], host_data['template'], duration, *tag_pairs]
134
138
  message = "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})".gsub(/^/, ' ' * indent)
135
- if host_data['state'] && host_data['state'] == "destroyed"
139
+ if host_data['state'] && host_data['state'] == 'destroyed'
136
140
  output_target.puts message.colorize(:red)
137
141
  else
138
142
  output_target.puts message
@@ -153,30 +157,26 @@ class Utils
153
157
  result = {}
154
158
  hostnames = [hostnames] unless hostnames.is_a? Array
155
159
  hostnames.each do |hostname|
156
- begin
157
- response = service.query(verbose, hostname)
158
- host_data = response[hostname]
159
- if block_given?
160
- yield host_data result
160
+ response = service.query(verbose, hostname)
161
+ host_data = response[hostname]
162
+ if block_given?
163
+ yield host_data result
164
+ else
165
+ case service.type
166
+ when 'ABS'
167
+ # For ABS, 'hostname' variable is the jobID
168
+ result[hostname] = host_data if host_data['state'] == 'allocated' || host_data['state'] == 'filled'
169
+ when 'Pooler'
170
+ result[hostname] = host_data
171
+ when 'NonstandardPooler'
172
+ result[hostname] = host_data
161
173
  else
162
- case service.type
163
- when 'ABS'
164
- # For ABS, 'hostname' variable is the jobID
165
- if host_data['state'] == 'allocated' || host_data['state'] == 'filled'
166
- result[hostname] = host_data
167
- end
168
- when 'Pooler'
169
- result[hostname] = host_data
170
- when 'NonstandardPooler'
171
- result[hostname] = host_data
172
- else
173
- raise "Invalid service type #{service.type}"
174
- end
174
+ raise "Invalid service type #{service.type}"
175
175
  end
176
- rescue StandardError => e
177
- FloatyLogger.error("Something went wrong while trying to gather information on #{hostname}:")
178
- FloatyLogger.error(e)
179
176
  end
177
+ rescue StandardError => e
178
+ FloatyLogger.error("Something went wrong while trying to gather information on #{hostname}:")
179
+ FloatyLogger.error(e)
180
180
  end
181
181
  result
182
182
  end
@@ -192,16 +192,14 @@ class Utils
192
192
 
193
193
  width = pools.keys.map(&:length).max
194
194
  pools.each do |name, pool|
195
- begin
196
- max = pool['max']
197
- ready = pool['ready']
198
- pending = pool['pending']
199
- missing = max - ready - pending
200
- char = 'o'
201
- puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
202
- rescue StandardError => e
203
- FloatyLogger.error "#{name.ljust(width)} #{e.red}"
204
- end
195
+ max = pool['max']
196
+ ready = pool['ready']
197
+ pending = pool['pending']
198
+ missing = max - ready - pending
199
+ char = 'o'
200
+ puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
201
+ rescue StandardError => e
202
+ FloatyLogger.error "#{name.ljust(width)} #{e.red}"
205
203
  end
206
204
  puts message.colorize(status_response['status']['ok'] ? :default : :red)
207
205
  when 'NonstandardPooler'
@@ -211,16 +209,14 @@ class Utils
211
209
 
212
210
  width = pools.keys.map(&:length).max
213
211
  pools.each do |name, pool|
214
- begin
215
- max = pool['total_hosts']
216
- ready = pool['available_hosts']
217
- pending = pool['pending'] || 0 # not available for nspooler
218
- missing = max - ready - pending
219
- char = 'o'
220
- puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
221
- rescue StandardError => e
222
- FloatyLogger.error "#{name.ljust(width)} #{e.red}"
223
- end
212
+ max = pool['total_hosts']
213
+ ready = pool['available_hosts']
214
+ pending = pool['pending'] || 0 # not available for nspooler
215
+ missing = max - ready - pending
216
+ char = 'o'
217
+ puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
218
+ rescue StandardError => e
219
+ FloatyLogger.error "#{name.ljust(width)} #{e.red}"
224
220
  end
225
221
  when 'ABS'
226
222
  FloatyLogger.error 'ABS Not OK' unless status_response
@@ -256,11 +252,11 @@ class Utils
256
252
  def self.get_service_config(config, options)
257
253
  # The top-level url, user, and token values in the config file are treated as defaults
258
254
  service_config = {
259
- 'url' => config['url'],
260
- 'user' => config['user'],
255
+ 'url' => config['url'],
256
+ 'user' => config['user'],
261
257
  'token' => config['token'],
262
258
  'vmpooler_fallback' => config['vmpooler_fallback'],
263
- 'type' => config['type'] || 'vmpooler',
259
+ 'type' => config['type'] || 'vmpooler'
264
260
  }
265
261
 
266
262
  if config['services']
@@ -271,7 +267,10 @@ class Utils
271
267
  service_config.merge! values
272
268
  else
273
269
  # If the user provided a service name at the command line, use that service if posible, or fail
274
- raise ArgumentError, "Could not find a configured service named '#{options.service}' in ~/.vmfloaty.yml" unless config['services'][options.service]
270
+ unless config['services'][options.service]
271
+ raise ArgumentError,
272
+ "Could not find a configured service named '#{options.service}' in ~/.vmfloaty.yml"
273
+ end
275
274
 
276
275
  # If the service is configured but some values are missing, use the top-level defaults to fill them in
277
276
  service_config.merge! config['services'][options.service]
@@ -295,22 +294,22 @@ class Utils
295
294
  config = Conf.read_config
296
295
  # The top-level url, user, and token values in the config file are treated as defaults
297
296
  service_config = {
298
- 'url' => config['url'],
299
- 'user' => config['user'],
300
- 'token' => config['token'],
301
- 'type' => 'vmpooler',
297
+ 'url' => config['url'],
298
+ 'user' => config['user'],
299
+ 'token' => config['token'],
300
+ 'type' => 'vmpooler'
302
301
  }
303
302
 
304
303
  # at a minimum, the url needs to be configured
305
304
  if config['services'] && config['services'][vmpooler_fallback] && config['services'][vmpooler_fallback]['url']
306
305
  # If the service is configured but some values are missing, use the top-level defaults to fill them in
307
306
  service_config.merge! config['services'][vmpooler_fallback]
307
+ elsif vmpooler_fallback.nil?
308
+ raise ArgumentError,
309
+ "The abs service should have a key named 'vmpooler_fallback' in ~/.vmfloaty.yml with a value that points to a vmpooler service name use this format:\nservices:\n myabs:\n url: 'http://abs.com'\n user: 'superman'\n token: 'kryptonite'\n vmpooler_fallback: 'myvmpooler'\n myvmpooler:\n url: 'http://vmpooler.com'\n user: 'superman'\n token: 'kryptonite'"
308
310
  else
309
- if vmpooler_fallback.nil?
310
- raise ArgumentError, "The abs service should have a key named 'vmpooler_fallback' in ~/.vmfloaty.yml with a value that points to a vmpooler service name use this format:\nservices:\n myabs:\n url: 'http://abs.com'\n user: 'superman'\n token: 'kryptonite'\n vmpooler_fallback: 'myvmpooler'\n myvmpooler:\n url: 'http://vmpooler.com'\n user: 'superman'\n token: 'kryptonite'"
311
- else
312
- raise ArgumentError, "Could not find a configured service named '#{vmpooler_fallback}' in ~/.vmfloaty.yml use this format:\nservices:\n #{vmpooler_fallback}:\n url: 'http://vmpooler.com'\n user: 'superman'\n token: 'kryptonite'"
313
- end
311
+ raise ArgumentError,
312
+ "Could not find a configured service named '#{vmpooler_fallback}' in ~/.vmfloaty.yml use this format:\nservices:\n #{vmpooler_fallback}:\n url: 'http://vmpooler.com'\n user: 'superman'\n token: 'kryptonite'"
314
313
  end
315
314
 
316
315
  service_config
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Vmfloaty
4
- VERSION = '1.3.0'
4
+ VERSION = '1.4.0'
5
5
  end
6
-
data/spec/spec_helper.rb CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  require 'simplecov'
4
4
  require 'coveralls'
5
+ require 'base64'
5
6
 
6
7
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
7
- SimpleCov::Formatter::HTMLFormatter,
8
- Coveralls::SimpleCov::Formatter
9
- ])
8
+ SimpleCov::Formatter::HTMLFormatter,
9
+ Coveralls::SimpleCov::Formatter
10
+ ])
10
11
  SimpleCov.start do
11
12
  add_filter %r{^/spec/}
12
13
  end
@@ -26,3 +27,19 @@ RSpec.configure do |config|
26
27
  config.tty = true
27
28
  config.formatter = :documentation
28
29
  end
30
+
31
+ def get_headers(username: nil, password: nil, token: nil, content_type: nil, content_length: nil)
32
+ headers = {
33
+ 'Accept' => '*/*',
34
+ 'Accept-Encoding' => /gzip/,
35
+ 'User-Agent' => /Faraday/,
36
+ }
37
+ if username && password
38
+ auth = Base64.encode64("#{username}:#{password}").chomp
39
+ headers['Authorization'] = "Basic #{auth}"
40
+ end
41
+ headers['X-Auth-Token'] = token if token
42
+ headers['Content-Type'] = content_type if content_type
43
+ headers['Content-Length'] = content_length.to_s if content_length
44
+ headers
45
+ end
@@ -3,7 +3,11 @@
3
3
  require 'spec_helper'
4
4
  require_relative '../../../lib/vmfloaty/auth'
5
5
 
6
+ user = 'first.last'
7
+ pass = 'password'
8
+
6
9
  describe Pooler do
10
+
7
11
  before :each do
8
12
  @abs_url = 'https://abs.example.com/api/v2'
9
13
  end
@@ -15,18 +19,20 @@ describe Pooler do
15
19
  end
16
20
 
17
21
  it 'returns a token from abs' do
18
- stub_request(:post, 'https://first.last:password@abs.example.com/api/v2/token')
19
- .to_return(:status => 200, :body => @get_token_response, :headers => {})
22
+ stub_request(:post, 'https://abs.example.com/api/v2/token')
23
+ .with(headers: get_headers(username: user, password: pass, content_length: 0))
24
+ .to_return(status: 200, body: @get_token_response, headers: {})
20
25
 
21
- token = Auth.get_token(false, @abs_url, 'first.last', 'password')
26
+ token = Auth.get_token(false, @abs_url, user, pass)
22
27
  expect(token).to eq @token
23
28
  end
24
29
 
25
30
  it 'raises a token error if something goes wrong' do
26
- stub_request(:post, 'https://first.last:password@abs.example.com/api/v2/token')
27
- .to_return(:status => 500, :body => '{"ok":false}', :headers => {})
31
+ stub_request(:post, 'https://abs.example.com/api/v2/token')
32
+ .with(headers: get_headers(username: user, password: pass, content_length: 0))
33
+ .to_return(status: 500, body: '{"ok":false}', headers: {})
28
34
 
29
- expect { Auth.get_token(false, @abs_url, 'first.last', 'password') }.to raise_error(TokenError)
35
+ expect { Auth.get_token(false, @abs_url, user, pass) }.to raise_error(TokenError)
30
36
  end
31
37
  end
32
38
 
@@ -37,21 +43,24 @@ describe Pooler do
37
43
  end
38
44
 
39
45
  it 'deletes the specified token' do
40
- stub_request(:delete, 'https://first.last:password@abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
41
- .to_return(:status => 200, :body => @delete_token_response, :headers => {})
46
+ stub_request(:delete, 'https://abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
47
+ .with(headers: get_headers(username: user, password: pass))
48
+ .to_return(status: 200, body: @delete_token_response, headers: {})
42
49
 
43
- expect(Auth.delete_token(false, @abs_url, 'first.last', 'password', @token)).to eq JSON.parse(@delete_token_response)
50
+ expect(Auth.delete_token(false, @abs_url, user, pass,
51
+ @token)).to eq JSON.parse(@delete_token_response)
44
52
  end
45
53
 
46
54
  it 'raises a token error if something goes wrong' do
47
- stub_request(:delete, 'https://first.last:password@abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
48
- .to_return(:status => 500, :body => '{"ok":false}', :headers => {})
55
+ stub_request(:delete, 'https://abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
56
+ .with(headers: get_headers(username: user, password: pass))
57
+ .to_return(status: 500, body: '{"ok":false}', headers: {})
49
58
 
50
- expect { Auth.delete_token(false, @abs_url, 'first.last', 'password', @token) }.to raise_error(TokenError)
59
+ expect { Auth.delete_token(false, @abs_url, user, pass, @token) }.to raise_error(TokenError)
51
60
  end
52
61
 
53
62
  it 'raises a token error if no token provided' do
54
- expect { Auth.delete_token(false, @abs_url, 'first.last', 'password', nil) }.to raise_error(TokenError)
63
+ expect { Auth.delete_token(false, @abs_url, user, pass, nil) }.to raise_error(TokenError)
55
64
  end
56
65
  end
57
66
 
@@ -63,16 +72,16 @@ describe Pooler do
63
72
 
64
73
  it 'checks the status of a token' do
65
74
  stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
66
- .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' })
67
- .to_return(:status => 200, :body => @token_status_response, :headers => {})
75
+ .with(headers: get_headers)
76
+ .to_return(status: 200, body: @token_status_response, headers: {})
68
77
 
69
78
  expect(Auth.token_status(false, @abs_url, @token)).to eq JSON.parse(@token_status_response)
70
79
  end
71
80
 
72
81
  it 'raises a token error if something goes wrong' do
73
82
  stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
74
- .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' })
75
- .to_return(:status => 500, :body => '{"ok":false}', :headers => {})
83
+ .with(headers: get_headers)
84
+ .to_return(status: 500, body: '{"ok":false}', headers: {})
76
85
 
77
86
  expect { Auth.token_status(false, @abs_url, @token) }.to raise_error(TokenError)
78
87
  end