From 4de3490bfe7c24939d16cc1c492242decb1f3031 Mon Sep 17 00:00:00 2001 From: "kirby@puppetlabs.com" Date: Mon, 11 May 2020 17:46:09 -0700 Subject: [PATCH] Add test cases for when ondemandvm GET is run and the request has been deleted, or marked as failed. --- spec/helpers.rb | 4 +-- spec/integration/api/v1/ondemandvm_spec.rb | 40 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/spec/helpers.rb b/spec/helpers.rb index d1019e7..87245db 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -137,8 +137,8 @@ def create_ondemand_request_for_test(request_id, score, platforms_string, redis, redis.hset("vmpooler__odrequest__#{request_id}", 'token:user', user) if user end -def set_ondemand_request_ready(request_id, redis) - redis.hset("vmpooler__odrequest__#{request_id}", 'status', 'ready') +def set_ondemand_request_status(request_id, status, redis) + redis.hset("vmpooler__odrequest__#{request_id}", 'status', status) end def create_ondemand_vm(vmname, request_id, pool, pool_alias, redis) diff --git a/spec/integration/api/v1/ondemandvm_spec.rb b/spec/integration/api/v1/ondemandvm_spec.rb index ac53383..1e0eae5 100644 --- a/spec/integration/api/v1/ondemandvm_spec.rb +++ b/spec/integration/api/v1/ondemandvm_spec.rb @@ -207,7 +207,7 @@ describe Vmpooler::API::V1 do context 'with ready instances' do before(:each) do create_ondemand_vm(vmname, uuid, 'pool1', 'pool1', redis) - set_ondemand_request_ready(uuid, redis) + set_ondemand_request_status(uuid, 'ready', redis) end it 'returns 200 with hostnames when the request is ready' do @@ -226,6 +226,44 @@ describe Vmpooler::API::V1 do expect(last_response.body).to eq(JSON.pretty_generate(expected)) end end + + context 'with a deleted request' do + before(:each) do + set_ondemand_request_status(uuid, 'deleted', redis) + end + + it 'returns a message that the request has been deleted' do + get "#{prefix}/ondemandvm/#{uuid}" + expect_json(true, 200) + expected = { + "ok": true, + "request_id": uuid, + "ready": false, + "message": "The request has been deleted" + } + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + end + end + + context 'with a failed request' do + let(:ondemand_request_ttl) { 5 } + before(:each) do + config[:config]['ondemand_request_ttl'] = ondemand_request_ttl + set_ondemand_request_status(uuid, 'failed', redis) + end + + it 'returns a message that the request has failed' do + get "#{prefix}/ondemandvm/#{uuid}" + expect_json(true, 200) + expected = { + "ok": true, + "request_id": uuid, + "ready": false, + "message": "The request failed to provision instances within the configured ondemand_request_ttl '#{ondemand_request_ttl}'" + } + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + end + end end end