Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shindo to Minitest: orchestration, metering, volume #134

Merged
merged 1 commit into from Jun 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/requests/metering/event_tests.rb
@@ -0,0 +1,23 @@
require "test_helper"

describe "Fog::Metering[:openstack] | event requests" do
before do
@metering = Fog::Metering[:openstack]
@event_format = {
'message_id' => String,
'event_type' => String
}
end

describe "success" do
it "#list_events" do
@metering.list_events.body.
must_match_schema([@event_format])
end

it "#get_event" do
@metering.get_event('test').body.
must_match_schema(@event_format)
end
end
end
58 changes: 58 additions & 0 deletions test/requests/metering/meter_tests.rb
@@ -0,0 +1,58 @@
require "test_helper"

describe "Fog::Metering[:openstack] | meter requests" do
before do
@metering = Fog::Metering[:openstack]

@sample_format = {
'counter_name' => String,
'user_id' => String,
'resource_id' => String,
'timestamp' => String,
'resource_metadata' => Hash,
'source' => String,
'counter_unit' => String,
'counter_volume' => Float,
'project_id' => String,
'message_id' => String,
'counter_type' => String
}

@meter_format = {
'user_id' => String,
'name' => String,
'resource_id' => String,
'project_id' => String,
'type' => String,
'unit' => String
}

@statistics_format = {
'count' => Integer,
'duration_start' => String,
'min' => Float,
'max' => Float,
'duration_end' => String,
'period' => Integer,
'period_end' => String,
'duration' => Float,
'period_start' => String,
'avg' => Float,
'sum' => Float
}
end

describe "success" do
it "#list_meters" do
@metering.list_meters.body.must_match_schema([@meter_format])
end

it "#get_samples" do
@metering.get_samples('test').body.must_match_schema([@sample_format])
end

it "#get_statistics" do
@metering.get_statistics('test').body.must_match_schema([@statistics_format])
end
end
end
24 changes: 24 additions & 0 deletions test/requests/metering/resource_tests.rb
@@ -0,0 +1,24 @@
require "test_helper"

describe "Fog::Metering[:openstack] | resource requests" do
before do
@metering = Fog::Metering[:openstack]

@resource_format = {
'resource_id' => String,
'project_id' => String,
'user_id' => String,
'metadata' => Hash
}
end

describe "success" do
it "#list_resource" do
@metering.list_resources.body.must_match_schema([@resource_format])
end

it "#get_resource" do
@metering.get_resource('test').body.must_match_schema(@resource_format)
end
end
end
70 changes: 70 additions & 0 deletions test/requests/orchestration/stack_tests.rb
@@ -0,0 +1,70 @@
require "test_helper"

describe "Fog::Orchestration[:openstack] | stack requests" do
before do
@orchestration = Fog::Orchestration[:openstack]

@stack_format = {
'links' => Array,
'id' => String,
'stack_name' => String,
'description' => Fog::Nullable::String,
'stack_status' => String,
'stack_status_reason' => String,
'creation_time' => Time,
'updated_time' => Time
}

@stack_detailed_format = {
"parent" => Fog::Nullable::String,
"disable_rollback" => Fog::Boolean,
"description" => String,
"links" => Array,
"stack_status_reason" => String,
"stack_name" => String,
"stack_user_project_id" => String,
"stack_owner" => String,
"creation_time" => Fog::Nullable::String,
"capabilities" => Array,
"notification_topics" => Array,
"updated_time" => Fog::Nullable::String,
"timeout_mins" => Fog::Nullable::String,
"stack_status" => String,
"parameters" => Hash,
"id" => String,
"outputs" => Array,
"template_description" => String
}

@create_format = {
'id' => String,
'links' => Array,
}
end

describe "success" do
it "#create_stack" do
@stack = @orchestration.create_stack("teststack").body.must_match_schema(@create_format)
end

it "#list_stack_data" do
@orchestration.list_stack_data.body.must_match_schema('stacks' => [@stack_format])
end

it "#list_stack_data_Detailed" do
@orchestration.list_stack_data_detailed.body.must_match_schema('stacks' => [@stack_detailed_format])
end

it "#update_stack" do
@orchestration.update_stack("teststack").body.must_match_schema({})
end

it "#patch_stack" do
@orchestration.patch_stack(@stack).body.must_match_schema({})
end

it "#delete_stack" do
@orchestration.delete_stack("teststack", "id").body.must_match_schema({})
end
end
end
17 changes: 17 additions & 0 deletions test/requests/volume/availability_zone_tests.rb
@@ -0,0 +1,17 @@
require 'test_helper'

describe "Fog::Volume[:openstack] | availability zone requests" do
before do
@flavor_format = {
'zoneName' => String,
'zoneState' => Hash
}
end

describe "success" do
it "#list_zones" do
Fog::Volume[:openstack].list_zones.body.
must_match_schema('availabilityZoneInfo' => [@flavor_format])
end
end
end
36 changes: 36 additions & 0 deletions test/requests/volume/quota_tests.rb
@@ -0,0 +1,36 @@
require 'test_helper'

describe "Fog::Volume[:openstack] | quota requests" do
before do
@volume = Fog::Volume[:openstack]
@tenant_id = Fog::Compute[:openstack].list_tenants.body['tenants'].first['id']
@quota_set_format = {
'volumes' => Fog::Nullable::Integer,
'gigabytes' => Fog::Nullable::Integer,
'snapshots' => Fog::Nullable::Integer,
'id' => String
}
@quota = @volume.get_quota(@tenant_id).body['quota_set']
end

describe "success" do
it "#get_quota_defaults" do
@volume.get_quota_defaults(@tenant_id).body.
must_match_schema('quota_set' => @quota_set_format)
end

it "#get_quota" do
@quota.must_match_schema(@quota_set_format)
end

it "updates quota" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has two asserts - line 33 and line 37. When first one fails the second one will never be run (and it can fail too). This introduces delay in developers workflow - solve the first one failing just to discover the second one failing too.

Another issue with more than one assert per it is connected to what I wrote at #128 (comment) - it is the structure of describe/it and naming of them. Should one of these asserts fail I will see
Fog::Volume[:openstack] | quota requests::success#test_0003_updates quota [/home/pblaho/workspace/fog/fog-openstack/test/requests/volume/quota_tests.rb:37]: and with information about expected and actual result. That line suggests where the failing assert is located (line 37 here) but it tells me that it is Fog::Volume[:openstack] | quota requests::success#test_0003_updates quota test failing.

With proper naming and structure of describe/it blocks and only one assert per test you can immediately see all failed tests and exactly what test failed and developer who knows the codebase can just know what the issue could be.

If there is a need to test two subsequent quota updates I would just create two it blocks, make them share the same describe and before block to setup tests, and the first would just call #update_quota once and assert result and the second would call it twice and assert result.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanation. I agree the break down of describe/it can/must be improved for better readability. Again this is legacy code and the initial target is to port it to Minitest.
Regarding the specific "updates quota" I effectively don't see the point of asserting #update_quota twice. Therefore I remove the second one.

@new_values = @quota.merge(
'volumes' => @quota['volumes'] / 2,
'snapshots' => @quota['snapshots'] / 2
)

@volume.update_quota(@tenant_id, @new_values.clone)
@volume.get_quota(@tenant_id).body['quota_set'].must_match_schema @new_values
end
end
end
42 changes: 42 additions & 0 deletions test/requests/volume/volume_type_tests.rb
@@ -0,0 +1,42 @@
require 'test_helper'

describe "Fog::Volume[:openstack] | volume_type requests" do
before do
@volume = Fog::Volume[:openstack]

@volume_type_format = {
'name' => String,
'extra_specs' => Hash,
'id' => String
}

@volume_type = @volume.create_volume_type(:name => 'test_volume_type').body['volume_type']
end

describe "success" do
it "#create_volume_type" do
@volume_type.must_match_schema(@volume_type_format)
end

it "#update_volume_type" do
@volume.update_volume_type(
@volume_type['id'],
:name => 'test_volume_type_1'
).body['volume_type'].must_match_schema(@volume_type_format)
end

it "#get_volume_type" do
@volume.get_volume_type_details(@volume_type['id']).body['volume_type'].
must_match_schema(@volume_type_format)
end

it "#list_volume_type" do
@volume.list_volume_types.body['volume_types'].
must_match_schema([@volume_type_format])
end

it 'delete the volute type' do
@volume.delete_volume_type(@volume_type['id'])
end
end
end
17 changes: 0 additions & 17 deletions tests/openstack/requests/metering/event_tests.rb

This file was deleted.

52 changes: 0 additions & 52 deletions tests/openstack/requests/metering/meter_tests.rb

This file was deleted.

19 changes: 0 additions & 19 deletions tests/openstack/requests/metering/resource_tests.rb

This file was deleted.