test/yao/resources/test_hypervisor.rb in yao-0.7.0 vs test/yao/resources/test_hypervisor.rb in yao-0.8.0
- old
+ new
@@ -1,21 +1,18 @@
-class TestHypervisor < Test::Unit::TestCase
+class TestHypervisor < TestYaoResource
+
def test_hypervisor
params = {
"status" => "enabled"
}
host = Yao::Hypervisor.new(params)
assert_equal(host.enabled?, true)
end
- def setup
- Yao.default_client.pool["compute"] = Yao::Client.gen_client("https://example.com:12345")
- end
-
- def test_list_detail
- stub_request(:get, "https://example.com:12345/os-hypervisors/detail")
+ def test_list
+ stub = stub_request(:get, "https://example.com:12345/os-hypervisors/detail")
.with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"})
.to_return(
status: 200,
body: <<-JSON,
{
@@ -25,16 +22,22 @@
}
JSON
headers: {'Content-Type' => 'application/json'}
)
- h = Yao::Resources::Hypervisor.list_detail
+ h = Yao::Resources::Hypervisor.list
assert_equal(h.first.id, "dummy")
+
+ assert_requested(stub)
end
+ def test_list_detail
+ assert_equal(Yao::Hypervisor.method(:list_detail), Yao::Hypervisor.method(:list))
+ end
+
def test_statistics
- stub_request(:get, "https://example.com:12345/os-hypervisors/statistics")
+ stub = stub_request(:get, "https://example.com:12345/os-hypervisors/statistics")
.with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"})
.to_return(
status: 200,
body: <<-JSON,
{
@@ -57,14 +60,16 @@
headers: {'Content-Type' => 'application/json'}
)
s = Yao::Resources::Hypervisor.statistics
assert_equal(s.count, 1)
+
+ assert_requested(stub)
end
def test_uptime
- stub_request(:get, "https://example.com:12345/os-hypervisors/1/uptime")
+ stub = stub_request(:get, "https://example.com:12345/os-hypervisors/1/uptime")
.with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"})
.to_return(
status: 200,
body: <<-JSON,
{
@@ -80,7 +85,9 @@
headers: {'Content-Type' => 'application/json'}
)
u = Yao::Resources::Hypervisor.uptime(1)
assert_equal(u.uptime, " 08:32:11 up 93 days, 18:25, 12 users, load average: 0.20, 0.12, 0.14")
+
+ assert_requested(stub)
end
end