(maint) Convert vm deletion specs

This commit is contained in:
Rick Bradley 2016-06-01 16:26:15 -05:00
parent 09d7f9ca92
commit 62928f4436
2 changed files with 71 additions and 68 deletions

View file

@ -28,12 +28,23 @@ def token_exists?(token)
result && !result.empty? result && !result.empty?
end end
def create_ready_vm(template, name) def create_ready_vm(template, name, token = nil)
create_vm(name, token)
redis.sadd('vmpooler__ready__' + template, name) redis.sadd('vmpooler__ready__' + template, name)
redis.hset("vmpooler_vm_#{name}", "template", template)
end end
def create_vm(name) def create_running_vm(template, name, token = nil)
create_vm(name, token)
redis.sadd('vmpooler__running__' + template, name)
redis.hset("vmpooler__vm__#{name}", "template", template)
end
def create_vm(name, token = nil)
redis.hset("vmpooler__vm__#{name}", 'checkout', Time.now) redis.hset("vmpooler__vm__#{name}", 'checkout', Time.now)
if token
redis.hset("vmpooler__vm__#{name}", 'token:token', token)
end
end end
def fetch_vm(vm) def fetch_vm(vm)

View file

@ -162,72 +162,64 @@ describe Vmpooler::API::V1 do
end end
end end
# describe 'DELETE /vm/:hostname' do describe 'DELETE /vm/:hostname' do
# context '(auth not configured)' do context '(auth not configured)' do
# let(:config) { { auth: false } } it 'does not delete a non-existant VM' do
# delete "#{prefix}/vm/testhost"
# it 'does not delete a non-existant VM' do expect_json(ok = false, http = 404)
# expect(redis).to receive(:hgetall).and_return({}) end
# expect(redis).not_to receive(:sadd)
# expect(redis).not_to receive(:srem) it 'deletes an existing VM' do
# create_running_vm('pool1', 'testhost')
# delete "#{prefix}/vm/testhost" expect fetch_vm('testhost')
#
# expect_json(ok = false, http = 404) delete "#{prefix}/vm/testhost"
# end expect_json(ok = true, http = 200)
# expect !fetch_vm('testhost')
# it 'deletes an existing VM' do end
# expect(redis).to receive(:hgetall).with('vmpooler__vm__testhost').and_return({"template" => "pool1"}) end
# expect(redis).to receive(:srem).and_return(true)
# expect(redis).to receive(:sadd) context '(auth configured)' do
# before(:each) do
# delete "#{prefix}/vm/testhost" app.settings.set :config, auth: true
# end
# expect_json(ok = true, http = 200)
# end context '(checked-out without token)' do
# end it 'deletes a VM without supplying a token' do
# create_running_vm('pool1', 'testhost')
# context '(auth configured)' do expect fetch_vm('testhost')
# let(:config) { { auth: true } }
# delete "#{prefix}/vm/testhost"
# context '(checked-out without token)' do expect_json(ok = true, http = 200)
# it 'deletes a VM without supplying a token' do expect !fetch_vm('testhost')
# expect(redis).to receive(:hgetall).with('vmpooler__vm__testhost').and_return({"template" => "pool1"}) end
# expect(redis).to receive(:srem).and_return(true) end
# expect(redis).to receive(:sadd)
# context '(checked-out with token)' do
# delete "#{prefix}/vm/testhost" it 'fails to delete a VM without supplying a token' do
# create_running_vm('pool1', 'testhost', 'abcdefghijklmnopqrstuvwxyz012345')
# expect_json(ok = true, http = 200) expect fetch_vm('testhost')
# end
# end delete "#{prefix}/vm/testhost"
# expect_json(ok = false, http = 401)
# context '(checked-out with token)' do expect fetch_vm('testhost')
# it 'fails to delete a VM without supplying a token' do end
# expect(redis).to receive(:hgetall).with('vmpooler__vm__testhost').and_return({"template" => "pool1", "token:token" => "abcdefghijklmnopqrstuvwxyz012345"})
# expect(redis).not_to receive(:sadd) it 'deletes a VM when token is supplied' do
# expect(redis).not_to receive(:srem) create_running_vm('pool1', 'testhost', 'abcdefghijklmnopqrstuvwxyz012345')
# expect fetch_vm('testhost')
# delete "#{prefix}/vm/testhost"
# delete "#{prefix}/vm/testhost", "", {
# expect_json(ok = false, http = 401) 'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
# end }
# expect_json(ok = true, http = 200)
# it 'deletes a VM when token is supplied' do
# expect(redis).to receive(:hgetall).with('vmpooler__vm__testhost').and_return({"template" => "pool1", "token:token" => "abcdefghijklmnopqrstuvwxyz012345"}) expect !fetch_vm('testhost')
# expect(redis).to receive(:srem).and_return(true) end
# expect(redis).to receive(:sadd) end
# end
# delete "#{prefix}/vm/testhost", "", { end
# 'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
# }
#
# expect_json(ok = true, http = 200)
# end
# end
# end
# end
#
# describe 'POST /vm/:hostname/snapshot' do # describe 'POST /vm/:hostname/snapshot' do
# context '(auth not configured)' do # context '(auth not configured)' do
# let(:config) { { auth: false } } # let(:config) { { auth: false } }