test/yao/resources/test_server.rb in yao-0.7.0 vs test/yao/resources/test_server.rb in yao-0.8.0
- old
+ new
@@ -1,11 +1,7 @@
-class TestServer < Test::Unit::TestCase
+class TestServer < TestYaoResource
- def setup
- Yao.default_client.pool["compute"] = Yao::Client.gen_client("https://example.com:12345")
- end
-
def test_server
# https://docs.openstack.org/api-ref/compute/?expanded=list-servers-detail,list-servers-detailed-detail#list-servers
params = {
"OS-DCF:diskConfig" => "AUTO",
@@ -140,12 +136,12 @@
assert_equal(server.ext_sts_power_state, 1)
assert_equal(server.ext_sts_task_state, nil)
assert_equal(server.ext_sts_vm_state, "active")
end
- def test_list_detail
- stub_request(:get, "https://example.com:12345/servers/detail")
+ def test_list
+ stub = stub_request(:get, "https://example.com:12345/servers/detail")
.to_return(
status: 200,
body: <<-JSON,
{
"servers": [{
@@ -154,11 +150,41 @@
}
JSON
headers: {'Content-Type' => 'application/json'}
)
- servers = Yao::Server.list_detail
+ assert(Yao::Server.resources_detail_available)
+
+ servers = Yao::Server.list
assert_instance_of(Array, servers)
assert_instance_of(Yao::Server, servers.first)
assert_equal(servers.first.id, 'dummy')
+
+ assert_requested(stub)
+ end
+
+ def test_list_detail
+ assert_equal(Yao::Server.method(:list_detail), Yao::Server.method(:list))
+ end
+
+ def test_tenant
+
+ stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
+ .to_return(
+ status: 200,
+ body: <<-JSON,
+ {
+ "tenant": {
+ "id": "0123456789abcdef0123456789abcdef"
+ }
+ }
+ JSON
+ headers: {'Content-Type' => 'application/json'}
+ )
+
+ server = Yao::Server.new('tenant_id' => '0123456789abcdef0123456789abcdef')
+ assert_instance_of(Yao::Tenant, server.tenant)
+ assert_equal(server.tenant.id, '0123456789abcdef0123456789abcdef')
+
+ assert_requested(stub)
end
end