@@ -280,7 +280,73 @@ class Service
280
280
281
281
subject { Utils . pretty_print_hosts ( verbose , service , hostname , print_to_stderr ) }
282
282
283
- describe 'with vmpooler service' do
283
+ describe 'with vmpooler api v2 service' do
284
+ let ( :service ) { Service . new ( MockOptions . new , 'url' => url ) }
285
+
286
+ let ( :hostname ) { 'mcpy42eqjxli9g2' }
287
+ let ( :fqdn ) { [ hostname , 'delivery.puppetlabs.net' ] . join ( '.' ) }
288
+
289
+ let ( :response_body ) do
290
+ {
291
+ hostname => {
292
+ 'template' => 'ubuntu-1604-x86_64' ,
293
+ 'lifetime' => 12 ,
294
+ 'running' => 9.66 ,
295
+ 'state' => 'running' ,
296
+ 'ip' => '127.0.0.1' ,
297
+ 'fqdn' => fqdn
298
+ }
299
+ }
300
+ end
301
+
302
+ let ( :default_output ) { "- #{ fqdn } (running, ubuntu-1604-x86_64, 9.66/12 hours)" }
303
+
304
+ it 'prints output with host fqdn, template and duration info' do
305
+ expect ( $stdout) . to receive ( :puts ) . with ( default_output )
306
+
307
+ subject
308
+ end
309
+
310
+ context 'when tags are supplied' do
311
+ let ( :hostname ) { 'aiydvzpg23r415q' }
312
+ let ( :response_body ) do
313
+ {
314
+ hostname => {
315
+ 'template' => 'redhat-7-x86_64' ,
316
+ 'lifetime' => 48 ,
317
+ 'running' => 7.67 ,
318
+ 'state' => 'running' ,
319
+ 'tags' => {
320
+ 'user' => 'bob' ,
321
+ 'role' => 'agent'
322
+ } ,
323
+ 'ip' => '127.0.0.1' ,
324
+ 'fqdn' => fqdn
325
+ }
326
+ }
327
+ end
328
+
329
+ it 'prints output with host fqdn, template, duration info, and tags' do
330
+ output = "- #{ fqdn } (running, redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)"
331
+
332
+ expect ( $stdout) . to receive ( :puts ) . with ( output )
333
+
334
+ subject
335
+ end
336
+ end
337
+
338
+ context 'when print_to_stderr option is true' do
339
+ let ( :print_to_stderr ) { true }
340
+
341
+ it 'outputs to stderr instead of stdout' do
342
+ expect ( $stderr) . to receive ( :puts ) . with ( default_output )
343
+
344
+ subject
345
+ end
346
+ end
347
+ end
348
+
349
+ describe 'with vmpooler api v1 service' do
284
350
let ( :service ) { Service . new ( MockOptions . new , 'url' => url ) }
285
351
286
352
let ( :hostname ) { 'mcpy42eqjxli9g2' }
0 commit comments