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

- old
+ new

@@ -1,11 +1,7 @@ -class TestSubnet < Test::Unit::TestCase +class TestSubnet < TestYaoResource - def setup - Yao.default_client.pool["network"] = Yao::Client.gen_client("https://example.com:12345") - end - def test_subnet # https://docs.openstack.org/api-ref/network/v2/#subnets params = { "name" => "private-subnet", "enable_dhcp" => true, @@ -54,11 +50,11 @@ # #allocation_pools assert_equal(subnet.allocation_pools, ["10.0.0.2".."10.0.0.254"]) 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": { @@ -74,7 +70,30 @@ } subnet = Yao::Subnet.new(params) assert_instance_of(Yao::Resources::Network, subnet.network) assert_equal(subnet.network.id, "00000000-0000-0000-0000-000000000000") + + assert_requested(stub) + 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'} + ) + + subnet = Yao::Subnet.new('tenant_id' => '0123456789abcdef0123456789abcdef') + assert_instance_of(Yao::Tenant, subnet.tenant) + assert_equal(subnet.tenant.id, '0123456789abcdef0123456789abcdef') + + assert_requested(stub) end end