1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

more tests for instrumentations

This commit is contained in:
Kevin Olbrich 2014-01-03 15:12:25 -05:00
parent 619a66216c
commit 62692f1dd8
5 changed files with 89 additions and 9 deletions

View file

@ -20,20 +20,46 @@ module Fog
attribute :value_scope, aliases: 'value-scope'
attribute :uris, :type => :array
def initialize(attributes={})
self.decomposition = []
self.value_arity = 'scalar'
self.retention_time = 600
self.idle_max = 3600
self.persist_data = false
self.value_scope = 'interval'
super
end
def crtime=(new_crtime)
attributes[:crtime] = Time.at(new_crtime.to_i / 1000)
end
def decomposition=(value)
attributes[:decomposition] = value
self.value_dimension = self.decomposition.size + 1
self.decomposition
end
def save
requires :joyent_module, :stat
munged_attributes = attributes.dup
munged_attributes[:module] = munged_attributes.delete(:joyent_module)
munged_attributes[:'value-dimension'] = munged_attributes.delete(:value_dimension) || (self.decomposition.size + 1)
munged_attributes[:'value-arity'] = munged_attributes.delete(:value_arity) || 'scalar'
munged_attributes[:'retention-time'] = munged_attributes.delete(:retention_time) || 600
munged_attributes[:'idle-max'] = munged_attributes.delete(:idle_max) || 3600
munged_attributes[:'persist-data'] = munged_attributes.delete(:persist_data) || false
munged_attributes[:'value-scope'] = munged_attributes.delete(:value_scope) || 'interval'
#munged_attributes = attributes.dup
#munged_attributes[:module] = munged_attributes.delete(:joyent_module)
#munged_attributes[:'value-dimension'] = munged_attributes.delete(:value_dimension) || (self.decomposition.size + 1)
#munged_attributes[:'value-arity'] = munged_attributes.delete(:value_arity) || 'scalar'
#munged_attributes[:'retention-time'] = munged_attributes.delete(:retention_time) || 600
#munged_attributes[:'idle-max'] = munged_attributes.delete(:idle_max) || 3600
#munged_attributes[:'persist-data'] = munged_attributes.delete(:persist_data) || false
#munged_attributes[:'value-scope'] = munged_attributes.delete(:value_scope) || 'interval'
munged_attributes = remap_attributes(self.attributes.dup, {
:joyent_module => 'module',
:value_dimension => 'value-dimension',
:value_arity => 'value-arity',
:retention_time => 'retention-time',
:idle_max => 'idle-max',
:persist_data => 'persist-data',
:value_scope => 'value-scope'
})
data = service.create_instrumentation(munged_attributes)
merge_attributes(data.body)
true

View file

@ -15,7 +15,7 @@ module Fog
class Mock
def create_instrumentation(values = {})
response = Excon::Response.new
response.status = 200
response.status = 201
response.body = self.data[:instrumentation]
response
end

View file

@ -10,6 +10,16 @@ module Fog
)
end
end
class Mock
def get_instrumentation(id)
raise Fog::Compute::Joyent::Errors::NotFound.new('not found') unless id == self.data[:instrumentation]['id']
response = Excon::Response.new
response.status = 200
response.body = self.data[:instrumentation]
response
end
end
end
end
end

View file

@ -0,0 +1,44 @@
Shindo.tests("Fog::Joyent::Analytics | instrumentations", %w{joyent}) do
@analytics = Fog::Joyent[:analytics]
@instrumentation_schema = {
'id' => String,
'module' => String,
'stat' => String,
'predicate' => Hash,
'decomposition' => [String],
'value-dimension' => Integer,
'value-arity' => String,
'retention-time' => Integer,
'granularity' => Integer,
'idle-max' => Integer,
'transformations' => [String],
'persist-data' => Fog::Boolean,
'crtime' => Integer,
'value-scope' => String,
'uris' => [
{
'uri' => String,
'name' => String
}
]
}
tests('#create_instrumentation').data_matches_schema(@instrumentation_schema) do
@analytics.create_instrumentation.body
end
tests('#list_instrumentations') do
data_matches_schema(@instrumentation_schema) do
@analytics.list_instrumentations.body.first
end
returns(Array) { @analytics.list_instrumentations.body.class }
end
tests('#delete_instrumentation') do
returns(204) { @analytics.delete_instrumentation(Fog::Joyent::Analytics::Mock.data[:instrumentation]['id']).status }
end
end