From 716af47b8a22ee9ee7d25b3eb29490ea3a407057 Mon Sep 17 00:00:00 2001 From: Kevin Olbrich Date: Sat, 4 Jan 2014 03:18:12 +0000 Subject: [PATCH] add tests for metrics, types and a few other things --- lib/fog/joyent/analytics.rb | 41 ++++++++++++++----- tests/joyent/models/analytics/field_tests.rb | 2 +- .../models/analytics/instrumentation_tests.rb | 2 +- .../analytics/instrumentations_tests.rb | 2 +- .../models/analytics/joyent_module_tests.rb | 2 +- tests/joyent/models/analytics/metric_tests.rb | 10 +++++ .../joyent/models/analytics/metrics_tests.rb | 20 +++++++++ .../models/analytics/transformation_tests.rb | 10 +++++ .../models/analytics/transformations_tests.rb | 13 ++++++ tests/joyent/models/analytics/type_tests.rb | 10 +++++ tests/joyent/models/analytics/types_tests.rb | 13 ++++++ 11 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 tests/joyent/models/analytics/metric_tests.rb create mode 100644 tests/joyent/models/analytics/metrics_tests.rb create mode 100644 tests/joyent/models/analytics/transformation_tests.rb create mode 100644 tests/joyent/models/analytics/transformations_tests.rb create mode 100644 tests/joyent/models/analytics/type_tests.rb create mode 100644 tests/joyent/models/analytics/types_tests.rb diff --git a/lib/fog/joyent/analytics.rb b/lib/fog/joyent/analytics.rb index 072d2956d..fbd52f9ea 100644 --- a/lib/fog/joyent/analytics.rb +++ b/lib/fog/joyent/analytics.rb @@ -21,7 +21,7 @@ module Fog request :list_instrumentations request :get_instrumentation request :create_instrumentation - request :delete_instrumentation + request :delete_instrumentation request :get_instrumentation_value model_path 'fog/joyent/models/analytics' @@ -73,16 +73,16 @@ module Fog "name" => "value_raw" }] } when :values { - 'value' => { 'zoneid' => 0 }, - 'transformations' => {}, - 'start_time' => Time.now.utc - 600, - 'duration' => 30, - 'end_time' => Time.now.utc - 570, - 'nsources' => 1, - 'minreporting' => 1, - 'requested_start_time' => Time.now.utc - 600, - 'requested_duration' => 30, - 'requested_end_time' => Time.now.utc - 570 + 'value' => { 'zoneid' => 0 }, + 'transformations' => {}, + 'start_time' => Time.now.utc - 600, + 'duration' => 30, + 'end_time' => Time.now.utc - 570, + 'nsources' => 1, + 'minreporting' => 1, + 'requested_start_time' => Time.now.utc - 600, + 'requested_duration' => 30, + 'requested_end_time' => Time.now.utc - 570 } when :describe_analytics { @@ -100,6 +100,25 @@ module Fog 'cpu' => { 'label' => 'CPU' } + }, + 'transformations' => { + 'geolocate' => { + 'label' => 'geolocate IP addresses', + 'fields' => ['raddr'] } + }, + 'metrics' => [{ + "module" => "cpu", + "stat" => "thread_executions", + "label" => "thread executions", + "interval" => "interval", + "fields" => ["hostname", "zonename", "runtime"], + "unit" => "operations" + }], + 'types' => { + 'string' => { + 'arity' => "discrete", + 'unit' => "" + } } } else diff --git a/tests/joyent/models/analytics/field_tests.rb b/tests/joyent/models/analytics/field_tests.rb index f16feb609..384f4e831 100644 --- a/tests/joyent/models/analytics/field_tests.rb +++ b/tests/joyent/models/analytics/field_tests.rb @@ -1,4 +1,4 @@ -Shindo.tests("Fog::Joyent[:analytics] | field", %w{joyent analytics}) do +Shindo.tests("Fog::Joyent[:analytics] | field", %w{joyent}) do @analytics = Fog::Joyent[:analytics] @field = @analytics.fields.first diff --git a/tests/joyent/models/analytics/instrumentation_tests.rb b/tests/joyent/models/analytics/instrumentation_tests.rb index 24e4241fa..6d25b7db2 100644 --- a/tests/joyent/models/analytics/instrumentation_tests.rb +++ b/tests/joyent/models/analytics/instrumentation_tests.rb @@ -1,4 +1,4 @@ -Shindo.tests("Fog::Joyent[:analytics] | instrumentation", %w{joyent analytics instrumentation }) do +Shindo.tests("Fog::Joyent[:analytics] | instrumentation", %w{joyent }) do model_tests(Fog::Joyent[:analytics].instrumentations, {:joyent_module => 'cpu', :stat => 'usage'}, true) @analytics = Fog::Joyent[:analytics] diff --git a/tests/joyent/models/analytics/instrumentations_tests.rb b/tests/joyent/models/analytics/instrumentations_tests.rb index 430a31490..f8e1c269b 100644 --- a/tests/joyent/models/analytics/instrumentations_tests.rb +++ b/tests/joyent/models/analytics/instrumentations_tests.rb @@ -1,3 +1,3 @@ -Shindo.tests("Fog::Joyent[:analytics] | instrumentations", %w{joyent models instrumentation }) do +Shindo.tests("Fog::Joyent[:analytics] | instrumentations", %w{joyent}) do collection_tests(Fog::Joyent[:analytics].instrumentations, {:joyent_module => 'cpu', :stat => 'usage'}, true) end diff --git a/tests/joyent/models/analytics/joyent_module_tests.rb b/tests/joyent/models/analytics/joyent_module_tests.rb index 8fbe8c98a..4b6550017 100644 --- a/tests/joyent/models/analytics/joyent_module_tests.rb +++ b/tests/joyent/models/analytics/joyent_module_tests.rb @@ -1,4 +1,4 @@ -Shindo.tests("Fog::Joyent[:analytics] | joyent_module", %w{joyent analytics}) do +Shindo.tests("Fog::Joyent[:analytics] | joyent_module", %w{joyent}) do @analytics = Fog::Joyent[:analytics] @joyent_module = @analytics.joyent_modules.first diff --git a/tests/joyent/models/analytics/metric_tests.rb b/tests/joyent/models/analytics/metric_tests.rb new file mode 100644 index 000000000..ab93f563c --- /dev/null +++ b/tests/joyent/models/analytics/metric_tests.rb @@ -0,0 +1,10 @@ +Shindo.tests("Fog::Joyent[:analytics] | metric", %w{joyent}) do + @analytics = Fog::Joyent[:analytics] + @metric = @analytics.metrics.first + + tests('read only') do + returns(false, 'should not save') { @metric.respond_to?(:save)} + returns(false, 'should not allow creating a new one') { @metric.respond_to?(:create)} + returns(false, 'should not allow destroying') { @metric.respond_to?(:destroy)} + end +end diff --git a/tests/joyent/models/analytics/metrics_tests.rb b/tests/joyent/models/analytics/metrics_tests.rb new file mode 100644 index 000000000..bc7bb603d --- /dev/null +++ b/tests/joyent/models/analytics/metrics_tests.rb @@ -0,0 +1,20 @@ +Shindo.tests("Fog::Joyent[:analytics] | metrics", %w{joyent}) do + @analytics = Fog::Joyent[:analytics] + @metrics = @analytics.metrics + + tests('#all').succeeds do + @metrics.all + end + + tests('#new').succeeds do + @metrics.new({ + "module" => "cpu", + "stat" => "thread_executions", + "label" => "thread executions", + "interval" => "interval", + "fields" => ["hostname", "zonename", "runtime"], + "unit" => "operations" + }) + end + +end diff --git a/tests/joyent/models/analytics/transformation_tests.rb b/tests/joyent/models/analytics/transformation_tests.rb new file mode 100644 index 000000000..eeecfd08d --- /dev/null +++ b/tests/joyent/models/analytics/transformation_tests.rb @@ -0,0 +1,10 @@ +Shindo.tests("Fog::Joyent[:analytics] | transformation", %w{joyent}) do + @analytics = Fog::Joyent[:analytics] + @transformation = @analytics.transformations.first + + tests('read only') do + returns(false, 'should not save') { @transformation.respond_to?(:save)} + returns(false, 'should not allow creating a new one') { @transformation.respond_to?(:create)} + returns(false, 'should not allow destroying') { @transformation.respond_to?(:destroy)} + end +end diff --git a/tests/joyent/models/analytics/transformations_tests.rb b/tests/joyent/models/analytics/transformations_tests.rb new file mode 100644 index 000000000..8953e6530 --- /dev/null +++ b/tests/joyent/models/analytics/transformations_tests.rb @@ -0,0 +1,13 @@ +Shindo.tests("Fog::Joyent[:analytics] | transformations", %w{joyent}) do + @analytics = Fog::Joyent[:analytics] + @transformations = @analytics.transformations + + tests('#all').succeeds do + @transformations.all + end + + tests('#new').succeeds do + @transformations.new(['geolocate', { 'label' => 'geolocate IP addresses', "fields" => ["raddr"] }]) + end + +end diff --git a/tests/joyent/models/analytics/type_tests.rb b/tests/joyent/models/analytics/type_tests.rb new file mode 100644 index 000000000..5c1dd4271 --- /dev/null +++ b/tests/joyent/models/analytics/type_tests.rb @@ -0,0 +1,10 @@ +Shindo.tests("Fog::Joyent[:analytics] | type", %w{joyent}) do + @analytics = Fog::Joyent[:analytics] + @type = @analytics.types.first + + tests('read only') do + returns(false, 'should not save') { @type.respond_to?(:save)} + returns(false, 'should not allow creating a new one') { @type.respond_to?(:create)} + returns(false, 'should not allow destroying') { @type.respond_to?(:destroy)} + end +end diff --git a/tests/joyent/models/analytics/types_tests.rb b/tests/joyent/models/analytics/types_tests.rb new file mode 100644 index 000000000..53e2240fa --- /dev/null +++ b/tests/joyent/models/analytics/types_tests.rb @@ -0,0 +1,13 @@ +Shindo.tests("Fog::Joyent[:analytics] | types", %w{joyent}) do + @analytics = Fog::Joyent[:analytics] + @types = @analytics.types + + tests('#all').succeeds do + @types.all + end + + tests('#new').succeeds do + @types.new(['string', {'arity' => 'discrete', 'unit' => ''}]) + end + +end