mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
- Fixes tests to run in both mock and non-mock mode
- Clean ups and fixes
This commit is contained in:
parent
b89708b26e
commit
4ff115c1de
9 changed files with 92 additions and 55 deletions
|
@ -147,6 +147,7 @@ module Fog
|
||||||
|
|
||||||
if response.headers["Content-Type"] == "application/json"
|
if response.headers["Content-Type"] == "application/json"
|
||||||
response.body = MultiJson.decode(response.body)
|
response.body = MultiJson.decode(response.body)
|
||||||
|
response.body = decode_time_props(response.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
response
|
response
|
||||||
|
@ -171,6 +172,22 @@ module Fog
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def decode_time_props(obj)
|
||||||
|
if obj.kind_of?(Hash)
|
||||||
|
if obj["created"]
|
||||||
|
obj["created"] = Time.parse(obj["created"])
|
||||||
|
end
|
||||||
|
|
||||||
|
if obj["updated"]
|
||||||
|
obj["updated"] = Time.parse(obj["updated"])
|
||||||
|
end
|
||||||
|
elsif obj.kind_of?(Array)
|
||||||
|
obj.map do |o|
|
||||||
|
decode_time_props(o)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
obj
|
||||||
|
end
|
||||||
end # Real
|
end # Real
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,10 +8,12 @@ module Fog
|
||||||
def create_key(params)
|
def create_key(params)
|
||||||
name = params[:name]
|
name = params[:name]
|
||||||
key = params[:key]
|
key = params[:key]
|
||||||
|
|
||||||
record = {
|
record = {
|
||||||
"name" => name,
|
"name" => name,
|
||||||
"key" => key,
|
"key" => key,
|
||||||
"created" => Time.now.utc
|
"created" => Time.now.utc,
|
||||||
|
"updated" => Time.now.utc
|
||||||
}
|
}
|
||||||
|
|
||||||
self.data[:keys][name] = record
|
self.data[:keys][name] = record
|
||||||
|
@ -43,7 +45,7 @@ module Fog
|
||||||
request(
|
request(
|
||||||
:method => "POST",
|
:method => "POST",
|
||||||
:path => "/my/keys",
|
:path => "/my/keys",
|
||||||
:body => { "name" => params[:name], "body" => params[:body] },
|
:body => { "name" => params[:name], "key" => params[:key] },
|
||||||
:expects => 201
|
:expects => 201
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Fog
|
||||||
def delete_key(keyname)
|
def delete_key(keyname)
|
||||||
if self.data[:keys].delete(keyname)
|
if self.data[:keys].delete(keyname)
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 200
|
response.status = 204
|
||||||
response
|
response
|
||||||
else
|
else
|
||||||
raise Excon::Errors::NotFound, "Not Found"
|
raise Excon::Errors::NotFound, "Not Found"
|
||||||
|
@ -15,11 +15,11 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
class Real
|
class Real
|
||||||
def delete_key(keyname)
|
def delete_key(name)
|
||||||
request(
|
request(
|
||||||
:method => "DELETE",
|
:method => "DELETE",
|
||||||
:path => "/my/keys/#{name}",
|
:path => "/my/keys/#{name}",
|
||||||
:expects => 200
|
:expects => 204
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end # Real
|
end # Real
|
||||||
|
|
|
@ -8,6 +8,7 @@ module Fog
|
||||||
res = Excon::Response.new
|
res = Excon::Response.new
|
||||||
res.status = 200
|
res.status = 200
|
||||||
res.body = machine
|
res.body = machine
|
||||||
|
res
|
||||||
else
|
else
|
||||||
raise Excon::Errors::NotFound, "Not Found"
|
raise Excon::Errors::NotFound, "Not Found"
|
||||||
end
|
end
|
||||||
|
@ -18,7 +19,8 @@ module Fog
|
||||||
def get_machine(uuid)
|
def get_machine(uuid)
|
||||||
request(
|
request(
|
||||||
:method => "GET",
|
:method => "GET",
|
||||||
:path => "/my/machines/#{uuid}"
|
:path => "/my/machines/#{uuid}",
|
||||||
|
:expects => 200
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'uri'
|
||||||
|
|
||||||
module Fog
|
module Fog
|
||||||
module Compute
|
module Compute
|
||||||
class Joyent
|
class Joyent
|
||||||
|
@ -17,9 +19,11 @@ module Fog
|
||||||
|
|
||||||
class Real
|
class Real
|
||||||
def get_package(name)
|
def get_package(name)
|
||||||
|
name = URI.escape(name)
|
||||||
request(
|
request(
|
||||||
:method => "GET",
|
:method => "GET",
|
||||||
:path => "/my/packages/#{name}"
|
:path => "/my/packages/#{name}",
|
||||||
|
:expects => 200
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ module Fog
|
||||||
def list_packages
|
def list_packages
|
||||||
request(
|
request(
|
||||||
:path => "/my/packages",
|
:path => "/my/packages",
|
||||||
:method => "GET"
|
:method => "GET",
|
||||||
|
:expects => 200
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end # Real
|
end # Real
|
||||||
|
|
|
@ -3,45 +3,44 @@ Shindo.tests("Fog::Compute::Joyent | key requests", ['joyent']) do
|
||||||
@key_format = {
|
@key_format = {
|
||||||
"name" => String,
|
"name" => String,
|
||||||
"key" => String,
|
"key" => String,
|
||||||
"created" => Time
|
"created" => Time,
|
||||||
|
"updated" => Time
|
||||||
}
|
}
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Fog::Compute[:joyent].create_key(
|
#
|
||||||
:name => "key1",
|
# Clear out all the test keys on the account in prep for test
|
||||||
:key => "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAlau1...")
|
#
|
||||||
|
Fog::Compute[:joyent].list_keys.body.each do |key|
|
||||||
Fog::Compute[:joyent].create_key(
|
if key["name"] =~ /^fog-test/
|
||||||
:name => "key2",
|
Fog::Compute[:joyent].delete_key(key["name"])
|
||||||
:key => "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAlau1...")
|
end
|
||||||
end
|
|
||||||
|
|
||||||
tests("#list_keys").formats([@key_format]) do
|
|
||||||
Fog::Compute[:joyent].list_keys.body
|
|
||||||
end
|
|
||||||
|
|
||||||
tests("#list_keys") do
|
|
||||||
returns(2) do
|
|
||||||
Fog::Compute[:joyent].list_keys.body.length
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@test_key_name = "fog-test-#{Time.now.utc.to_i}"
|
||||||
|
|
||||||
|
Fog::Compute[:joyent].create_key(
|
||||||
|
:name => @test_key_name,
|
||||||
|
:key => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWxSNYngOTeu0pYd+2tpfYGISuMfMUNGyAIh4yRprAbacVddRq4Nyr12vDklzaRTzgd9PgX/82JMb4RARbVTtUKXJXmaBLvg2epGM+ScanZIitzL53whJrlGx+7nT+TnRdkB1XG7uIf2EpTQBaKrT4iG0magCXh5bmOqCyWte2gV8fArMg5bZclUT1p2E7qEW0htaLOiMSyGkjBlxb6vYQCA/Pa8VWETHehIF46S942gCj0aaL81gTocfyTm5/F+AgvUAsjHzRVkB/Dlhwq7Q7sK+4iAhlKPYMflkKC8r+nF0/LL9S3lllLZvbkEWJfEqlMCAbgmjTpYlBzQEqf/eN"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("#list_keys").formats(@key_format) do
|
||||||
|
Fog::Compute[:joyent].list_keys.body.first
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#get_key").formats(@key_format) do
|
tests("#get_key").formats(@key_format) do
|
||||||
Fog::Compute[:joyent].get_key('key1').body
|
Fog::Compute[:joyent].get_key(@test_key_name).body
|
||||||
end
|
|
||||||
|
|
||||||
tests("#get_key").formats(@key_format) do
|
|
||||||
Fog::Compute[:joyent].get_key('key2').body
|
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#delete_key") do
|
tests("#delete_key") do
|
||||||
returns(200, "returns status code 200") do
|
returns(204 , "returns status code 204") do
|
||||||
Fog::Compute[:joyent].delete_key("key1").status
|
Fog::Compute[:joyent].delete_key(@test_key_name).status
|
||||||
end
|
end
|
||||||
|
|
||||||
raises(Excon::Errors::NotFound, "when a key no longer exists") do
|
raises(Excon::Errors::NotFound, "when a key no longer exists") do
|
||||||
Fog::Compute[:joyent].delete_key("key1")
|
Fog::Compute[:joyent].delete_key(@test_key_name)
|
||||||
Fog::Compute[:joyent].delete_key("key1")
|
Fog::Compute[:joyent].delete_key(@test_key_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,26 +14,30 @@ Shindo.tests("Fog::Compute[:joyent] | machine requests", ["joyent"]) do
|
||||||
"updated" => Time
|
"updated" => Time
|
||||||
}
|
}
|
||||||
|
|
||||||
@machines = Fog::Compute[:joyent].data[:machines] = {
|
if Fog.mock?
|
||||||
"15080eca-3786-4bb8-a4d0-f43e1981cd72" => {
|
@machines = Fog::Compute[:joyent].data[:machines] = {
|
||||||
"id" => "15080eca-3786-4bb8-a4d0-f43e1981cd72",
|
"15080eca-3786-4bb8-a4d0-f43e1981cd72" => {
|
||||||
"name" => "getting-started",
|
"id" => "15080eca-3786-4bb8-a4d0-f43e1981cd72",
|
||||||
"type" => "smartmachine",
|
"name" => "getting-started",
|
||||||
"state" => "running",
|
"type" => "smartmachine",
|
||||||
"dataset" => "sdc:sdc:smartos:1.3.15",
|
"state" => "running",
|
||||||
"memory" => 256,
|
"dataset" => "sdc:sdc:smartos:1.3.15",
|
||||||
"disk" => 5120,
|
"memory" => 256,
|
||||||
"ips" => ["10.88.88.50"],
|
"disk" => 5120,
|
||||||
"metadata" => {},
|
"ips" => ["10.88.88.50"],
|
||||||
"created" => Time.parse("2011-06-03T00:02:31+00:00"),
|
"metadata" => {},
|
||||||
"updated" => Time.parse("2011-06-03T00:02:31+00:00")
|
"created" => Time.parse("2011-06-03T00:02:31+00:00"),
|
||||||
|
"updated" => Time.parse("2011-06-03T00:02:31+00:00")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
end
|
||||||
|
|
||||||
@provider = Fog::Compute[:joyent]
|
@provider = Fog::Compute[:joyent]
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
# https://us-west-1.api.joyentcloud.com/docs#ListMachines
|
# https://us-west-1.api.joyentcloud.com/docs#ListMachines
|
||||||
|
#
|
||||||
tests("#list_machines") do
|
tests("#list_machines") do
|
||||||
if Fog.mock?
|
if Fog.mock?
|
||||||
returns(@machines.length, "correct number of machines") do
|
returns(@machines.length, "correct number of machines") do
|
||||||
|
@ -54,7 +58,7 @@ Shindo.tests("Fog::Compute[:joyent] | machine requests", ["joyent"]) do
|
||||||
tests("#get_machine") do
|
tests("#get_machine") do
|
||||||
formats(@machine_format) do
|
formats(@machine_format) do
|
||||||
id = @provider.list_machines.body.first["id"]
|
id = @provider.list_machines.body.first["id"]
|
||||||
@provider.get_machine(id)
|
@provider.get_machine(id).body
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
Shindo.tests("Fog::Compute[:joyent] | package requests", ["joyent"]) do
|
Shindo.tests("Fog::Compute[:joyent] | package requests", ["joyent"]) do
|
||||||
@data = Fog::Compute[:joyent].data
|
|
||||||
|
|
||||||
@package_format = {
|
@package_format = {
|
||||||
'name' => String,
|
'name' => String,
|
||||||
'vcpus' => Integer,
|
'vcpus' => Integer,
|
||||||
|
@ -11,6 +9,8 @@ Shindo.tests("Fog::Compute[:joyent] | package requests", ["joyent"]) do
|
||||||
}
|
}
|
||||||
|
|
||||||
if Fog.mock?
|
if Fog.mock?
|
||||||
|
@data = Fog::Compute[:joyent].data
|
||||||
|
|
||||||
@data[:packages] = {
|
@data[:packages] = {
|
||||||
"regular_128" => {
|
"regular_128" => {
|
||||||
"name" => "regular_128",
|
"name" => "regular_128",
|
||||||
|
@ -43,15 +43,23 @@ Shindo.tests("Fog::Compute[:joyent] | package requests", ["joyent"]) do
|
||||||
formats([@package_format]) do
|
formats([@package_format]) do
|
||||||
Fog::Compute[:joyent].list_packages.body
|
Fog::Compute[:joyent].list_packages.body
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
actual = @data[:packages].values.length
|
if Fog.mock?
|
||||||
returns(actual, "has correct number of packages") do
|
tests("#list_packages") do
|
||||||
Fog::Compute[:joyent].list_packages.body.length
|
actual = @data[:packages].values.length
|
||||||
|
returns(actual, "has correct number of packages") do
|
||||||
|
Fog::Compute[:joyent].list_packages.body.length
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#get_package") do
|
tests("#get_package") do
|
||||||
pkgid = @data[:packages].keys.first
|
pkgid = if Fog.mock?
|
||||||
|
@data[:packages].keys.first
|
||||||
|
else
|
||||||
|
Fog::Compute[:joyent].list_packages.body.first["name"]
|
||||||
|
end
|
||||||
|
|
||||||
formats(@package_format) do
|
formats(@package_format) do
|
||||||
Fog::Compute[:joyent].get_package(pkgid).body
|
Fog::Compute[:joyent].get_package(pkgid).body
|
||||||
|
|
Loading…
Reference in a new issue