Skip to content

Commit cd7c0fa

Browse files
author
Samuel Beaulieu
committed
Adding spec tests for #list
1 parent 4df970b commit cd7c0fa

File tree

2 files changed

+56
-12
lines changed

2 files changed

+56
-12
lines changed

lib/vmfloaty/abs.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ def self.list(verbose, url, os_filter = nil)
172172
res_body = JSON.parse(res.body)
173173
if res_body.key?('vmpooler_platforms')
174174
os_list << '*** VMPOOLER Pools ***'
175-
if res_body['vmpooler_platforms'].is_a?(Hash)
176-
os_list += res_body['vmpooler_platforms']
177-
else
175+
if res_body['vmpooler_platforms'].is_a?(String)
178176
os_list += JSON.parse(res_body['vmpooler_platforms']) # legacy ABS had another JSON string always-be-scheduling/pull/306
177+
else
178+
os_list += res_body['vmpooler_platforms']
179179
end
180180
end
181181
end
@@ -186,10 +186,10 @@ def self.list(verbose, url, os_filter = nil)
186186
if res_body.key?('ondemand_vmpooler_platforms') && res_body['ondemand_vmpooler_platforms'] != '[]'
187187
os_list << ''
188188
os_list << '*** VMPOOLER ONDEMAND Pools ***'
189-
if res_body['ondemand_vmpooler_platforms'].is_a?(Hash)
190-
os_list += res_body['ondemand_vmpooler_platforms']
191-
else
189+
if res_body['ondemand_vmpooler_platforms'].is_a?(String)
192190
os_list += JSON.parse(res_body['ondemand_vmpooler_platforms']) # legacy ABS had another JSON string always-be-scheduling/pull/306
191+
else
192+
os_list += res_body['ondemand_vmpooler_platforms']
193193
end
194194
end
195195
end
@@ -200,10 +200,10 @@ def self.list(verbose, url, os_filter = nil)
200200
if res_body.key?('nspooler_platforms')
201201
os_list << ''
202202
os_list << '*** NSPOOLER Pools ***'
203-
if res_body['nspooler_platforms'].is_a?(Hash)
204-
os_list += res_body['nspooler_platforms']
205-
else
203+
if res_body['nspooler_platforms'].is_a?(String)
206204
os_list += JSON.parse(res_body['nspooler_platforms']) # legacy ABS had another JSON string always-be-scheduling/pull/306
205+
else
206+
os_list += res_body['nspooler_platforms']
207207
end
208208
end
209209
end
@@ -214,10 +214,10 @@ def self.list(verbose, url, os_filter = nil)
214214
if res_body.key?('aws_platforms')
215215
os_list << ''
216216
os_list << '*** AWS Pools ***'
217-
if res_body['aws_platforms'].is_a?(Hash)
218-
os_list += res_body['aws_platforms']
219-
else
217+
if res_body['aws_platforms'].is_a?(String)
220218
os_list += JSON.parse(res_body['aws_platforms']) # legacy ABS had another JSON string always-be-scheduling/pull/306
219+
else
220+
os_list += res_body['aws_platforms']
221221
end
222222
end
223223
end

spec/vmfloaty/abs_spec.rb

+44
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,50 @@
99
before :each do
1010
end
1111

12+
describe '#list' do
13+
it 'skips empty platforms and lists aws' do
14+
stub_request(:get, "http://foo/status/platforms/vmpooler").
15+
to_return(:status => 200, :body => "", :headers => {})
16+
stub_request(:get, "http://foo/status/platforms/ondemand_vmpooler").
17+
to_return(:status => 200, :body => "", :headers => {})
18+
stub_request(:get, "http://foo/status/platforms/nspooler").
19+
to_return(:status => 200, :body => "", :headers => {})
20+
body = '{
21+
"aws_platforms": [
22+
"amazon-6-x86_64",
23+
"amazon-7-x86_64",
24+
"amazon-7-arm64",
25+
"centos-7-x86-64-west",
26+
"redhat-8-arm64"
27+
]
28+
}'
29+
stub_request(:get, "http://foo/status/platforms/aws").
30+
to_return(:status => 200, :body => body, :headers => {})
31+
32+
33+
results = ABS.list(false, "http://foo")
34+
35+
expect(results).to include("amazon-6-x86_64", "amazon-7-x86_64", "amazon-7-arm64", "centos-7-x86-64-west", "redhat-8-arm64")
36+
end
37+
it 'legacy JSON string, prior to PR 306' do
38+
stub_request(:get, "http://foo/status/platforms/vmpooler").
39+
to_return(:status => 200, :body => "", :headers => {})
40+
stub_request(:get, "http://foo/status/platforms/ondemand_vmpooler").
41+
to_return(:status => 200, :body => "", :headers => {})
42+
stub_request(:get, "http://foo/status/platforms/nspooler").
43+
to_return(:status => 200, :body => "", :headers => {})
44+
body = '{
45+
"aws_platforms": "[\"amazon-6-x86_64\",\"amazon-7-x86_64\",\"amazon-7-arm64\",\"centos-7-x86-64-west\",\"redhat-8-arm64\"]"
46+
}'
47+
stub_request(:get, "http://foo/status/platforms/aws").
48+
to_return(:status => 200, :body => body, :headers => {})
49+
50+
results = ABS.list(false, "http://foo")
51+
52+
expect(results).to include("amazon-6-x86_64", "amazon-7-x86_64", "amazon-7-arm64", "centos-7-x86-64-west", "redhat-8-arm64")
53+
end
54+
end
55+
1256
describe '#format' do
1357
it 'returns an hash formatted like a vmpooler return, plus the job_id' do
1458
job_id = "generated_by_floaty_12345"

0 commit comments

Comments
 (0)