test/yao/resources/test_port.rb in yao-0.7.0 vs test/yao/resources/test_port.rb in yao-0.8.0

- old
+ new

@@ -1,11 +1,7 @@ -class TestPort < Test::Unit::TestCase +class TestPort < TestYaoResource - def setup - Yao.default_client.pool["network"] = Yao::Client.gen_client("https://example.com:12345") - end - def test_port # https://docs.openstack.org/api-ref/network/v2/?expanded=list-floating-ips-detail,show-port-details-detail#ports params = { "admin_state_up" => true, @@ -79,10 +75,32 @@ # primary_ip assert_equal(port.primary_ip, "10.0.0.1") 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'} + ) + + port = Yao::Port.new('tenant_id' => '0123456789abcdef0123456789abcdef') + assert_instance_of(Yao::Tenant, port.tenant) + assert_equal(port.tenant.id, '0123456789abcdef0123456789abcdef') + + assert_requested(stub) + end + def test_primary_ip params = { "fixed_ips" => [ { @@ -96,11 +114,11 @@ assert_equal(port.primary_ip, "10.0.0.1") end def test_primary_subnet - stub_request(:get, "https://example.com:12345/subnets/00000000-0000-0000-0000-000000000000") + stub = stub_request(:get, "https://example.com:12345/subnets/00000000-0000-0000-0000-000000000000") .to_return( status: 200, body: <<-JSON, { "subnet": { @@ -121,15 +139,17 @@ } port = Yao::Port.new(params) assert{ port.primary_subnet.instance_of?(Yao::Subnet) } assert_equal(port.primary_subnet.id, "00000000-0000-0000-0000-000000000000") + + assert_requested(stub) end def test_network - stub_request(:get, "https://example.com:12345/networks/00000000-0000-0000-0000-000000000000") + stub = stub_request(:get, "https://example.com:12345/networks/00000000-0000-0000-0000-000000000000") .to_return( status: 200, body: <<-JSON, { "network": { @@ -145,7 +165,9 @@ } port = Yao::Port.new(params) assert_instance_of(Yao::Network, port.network) assert_equal(port.network.id, "00000000-0000-0000-0000-000000000000") + + assert_requested(stub) end end