diff --git a/spec/helpers.rb b/spec/helpers.rb index a91c987..140d9b0 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -12,3 +12,31 @@ def expect_json( expect(last_response.status).to eq(http) end + +def create_token(token, user, timestamp) + redis.hset("vmpooler__token__#{token}", 'user', user) + redis.hset("vmpooler__token__#{token}", 'created', timestamp) +end + +def get_token_data(token) + redis.hgetall("vmpooler__token__#{token}") +end + +def token_exists?(token) + result = get_token_data + result && !result.empty? +end + +def create_vm(template, name) + redis.sadd('vmpooler__ready__' + template, name) +end + +def fetch_vm(vm) + redis.hgetall("vmpooler__vm__#{vm}") +end + +def clear_pool(pool) + ['ready'].each do |state| # TODO add more states if desired + redis.del("vmpooler__#{state}__#{pool}") + end +end diff --git a/spec/vmpooler/api/v1/token_spec.rb b/spec/vmpooler/api/v1/token_spec.rb index 67fc9d5..6308a59 100644 --- a/spec/vmpooler/api/v1/token_spec.rb +++ b/spec/vmpooler/api/v1/token_spec.rb @@ -15,20 +15,6 @@ def redis @redis ||= Redis.new end -def create_token(token, user, timestamp) - redis.hset("vmpooler__token__#{token}", 'user', user) - redis.hset("vmpooler__token__#{token}", 'created', timestamp) -end - -def get_token_data(token) - redis.hgetall("vmpooler__token__#{token}") -end - -def token_exists?(token) - result = get_token_data - result && !result.empty? -end - describe Vmpooler::API::V1 do include Rack::Test::Methods diff --git a/spec/vmpooler/api/v1/vm_spec.rb b/spec/vmpooler/api/v1/vm_spec.rb index aeb7dda..1038b94 100644 --- a/spec/vmpooler/api/v1/vm_spec.rb +++ b/spec/vmpooler/api/v1/vm_spec.rb @@ -15,25 +15,6 @@ def redis @redis ||= Redis.new end -def create_token(token, user, timestamp) - redis.hset("vmpooler__token__#{token}", 'user', user) - redis.hset("vmpooler__token__#{token}", 'created', timestamp) -end - -def create_vm(template, name) - redis.sadd('vmpooler__ready__' + template, name) -end - -def fetch_vm(vm) - redis.hgetall("vmpooler__vm__#{vm}") -end - -def clear_pool(pool) - ['ready'].each do |state| # TODO add more states if desired - redis.del("vmpooler__#{state}__#{pool}") - end -end - describe Vmpooler::API::V1 do include Rack::Test::Methods diff --git a/spec/vmpooler/api/v1/vm_template_spec.rb b/spec/vmpooler/api/v1/vm_template_spec.rb index eb1c884..3a09a87 100644 --- a/spec/vmpooler/api/v1/vm_template_spec.rb +++ b/spec/vmpooler/api/v1/vm_template_spec.rb @@ -15,25 +15,6 @@ def redis @redis ||= Redis.new end -def create_token(token, user, timestamp) - redis.hset("vmpooler__token__#{token}", 'user', user) - redis.hset("vmpooler__token__#{token}", 'created', timestamp) -end - -def create_vm(template, name) - redis.sadd('vmpooler__ready__' + template, name) -end - -def fetch_vm(vm) - redis.hgetall("vmpooler__vm__#{vm}") -end - -def clear_pool(pool) - ['ready'].each do |state| # TODO add more states if desired - redis.del("vmpooler__#{state}__#{pool}") - end -end - describe Vmpooler::API::V1 do include Rack::Test::Methods