(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?
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.hset("vmpooler_vm_#{name}", "template", template)
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)
if token
redis.hset("vmpooler__vm__#{name}", 'token:token', token)
end
end
def fetch_vm(vm)

View file

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