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

- old
+ new

@@ -1,13 +1,7 @@ -class TestMeter < Test::Unit::TestCase +class TestMeter < TestYaoResource - def setup - Yao.default_client.pool["metering"] = Yao::Client.gen_client("https://example.com:12345") - # notice: admin_pool を指定するあたりでハマったので注意 - Yao.default_client.admin_pool["identity"] = Yao::Client.gen_client("https://example.com:12345") - end - def test_meter # https://docs.openstack.org/ceilometer/pike/webapi/v2.html params = { "meter_id" => "YmQ5NDMxYzEtOGQ2OS00YWQzLTgwM2EtOGQ0YTZiODlmZDM2K2luc3RhbmNl", "name" => "instance", @@ -32,13 +26,12 @@ assert_equal(meter.unit, "instance") assert_equal(meter.user_id, "efd87807-12d2-4b38-9c70-5f5c2ac427ff") end def test_resource - # https://docs.openstack.org/ceilometer/pike/webapi/v2.html - stub_request(:get, "https://example.com:12345/v2/resources/00000000-0000-0000-0000-000000000000") + stub = stub_request(:get, "https://example.com:12345/v2/resources/00000000-0000-0000-0000-000000000000") .to_return( status: 200, body: <<-JSON, { "resource_id": "00000000-0000-0000-0000-000000000000" @@ -50,17 +43,19 @@ params = { "resource_id" => "00000000-0000-0000-0000-000000000000", } meter = Yao::Meter.new(params) - resource = meter.resource - assert_instance_of(Yao::Resource, resource) - assert_equal(resource.resource_id, "00000000-0000-0000-0000-000000000000") + assert_instance_of(Yao::Resource, meter.resource) + assert_equal(meter.resource.resource_id, "00000000-0000-0000-0000-000000000000") + assert_equal(meter.resource.id, "00000000-0000-0000-0000-000000000000") + + assert_requested(stub) end def test_tenant - stub_request(:get, "https://example.com:12345/tenants/00000000-0000-0000-0000-000000000000") + stub = stub_request(:get, "https://example.com:12345/tenants/00000000-0000-0000-0000-000000000000") .to_return( status: 200, body: <<-JSON, { "tenant": { @@ -76,14 +71,16 @@ } meter = Yao::Meter.new(params) assert_instance_of(Yao::Tenant, meter.tenant) assert_equal(meter.tenant.id, "00000000-0000-0000-0000-000000000000") + + assert_requested(stub) end def test_user - stub_request(:get, "https://example.com:12345/users/00000000-0000-0000-0000-000000000000") + stub = stub_request(:get, "https://example.com:12345/users/00000000-0000-0000-0000-000000000000") .to_return( status: 200, body: <<-JSON, { "user": { @@ -99,7 +96,9 @@ } meter = Yao::Meter.new(params) assert_instance_of(Yao::User, meter.user) assert_equal(meter.user.id, "00000000-0000-0000-0000-000000000000") + + assert_requested(stub) end end