hoodoo 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/hoodoo +5 -0
- data/lib/hoodoo.rb +27 -0
- data/lib/hoodoo/active.rb +32 -0
- data/lib/hoodoo/active/active_model/uuid_validator.rb +45 -0
- data/lib/hoodoo/active/active_record/base.rb +81 -0
- data/lib/hoodoo/active/active_record/creator.rb +134 -0
- data/lib/hoodoo/active/active_record/dated.rb +343 -0
- data/lib/hoodoo/active/active_record/error_mapping.rb +351 -0
- data/lib/hoodoo/active/active_record/finder.rb +606 -0
- data/lib/hoodoo/active/active_record/search_helper.rb +189 -0
- data/lib/hoodoo/active/active_record/secure.rb +431 -0
- data/lib/hoodoo/active/active_record/support.rb +106 -0
- data/lib/hoodoo/active/active_record/translated.rb +87 -0
- data/lib/hoodoo/active/active_record/uuid.rb +80 -0
- data/lib/hoodoo/active/active_record/writer.rb +321 -0
- data/lib/hoodoo/client.rb +23 -0
- data/lib/hoodoo/client/augmented_array.rb +29 -0
- data/lib/hoodoo/client/augmented_base.rb +168 -0
- data/lib/hoodoo/client/augmented_hash.rb +23 -0
- data/lib/hoodoo/client/client.rb +354 -0
- data/lib/hoodoo/client/endpoint/endpoint.rb +427 -0
- data/lib/hoodoo/client/endpoint/endpoints/amqp.rb +180 -0
- data/lib/hoodoo/client/endpoint/endpoints/auto_session.rb +194 -0
- data/lib/hoodoo/client/endpoint/endpoints/http.rb +203 -0
- data/lib/hoodoo/client/endpoint/endpoints/http_based.rb +367 -0
- data/lib/hoodoo/client/endpoint/endpoints/not_found.rb +59 -0
- data/lib/hoodoo/client/headers.rb +269 -0
- data/lib/hoodoo/communicators.rb +23 -0
- data/lib/hoodoo/communicators/fast.rb +44 -0
- data/lib/hoodoo/communicators/pool.rb +601 -0
- data/lib/hoodoo/communicators/slow.rb +84 -0
- data/lib/hoodoo/data.rb +51 -0
- data/lib/hoodoo/data/resources/caller.rb +39 -0
- data/lib/hoodoo/data/resources/errors.rb +28 -0
- data/lib/hoodoo/data/resources/log.rb +31 -0
- data/lib/hoodoo/data/resources/session.rb +26 -0
- data/lib/hoodoo/data/types/error_primitive.rb +27 -0
- data/lib/hoodoo/data/types/permissions.rb +40 -0
- data/lib/hoodoo/data/types/permissions_defaults.rb +32 -0
- data/lib/hoodoo/data/types/permissions_full.rb +28 -0
- data/lib/hoodoo/data/types/permissions_resources.rb +31 -0
- data/lib/hoodoo/discovery.rb +20 -0
- data/lib/hoodoo/errors.rb +19 -0
- data/lib/hoodoo/errors/error_descriptions.rb +229 -0
- data/lib/hoodoo/errors/errors.rb +322 -0
- data/lib/hoodoo/generator.rb +139 -0
- data/lib/hoodoo/logger.rb +23 -0
- data/lib/hoodoo/logger/fast_writer.rb +27 -0
- data/lib/hoodoo/logger/flattener_mixin.rb +36 -0
- data/lib/hoodoo/logger/logger.rb +387 -0
- data/lib/hoodoo/logger/slow_writer.rb +49 -0
- data/lib/hoodoo/logger/writer_mixin.rb +52 -0
- data/lib/hoodoo/logger/writers/file_writer.rb +45 -0
- data/lib/hoodoo/logger/writers/log_entries_dot_com_writer.rb +64 -0
- data/lib/hoodoo/logger/writers/stream_writer.rb +43 -0
- data/lib/hoodoo/middleware.rb +33 -0
- data/lib/hoodoo/presenters.rb +45 -0
- data/lib/hoodoo/presenters/base.rb +281 -0
- data/lib/hoodoo/presenters/base_dsl.rb +519 -0
- data/lib/hoodoo/presenters/common_resource_fields.rb +31 -0
- data/lib/hoodoo/presenters/embedding.rb +232 -0
- data/lib/hoodoo/presenters/types/array.rb +118 -0
- data/lib/hoodoo/presenters/types/boolean.rb +26 -0
- data/lib/hoodoo/presenters/types/date.rb +26 -0
- data/lib/hoodoo/presenters/types/date_time.rb +26 -0
- data/lib/hoodoo/presenters/types/decimal.rb +47 -0
- data/lib/hoodoo/presenters/types/enum.rb +55 -0
- data/lib/hoodoo/presenters/types/field.rb +158 -0
- data/lib/hoodoo/presenters/types/float.rb +26 -0
- data/lib/hoodoo/presenters/types/hash.rb +361 -0
- data/lib/hoodoo/presenters/types/integer.rb +26 -0
- data/lib/hoodoo/presenters/types/object.rb +117 -0
- data/lib/hoodoo/presenters/types/string.rb +53 -0
- data/lib/hoodoo/presenters/types/tags.rb +24 -0
- data/lib/hoodoo/presenters/types/text.rb +26 -0
- data/lib/hoodoo/presenters/types/uuid.rb +54 -0
- data/lib/hoodoo/services.rb +34 -0
- data/lib/hoodoo/services/discovery/discoverers/by_consul.rb +66 -0
- data/lib/hoodoo/services/discovery/discoverers/by_convention.rb +173 -0
- data/lib/hoodoo/services/discovery/discoverers/by_drb/by_drb.rb +195 -0
- data/lib/hoodoo/services/discovery/discoverers/by_drb/drb_server.rb +166 -0
- data/lib/hoodoo/services/discovery/discoverers/by_drb/drb_server_start.rb +37 -0
- data/lib/hoodoo/services/discovery/discovery.rb +186 -0
- data/lib/hoodoo/services/discovery/results/for_amqp.rb +58 -0
- data/lib/hoodoo/services/discovery/results/for_http.rb +85 -0
- data/lib/hoodoo/services/discovery/results/for_local.rb +85 -0
- data/lib/hoodoo/services/discovery/results/for_remote.rb +57 -0
- data/lib/hoodoo/services/middleware/amqp_log_message.rb +186 -0
- data/lib/hoodoo/services/middleware/amqp_log_writer.rb +119 -0
- data/lib/hoodoo/services/middleware/endpoints/inter_resource_local.rb +130 -0
- data/lib/hoodoo/services/middleware/endpoints/inter_resource_remote.rb +202 -0
- data/lib/hoodoo/services/middleware/exception_reporting/base_reporter.rb +105 -0
- data/lib/hoodoo/services/middleware/exception_reporting/exception_reporting.rb +115 -0
- data/lib/hoodoo/services/middleware/exception_reporting/reporters/airbrake_reporter.rb +64 -0
- data/lib/hoodoo/services/middleware/exception_reporting/reporters/raygun_reporter.rb +63 -0
- data/lib/hoodoo/services/middleware/interaction.rb +127 -0
- data/lib/hoodoo/services/middleware/middleware.rb +2705 -0
- data/lib/hoodoo/services/middleware/rack_monkey_patch.rb +73 -0
- data/lib/hoodoo/services/services/context.rb +153 -0
- data/lib/hoodoo/services/services/implementation.rb +132 -0
- data/lib/hoodoo/services/services/interface.rb +934 -0
- data/lib/hoodoo/services/services/permissions.rb +250 -0
- data/lib/hoodoo/services/services/request.rb +189 -0
- data/lib/hoodoo/services/services/response.rb +316 -0
- data/lib/hoodoo/services/services/service.rb +141 -0
- data/lib/hoodoo/services/services/session.rb +729 -0
- data/lib/hoodoo/utilities.rb +12 -0
- data/lib/hoodoo/utilities/string_inquirer.rb +54 -0
- data/lib/hoodoo/utilities/utilities.rb +380 -0
- data/lib/hoodoo/utilities/uuid.rb +44 -0
- data/lib/hoodoo/version.rb +17 -0
- data/spec/active/active_record/base_spec.rb +57 -0
- data/spec/active/active_record/creator_spec.rb +88 -0
- data/spec/active/active_record/dated_spec.rb +248 -0
- data/spec/active/active_record/error_mapping_spec.rb +360 -0
- data/spec/active/active_record/finder_spec.rb +744 -0
- data/spec/active/active_record/search_helper_spec.rb +384 -0
- data/spec/active/active_record/secure_spec.rb +435 -0
- data/spec/active/active_record/support_spec.rb +225 -0
- data/spec/active/active_record/translated_spec.rb +19 -0
- data/spec/active/active_record/uuid_spec.rb +72 -0
- data/spec/active/active_record/writer_spec.rb +272 -0
- data/spec/alchemy/alchemy-amq.rb +33 -0
- data/spec/client/augmented_array_spec.rb +15 -0
- data/spec/client/augmented_base_spec.rb +50 -0
- data/spec/client/augmented_hash_spec.rb +15 -0
- data/spec/client/client_spec.rb +955 -0
- data/spec/client/endpoint/endpoint_spec.rb +70 -0
- data/spec/client/endpoint/endpoints/amqp_spec.rb +16 -0
- data/spec/client/endpoint/endpoints/auto_session_spec.rb +9 -0
- data/spec/client/endpoint/endpoints/http_based_spec.rb +9 -0
- data/spec/client/endpoint/endpoints/http_spec.rb +103 -0
- data/spec/client/endpoint/endpoints/not_found_spec.rb +35 -0
- data/spec/client/headers_spec.rb +172 -0
- data/spec/communicators/fast_spec.rb +9 -0
- data/spec/communicators/pool_spec.rb +339 -0
- data/spec/communicators/slow_spec.rb +15 -0
- data/spec/data/resources/caller_spec.rb +156 -0
- data/spec/data/resources/errors_spec.rb +22 -0
- data/spec/data/resources/log_spec.rb +20 -0
- data/spec/data/resources/session_spec.rb +15 -0
- data/spec/data/types/error_primitive_spec.rb +15 -0
- data/spec/data/types/permissions_defaults_spec.rb +25 -0
- data/spec/data/types/permissions_full_spec.rb +44 -0
- data/spec/data/types/permissions_resources_spec.rb +34 -0
- data/spec/data/types/permissions_spec.rb +37 -0
- data/spec/errors/error_descriptions_spec.rb +98 -0
- data/spec/errors/errors_spec.rb +346 -0
- data/spec/integration/service_actions_spec.rb +112 -0
- data/spec/logger/fast_writer_spec.rb +18 -0
- data/spec/logger/logger_spec.rb +259 -0
- data/spec/logger/slow_writer_spec.rb +144 -0
- data/spec/logger/writers/file_writer_spec.rb +37 -0
- data/spec/logger/writers/log_entries_dot_com_writer_spec.rb +29 -0
- data/spec/logger/writers/stream_writer_spec.rb +38 -0
- data/spec/presenters/base_dsl_spec.rb +111 -0
- data/spec/presenters/base_spec.rb +871 -0
- data/spec/presenters/common_resource_fields_spec.rb +30 -0
- data/spec/presenters/embedding_spec.rb +87 -0
- data/spec/presenters/types/array_spec.rb +249 -0
- data/spec/presenters/types/boolean_spec.rb +51 -0
- data/spec/presenters/types/date_spec.rb +57 -0
- data/spec/presenters/types/date_time_spec.rb +59 -0
- data/spec/presenters/types/decimal_spec.rb +58 -0
- data/spec/presenters/types/enum_spec.rb +71 -0
- data/spec/presenters/types/field_spec.rb +77 -0
- data/spec/presenters/types/float_spec.rb +50 -0
- data/spec/presenters/types/hash_spec.rb +1069 -0
- data/spec/presenters/types/integer_spec.rb +50 -0
- data/spec/presenters/types/object_spec.rb +177 -0
- data/spec/presenters/types/string_spec.rb +65 -0
- data/spec/presenters/types/tags_spec.rb +56 -0
- data/spec/presenters/types/text_spec.rb +50 -0
- data/spec/presenters/types/uuid_spec.rb +46 -0
- data/spec/presenters/walk_spec.rb +198 -0
- data/spec/services/discovery/discoverers/by_consul_spec.rb +29 -0
- data/spec/services/discovery/discoverers/by_convention_spec.rb +67 -0
- data/spec/services/discovery/discoverers/by_drb/by_drb_spec.rb +80 -0
- data/spec/services/discovery/discoverers/by_drb/drb_server_spec.rb +205 -0
- data/spec/services/discovery/discovery_spec.rb +73 -0
- data/spec/services/discovery/results/for_amqp_spec.rb +17 -0
- data/spec/services/discovery/results/for_http_spec.rb +37 -0
- data/spec/services/discovery/results/for_local_spec.rb +21 -0
- data/spec/services/discovery/results/for_remote_spec.rb +15 -0
- data/spec/services/middleware/amqp_log_message_spec.rb +60 -0
- data/spec/services/middleware/amqp_log_writer_spec.rb +95 -0
- data/spec/services/middleware/endpoints/inter_resource_local_spec.rb +9 -0
- data/spec/services/middleware/endpoints/inter_resource_remote_spec.rb +9 -0
- data/spec/services/middleware/exception_reporting/base_reporter_spec.rb +16 -0
- data/spec/services/middleware/exception_reporting/exception_reporting_spec.rb +92 -0
- data/spec/services/middleware/exception_reporting/reporters/airbrake_reporter_spec.rb +24 -0
- data/spec/services/middleware/exception_reporting/reporters/raygun_reporter_spec.rb +23 -0
- data/spec/services/middleware/middleware_cors_spec.rb +93 -0
- data/spec/services/middleware/middleware_create_update_spec.rb +489 -0
- data/spec/services/middleware/middleware_dated_at_spec.rb +186 -0
- data/spec/services/middleware/middleware_exotic_communication_spec.rb +560 -0
- data/spec/services/middleware/middleware_logging_spec.rb +356 -0
- data/spec/services/middleware/middleware_multi_local_spec.rb +1094 -0
- data/spec/services/middleware/middleware_multi_remote_spec.rb +1440 -0
- data/spec/services/middleware/middleware_permissions_spec.rb +1014 -0
- data/spec/services/middleware/middleware_public_spec.rb +238 -0
- data/spec/services/middleware/middleware_spec.rb +1569 -0
- data/spec/services/middleware/string_inquirer_spec.rb +30 -0
- data/spec/services/services/application_spec.rb +74 -0
- data/spec/services/services/context_spec.rb +48 -0
- data/spec/services/services/implementation_spec.rb +45 -0
- data/spec/services/services/interface_spec.rb +262 -0
- data/spec/services/services/permissions_spec.rb +249 -0
- data/spec/services/services/request_spec.rb +95 -0
- data/spec/services/services/response_spec.rb +250 -0
- data/spec/services/services/session_spec.rb +432 -0
- data/spec/spec_helper.rb +298 -0
- data/spec/utilities/utilities_spec.rb +537 -0
- data/spec/utilities/uuid_spec.rb +20 -0
- metadata +615 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hoodoo::Services::Discovery do
|
4
|
+
context 'alone' do
|
5
|
+
it 'supports announcement directly' do
|
6
|
+
d = described_class.new
|
7
|
+
expect( d.announce( 'Foo', 3 ) ).to eq( nil )
|
8
|
+
end
|
9
|
+
|
10
|
+
# Note intentional mixed Symbol / String usage.
|
11
|
+
|
12
|
+
it 'records local announcements' do
|
13
|
+
d = described_class.new
|
14
|
+
expect( d.announce( 'Foo', 3 ) ).to eq( nil )
|
15
|
+
expect( d.is_local?( :Foo, 3 ) ).to eq( true )
|
16
|
+
expect( d.is_local?( 'Foo', 2 ) ).to eq( false )
|
17
|
+
expect( d.is_local?( 'Bar', 3 ) ).to eq( false )
|
18
|
+
expect( d.is_local?( 'Bar', 2 ) ).to eq( false )
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'complains about missing subclass implementations' do
|
22
|
+
d = described_class.new
|
23
|
+
expect {
|
24
|
+
d.discover( 'Foo', 3 )
|
25
|
+
}.to raise_exception( RuntimeError, "Hoodoo::Services::Discovery::Base subclass does not implement remote discovery required for resource 'Foo' / version '3'" )
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when subclassed' do
|
30
|
+
class RSpecTestDiscoverer < described_class
|
31
|
+
def announce_remote( resource, version, options )
|
32
|
+
'announce'
|
33
|
+
end
|
34
|
+
def discover_remote( resource, version )
|
35
|
+
'discover'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'calls with configuration options' do
|
40
|
+
opts = { :foo => :bar, :bar => :baz }
|
41
|
+
expect_any_instance_of( RSpecTestDiscoverer ).to receive( :configure_with ).with( opts ).and_call_original
|
42
|
+
RSpecTestDiscoverer.new( opts )
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'passes announcements on' do
|
46
|
+
opts = { :foo => :bar, :bar => :baz }
|
47
|
+
d = RSpecTestDiscoverer.new
|
48
|
+
expect( d ).to receive( :announce_remote ).with( :Foo, 3, opts ).and_call_original
|
49
|
+
expect( d.announce( :Foo, '3', opts ) ).to eq( 'announce' )
|
50
|
+
expect( d ).to receive( :announce_remote ).with( :Foo, 3, {} ).and_call_original
|
51
|
+
expect( d.announce( 'Foo', 3 ) ).to eq( 'announce' )
|
52
|
+
expect( d ).to receive( :announce_remote ).with( :Foo, 1, {} ).and_call_original
|
53
|
+
expect( d.announce( :Foo ) ).to eq( 'announce' )
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'does not pass local discovery on' do
|
57
|
+
d = RSpecTestDiscoverer.new
|
58
|
+
d.announce( 'Baz', 4 )
|
59
|
+
|
60
|
+
expect( d ).to_not receive( :discover_remote )
|
61
|
+
expect( d.discover( :Baz, '4' ) ).to eq( 'announce' )
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'passes remote discovery on' do
|
65
|
+
d = RSpecTestDiscoverer.new
|
66
|
+
d.announce( :Bar, 2 )
|
67
|
+
d.instance_variable_set( '@known_local_resources', {} ) # Hack for test!
|
68
|
+
|
69
|
+
expect( d ).to receive( :discover_remote ).with( :Bar, 2 ).and_call_original
|
70
|
+
expect( d.discover( 'Bar', 2 ) ).to eq( 'discover' )
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hoodoo::Services::Discovery::ForAMQP do
|
4
|
+
it 'stores known quantities and retrieves them' do
|
5
|
+
r = described_class.new(
|
6
|
+
resource: 'Foo', # Note String
|
7
|
+
version: 3,
|
8
|
+
queue_name: 'queue.foo',
|
9
|
+
equivalent_path: '/v3/foos'
|
10
|
+
)
|
11
|
+
|
12
|
+
expect( r.resource ).to eq( :Foo ) # Note Symbol
|
13
|
+
expect( r.version ).to eq( 3 )
|
14
|
+
expect( r.queue_name ).to eq( 'queue.foo' )
|
15
|
+
expect( r.equivalent_path ).to eq( '/v3/foos' )
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hoodoo::Services::Discovery::ForHTTP do
|
4
|
+
|
5
|
+
let( :endpoint_uri ) { URI.parse( 'http://foo.bar/v1/foos' ) }
|
6
|
+
let( :proxy_uri ) { URI.parse( 'http://bar.baz/v1/bars' ) }
|
7
|
+
|
8
|
+
it 'stores mandatory quantities and retrieves them' do
|
9
|
+
r = described_class.new(
|
10
|
+
resource: 'Foo', # Note String
|
11
|
+
version: 3,
|
12
|
+
endpoint_uri: endpoint_uri(),
|
13
|
+
)
|
14
|
+
|
15
|
+
expect( r.resource ).to eq( :Foo ) # Note Symbol
|
16
|
+
expect( r.version ).to eq( 3 )
|
17
|
+
expect( r.endpoint_uri ).to eq( endpoint_uri() )
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'stores all known quantities and retrieves them' do
|
21
|
+
r = described_class.new(
|
22
|
+
resource: :Bar, # Note Symbol
|
23
|
+
version: 2,
|
24
|
+
endpoint_uri: endpoint_uri(),
|
25
|
+
proxy_uri: proxy_uri(),
|
26
|
+
ca_file: 'foo.pem',
|
27
|
+
http_timeout: 0.25
|
28
|
+
)
|
29
|
+
|
30
|
+
expect( r.resource ).to eq( :Bar ) # Also Symbol
|
31
|
+
expect( r.version ).to eq( 2 )
|
32
|
+
expect( r.endpoint_uri ).to eq( endpoint_uri() )
|
33
|
+
expect( r.proxy_uri ).to eq( proxy_uri() )
|
34
|
+
expect( r.ca_file ).to eq( 'foo.pem' )
|
35
|
+
expect( r.http_timeout ).to eq( 0.25 )
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hoodoo::Services::Discovery::ForLocal do
|
4
|
+
it 'stores known quantities and retrieves them' do
|
5
|
+
r = described_class.new(
|
6
|
+
resource: 'Foo', # Note String
|
7
|
+
version: 3,
|
8
|
+
base_path: '/v3/foos',
|
9
|
+
routing_regexp: /\/v3\/foos.*/,
|
10
|
+
interface_class: Array, # Just any old class
|
11
|
+
implementation_instance: Array.new # Just any old comparable class instance
|
12
|
+
)
|
13
|
+
|
14
|
+
expect( r.resource ).to eq( :Foo ) # Note Symbol
|
15
|
+
expect( r.version ).to eq( 3 )
|
16
|
+
expect( r.base_path ).to eq( '/v3/foos' )
|
17
|
+
expect( r.routing_regexp ).to eq( /\/v3\/foos.*/ )
|
18
|
+
expect( r.interface_class ).to eq( Array )
|
19
|
+
expect( r.implementation_instance ).to eq( Array.new )
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hoodoo::Services::Discovery::ForRemote do
|
4
|
+
it 'stores known quantities and retrieves them' do
|
5
|
+
r = described_class.new(
|
6
|
+
resource: 'Foo', # Note String
|
7
|
+
version: 3,
|
8
|
+
wrapped_endpoint: Array.new # Just any old comparable class instance
|
9
|
+
)
|
10
|
+
|
11
|
+
expect( r.resource ).to eq( :Foo ) # Note Symbol
|
12
|
+
expect( r.version ).to eq( 3 )
|
13
|
+
expect( r.wrapped_endpoint ).to eq( Array.new )
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Hoodoo::Services::Middleware::AMQPLogMessage do
|
4
|
+
|
5
|
+
require 'msgpack'
|
6
|
+
|
7
|
+
let( :now ) do
|
8
|
+
Time.now
|
9
|
+
end
|
10
|
+
|
11
|
+
let( :source_hash ) do
|
12
|
+
{
|
13
|
+
:id => '1',
|
14
|
+
:level => 'info',
|
15
|
+
:component => 'RSpec',
|
16
|
+
:code => 'hello',
|
17
|
+
|
18
|
+
:data => { 'this' => 'that' },
|
19
|
+
|
20
|
+
:interaction_id => '3',
|
21
|
+
:caller_id => '2',
|
22
|
+
:identity => { :foo => '4', :bar => '5' }
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
let( :hash ) do
|
27
|
+
source_hash().merge( :reported_at => now() )
|
28
|
+
end
|
29
|
+
|
30
|
+
let( :compare_hash ) do
|
31
|
+
Hoodoo::Utilities.stringify(
|
32
|
+
source_hash().merge(
|
33
|
+
:reported_at => now().strftime( Hoodoo::Services::Middleware::AMQPLogMessage::TIME_FORMATTER )
|
34
|
+
)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'serializes' do
|
39
|
+
obj = described_class.new( hash )
|
40
|
+
expect( MessagePack.unpack( obj.serialize ) ).to eq( compare_hash )
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'deserializes' do
|
44
|
+
obj = described_class.new( hash )
|
45
|
+
expect( MessagePack.unpack( obj.serialize ) ).to eq( compare_hash )
|
46
|
+
obj.id = nil # Clear some instance vars
|
47
|
+
obj.level = nil
|
48
|
+
obj.deserialize # Should reset instance vars based on prior serialization
|
49
|
+
expect( MessagePack.unpack( obj.serialize ) ).to eq( compare_hash )
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'handles nil' do
|
53
|
+
local_compare_hash = Hoodoo::Utilities.stringify(
|
54
|
+
source_hash.merge( :reported_at => nil )
|
55
|
+
)
|
56
|
+
|
57
|
+
obj = described_class.new( source_hash )
|
58
|
+
expect( MessagePack.unpack( obj.serialize ) ).to eq( local_compare_hash )
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
require 'timecop'
|
3
|
+
|
4
|
+
describe Hoodoo::Services::Middleware::AMQPLogWriter do
|
5
|
+
before :each do
|
6
|
+
@session_id = Hoodoo::UUID.generate
|
7
|
+
@caller_id = Hoodoo::UUID.generate
|
8
|
+
@caller_version = 2
|
9
|
+
@session = Hoodoo::Services::Session.new( {
|
10
|
+
:session_id => @session_id,
|
11
|
+
:memcached_host => '0.0.0.0:0',
|
12
|
+
:caller_id => @caller_id,
|
13
|
+
:caller_version => @caller_version
|
14
|
+
} )
|
15
|
+
|
16
|
+
@permissions_hash = {
|
17
|
+
'default' => {
|
18
|
+
'else' => 'deny',
|
19
|
+
'actions' => {
|
20
|
+
'show' => 'ask'
|
21
|
+
}
|
22
|
+
},
|
23
|
+
'resources' => {
|
24
|
+
'Clock' => {
|
25
|
+
'else' => 'allow',
|
26
|
+
'actions' => {
|
27
|
+
'show' => 'deny'
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
@session.permissions = Hoodoo::Services::Permissions.new( @permissions_hash )
|
34
|
+
|
35
|
+
@identity_id_1 = Hoodoo::UUID.generate
|
36
|
+
@identity_id_2 = Hoodoo::UUID.generate
|
37
|
+
@identity_id_3 = Hoodoo::UUID.generate
|
38
|
+
|
39
|
+
@authorised_ids = [ Hoodoo::UUID.generate, Hoodoo::UUID.generate ]
|
40
|
+
@authorised_codes = [ 'CODE_A', 'CODE_B' ]
|
41
|
+
|
42
|
+
@session.identity = {
|
43
|
+
:id_1 => @identity_id_1,
|
44
|
+
:id_2 => @identity_id_2,
|
45
|
+
:id_3 => @identity_id_3,
|
46
|
+
}
|
47
|
+
|
48
|
+
@session.scoping = {
|
49
|
+
:authorised_ids => @authorised_ids,
|
50
|
+
:authorised_codes => @authorised_codes
|
51
|
+
}
|
52
|
+
|
53
|
+
@alchemy = OpenStruct.new
|
54
|
+
@queue = 'foo.bar'
|
55
|
+
@logger = described_class.new( @alchemy, @queue )
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sends expected data' do
|
59
|
+
Timecop.freeze do
|
60
|
+
level = 'warn'
|
61
|
+
component = 'test_component'
|
62
|
+
code = 'test_code'
|
63
|
+
reported_at = Time.now
|
64
|
+
id = Hoodoo::UUID.generate
|
65
|
+
interaction_id = Hoodoo::UUID.generate
|
66
|
+
data = {
|
67
|
+
:id => id,
|
68
|
+
:session => @session.to_h(),
|
69
|
+
:interaction_id => interaction_id
|
70
|
+
}
|
71
|
+
|
72
|
+
expected_hash = {
|
73
|
+
:id => id,
|
74
|
+
:level => 'warn',
|
75
|
+
:component => component,
|
76
|
+
:code => code,
|
77
|
+
:reported_at => reported_at,
|
78
|
+
|
79
|
+
:data => data,
|
80
|
+
|
81
|
+
:interaction_id => interaction_id,
|
82
|
+
:caller_id => @session.caller_id,
|
83
|
+
:identity => Hoodoo::Utilities.stringify( @session.identity.to_h ),
|
84
|
+
|
85
|
+
:routing_key => @queue,
|
86
|
+
}
|
87
|
+
|
88
|
+
expect( Hoodoo::Services::Middleware::AMQPLogMessage ).to receive( :new ).with( expected_hash ).and_return( {} )
|
89
|
+
expect_any_instance_of( Hash ).to receive( :serialize ).once
|
90
|
+
expect( @alchemy ).to receive( :send_message ).with( {} ).once
|
91
|
+
|
92
|
+
@logger.report( level, component, code, data )
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hoodoo::Services::Middleware::InterResourceLocal do
|
4
|
+
|
5
|
+
# No tests here yet. Full coverage is achieved by other tests running
|
6
|
+
# through the HTTP and AMQP endpoints (amongst other stuff), since
|
7
|
+
# those inherit from this code.
|
8
|
+
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hoodoo::Services::Middleware::InterResourceRemote do
|
4
|
+
|
5
|
+
# No tests here yet. Full coverage is achieved by other tests running
|
6
|
+
# through the HTTP and AMQP endpoints (amongst other stuff), since
|
7
|
+
# those inherit from this code.
|
8
|
+
|
9
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter do
|
4
|
+
class TestERBase < described_class
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'is a singleton' do
|
8
|
+
expect( TestERBase.instance ).to be_a( TestERBase )
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'provides a reporting example' do
|
12
|
+
expect {
|
13
|
+
TestERBase.instance.report( RuntimeError.new )
|
14
|
+
}.to raise_exception( RuntimeError )
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hoodoo::Services::Middleware::ExceptionReporting do
|
4
|
+
|
5
|
+
class TestReporterA < Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter
|
6
|
+
def report( e, env = nil )
|
7
|
+
expectable_hook_a( e, env )
|
8
|
+
sleep 0.2 # Deliberate delay to make sure ::wait() works;
|
9
|
+
# intermittent failures would imply it doesn't.
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class TestReporterB < Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter
|
14
|
+
def report( e, env = nil )
|
15
|
+
expectable_hook_b( e, env )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class TestReporterC < Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter
|
20
|
+
def report( e, env = nil )
|
21
|
+
raise 'I am broken'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
after :each do
|
26
|
+
Hoodoo::Services::Middleware::ExceptionReporting.wait()
|
27
|
+
Hoodoo::Services::Middleware::ExceptionReporting.remove( TestReporterA )
|
28
|
+
Hoodoo::Services::Middleware::ExceptionReporting.remove( TestReporterB )
|
29
|
+
Hoodoo::Services::Middleware::ExceptionReporting.remove( TestReporterC )
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'lets me add and remove handlers' do
|
33
|
+
Hoodoo::Services::Middleware::ExceptionReporting.add( TestReporterA )
|
34
|
+
Hoodoo::Services::Middleware::ExceptionReporting.add( TestReporterB )
|
35
|
+
Hoodoo::Services::Middleware::ExceptionReporting.remove( TestReporterA )
|
36
|
+
Hoodoo::Services::Middleware::ExceptionReporting.remove( TestReporterB )
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'calls handler A' do
|
40
|
+
Hoodoo::Services::Middleware::ExceptionReporting.add( TestReporterA )
|
41
|
+
ex = RuntimeError.new( 'A' )
|
42
|
+
ha = { :foo => :bar }
|
43
|
+
expect( TestReporterA.instance ).to receive( :expectable_hook_a ).once.with( ex, ha )
|
44
|
+
Hoodoo::Services::Middleware::ExceptionReporting.report( ex, ha )
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'calls handler B' do
|
48
|
+
Hoodoo::Services::Middleware::ExceptionReporting.add( TestReporterB )
|
49
|
+
ex = RuntimeError.new( 'B' )
|
50
|
+
expect( TestReporterB.instance ).to receive( :expectable_hook_b ).once.with( ex, nil )
|
51
|
+
Hoodoo::Services::Middleware::ExceptionReporting.report( ex )
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'calls all handlers' do
|
55
|
+
Hoodoo::Services::Middleware::ExceptionReporting.add( TestReporterA )
|
56
|
+
Hoodoo::Services::Middleware::ExceptionReporting.add( TestReporterB )
|
57
|
+
|
58
|
+
ex_one = RuntimeError.new( 'One' )
|
59
|
+
ex_two = RuntimeError.new( 'Two' )
|
60
|
+
|
61
|
+
expect( TestReporterA.instance ).to receive( :expectable_hook_a ).once.with( ex_one, nil )
|
62
|
+
expect( TestReporterB.instance ).to receive( :expectable_hook_b ).once.with( ex_one, nil )
|
63
|
+
expect( TestReporterA.instance ).to receive( :expectable_hook_a ).once.with( ex_two, nil )
|
64
|
+
expect( TestReporterB.instance ).to receive( :expectable_hook_b ).once.with( ex_two, nil )
|
65
|
+
|
66
|
+
Hoodoo::Services::Middleware::ExceptionReporting.report( ex_one, nil )
|
67
|
+
Hoodoo::Services::Middleware::ExceptionReporting.report( ex_two, nil )
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'complains about bad additions' do
|
71
|
+
expect {
|
72
|
+
Hoodoo::Services::Middleware::ExceptionReporting.add( Object )
|
73
|
+
}.to raise_exception( RuntimeError )
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'complains about bad removals' do
|
77
|
+
expect {
|
78
|
+
Hoodoo::Services::Middleware::ExceptionReporting.remove( Object )
|
79
|
+
}.to raise_exception( RuntimeError )
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'ignores exceptions in reporters' do
|
83
|
+
Hoodoo::Services::Middleware::ExceptionReporting.add( TestReporterC ) # Add "exception raiser first
|
84
|
+
Hoodoo::Services::Middleware::ExceptionReporting.add( TestReporterA ) # Then this after, which should still be called
|
85
|
+
|
86
|
+
ex = RuntimeError.new( 'A' )
|
87
|
+
ha = { :foo => :bar }
|
88
|
+
|
89
|
+
expect( TestReporterA.instance ).to receive( :expectable_hook_a ).once.with( ex, ha )
|
90
|
+
Hoodoo::Services::Middleware::ExceptionReporting.report( ex, ha )
|
91
|
+
end
|
92
|
+
end
|