hoodoo 1.16.0 → 1.16.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab07823823bf92d1cfdd5070eb71585b95d7adbe
4
- data.tar.gz: a9249d7aa4765ca5979eee0cf58d6919fc6f8a27
3
+ metadata.gz: 5c9903a7189fc118fdbc3deae1277da2602c64b9
4
+ data.tar.gz: b5b04be6a1c82e1958cf70863270a282256a51bc
5
5
  SHA512:
6
- metadata.gz: 8fe35486b496e980d15d58cb2c353b86692833612a89cee9349b00bfac3fe5e54ae6cdb2fcd2591dd99454d66034e13b7fce01c6234c05ef0f5bcb7ea9dd0da1
7
- data.tar.gz: 7101a2bc7914f19ab92fc338a74c16cb3f045b8d39985137dc177aae2bc1eb256a9f9af812be3eecd6eab78c2654302f853033c8bbf2bb88f7ab23e3767192fd
6
+ metadata.gz: 333ed5e667ade4ab94ee3f16dfb37e84351ab8678a09d5ffc325021b07e56e6bd3c95f820cec9ede6586c542de8abcad1746418f99e17c1ded693afb873efc51
7
+ data.tar.gz: 912f44dce0110b695c2815f969aa3a6a00e5ad88caf48e65578cb6097ef45f91446b59748523a8d8a65770b0d60f203f462ad5b479382feee4058e5e7a96d2a7
@@ -10,7 +10,6 @@
10
10
 
11
11
  require 'ostruct'
12
12
  require 'hoodoo/transient_store'
13
- require 'hoodoo/transient_store/mocks/dalli_client'
14
13
 
15
14
  module Hoodoo
16
15
  module Services
@@ -17,3 +17,8 @@ require 'hoodoo/transient_store/transient_store/base'
17
17
  require 'hoodoo/transient_store/transient_store/memcached'
18
18
  require 'hoodoo/transient_store/transient_store/redis'
19
19
  require 'hoodoo/transient_store/transient_store/memcached_redis_mirror'
20
+
21
+ # Mock plugin back-ends for test or other stubbing purposes.
22
+
23
+ require 'hoodoo/transient_store/mocks/dalli_client'
24
+ require 'hoodoo/transient_store/mocks/redis'
@@ -78,13 +78,20 @@ module Hoodoo
78
78
  # Connect to Memcached if possible and return the connected Dalli client
79
79
  # instance, else raise an exception.
80
80
  #
81
- # +host+:: Connection URI, e.g. <tt>localhost:11211</tt>.
81
+ # +host+:: Connection URI, e.g. <tt>localhost:11211</tt>.
82
+ # +namespace+:: Key namespace (prefix), as a String or Symbol; e.g.
83
+ # <tt>"nz_co_loyalty_hoodoo_transient_store_"</tt>.
82
84
  #
83
85
  def connect_to_memcached( host, namespace )
84
86
  exception = nil
85
87
  stats = nil
86
88
  client = nil
87
89
 
90
+ if Hoodoo::Services::Middleware.environment.test? &&
91
+ ( host.nil? || host.empty? )
92
+ return Hoodoo::TransientStore::Mocks::DalliClient.new
93
+ end
94
+
88
95
  begin
89
96
  client = ::Dalli::Client.new(
90
97
  host,
@@ -91,6 +91,11 @@ module Hoodoo
91
91
  info = nil
92
92
  client = nil
93
93
 
94
+ if Hoodoo::Services::Middleware.environment.test? &&
95
+ ( host.nil? || host.empty? )
96
+ return Hoodoo::TransientStore::Mocks::Redis.new
97
+ end
98
+
94
99
  begin
95
100
  client = ::Redis.new(
96
101
  :url => host,
@@ -12,6 +12,6 @@ module Hoodoo
12
12
  # The Hoodoo gem version. If this changes, ensure that the date in
13
13
  # "hoodoo.gemspec" is correct and run "bundle install" (or "update").
14
14
  #
15
- VERSION = '1.16.0'
15
+ VERSION = '1.16.1'
16
16
 
17
17
  end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'hoodoo/transient_store/mocks/dalli_client'
3
2
 
4
3
  describe Hoodoo::Services::Session do
5
4
 
data/spec/spec_helper.rb CHANGED
@@ -197,7 +197,27 @@ end
197
197
  # &block:: Block of code to call while +STDOUT+ is disabled.
198
198
  #
199
199
  def spec_helper_silence_stdout( &block )
200
- Kernel.silence_stream( STDOUT, &block )
200
+ spec_helper_silence_stream( $stdout, &block )
201
+ end
202
+
203
+ # Back-end to #spec_helper_silence_stdout; can silence arbitrary streams.
204
+ #
205
+ # +stream+:: The output stream to silence, e.g. <tt>$stdout</tt>
206
+ # &block:: Block of code to call while output stream is disabled.
207
+ #
208
+ def spec_helper_silence_stream( stream, &block )
209
+ begin
210
+ old_stream = stream.dup
211
+ stream.reopen( File::NULL )
212
+ stream.sync = true
213
+
214
+ yield
215
+
216
+ ensure
217
+ stream.reopen( old_stream )
218
+ old_stream.close
219
+
220
+ end
201
221
  end
202
222
 
203
223
  # Start up a service application under WEBrick via Rack on localhost, using
@@ -1,8 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'hoodoo/transient_store/mocks/dalli_client'
4
- require 'hoodoo/transient_store/mocks/redis'
5
-
6
3
  # These tests make sure that the mirror class calls down to the Memcached and
7
4
  # Redis abstractions, but assumes those abstractions are thoroughly tested by
8
5
  # their own unit tests. So it makes sure it gets expected call and result
@@ -1,7 +1,5 @@
1
1
  require 'spec_helper'
2
-
3
2
  require 'dalli'
4
- require 'hoodoo/transient_store/mocks/dalli_client'
5
3
 
6
4
  # ============================================================================
7
5
 
@@ -41,4 +41,41 @@ describe Hoodoo::TransientStore::Mocks::DalliClient do
41
41
  end
42
42
  end
43
43
 
44
+ context 'approximate old behaviour by' do
45
+ it 'using the mock client in test mode if there is an empty host' do
46
+ expect_any_instance_of( Hoodoo::TransientStore::Mocks::DalliClient ).to receive( :initialize ).once.and_call_original()
47
+
48
+ Hoodoo::TransientStore::Memcached.new(
49
+ storage_host_uri: '',
50
+ namespace: 'test_namespace_'
51
+ )
52
+ end
53
+
54
+ it 'using the mock client in test mode if there is a "nil" host' do
55
+ expect_any_instance_of( Hoodoo::TransientStore::Mocks::DalliClient ).to receive( :initialize ).once.and_call_original()
56
+
57
+ Hoodoo::TransientStore::Memcached.new(
58
+ storage_host_uri: nil,
59
+ namespace: 'test_namespace_'
60
+ )
61
+ end
62
+
63
+ it 'using a real client in test mode if there is a defined host' do
64
+ expect_any_instance_of( ::Dalli::Client ).to receive( :initialize ).once.and_call_original()
65
+
66
+ # Silence 'Errno::ECONNREFUSED' warnings if Memcached is not actually
67
+ # running at the given URI. That's fine; it's the initializer test
68
+ # above which is important.
69
+ #
70
+ spec_helper_silence_stream( $stdout ) do
71
+ spec_helper_silence_stream( $stderr ) do
72
+ Hoodoo::TransientStore::Memcached.new(
73
+ storage_host_uri: 'localhost:11211',
74
+ namespace: 'test_namespace_'
75
+ )
76
+ end
77
+ end
78
+ end
79
+ end
80
+
44
81
  end
@@ -25,4 +25,41 @@ describe Hoodoo::TransientStore::Mocks::Redis do
25
25
  end
26
26
  end
27
27
 
28
+ context 'mimic approcimated old behaviour of its Memcached counterpart by' do
29
+ it 'using the mock client in test mode if there is an empty host' do
30
+ expect_any_instance_of( Hoodoo::TransientStore::Mocks::Redis ).to receive( :initialize ).once.and_call_original()
31
+
32
+ Hoodoo::TransientStore::Redis.new(
33
+ storage_host_uri: '',
34
+ namespace: 'test_namespace_'
35
+ )
36
+ end
37
+
38
+ it 'using the mock client in test mode if there is a "nil" host' do
39
+ expect_any_instance_of( Hoodoo::TransientStore::Mocks::Redis ).to receive( :initialize ).once.and_call_original()
40
+
41
+ Hoodoo::TransientStore::Redis.new(
42
+ storage_host_uri: nil,
43
+ namespace: 'test_namespace_'
44
+ )
45
+ end
46
+
47
+ it 'using a real client in test mode if there is a defined host' do
48
+ expect_any_instance_of( ::Redis ).to receive( :initialize ).once.and_call_original()
49
+
50
+ # Silence 'Errno::ECONNREFUSED' warnings if Memcached is not actually
51
+ # running at the given URI. That's fine; it's the initializer test
52
+ # above which is important.
53
+ #
54
+ spec_helper_silence_stream( $stdout ) do
55
+ spec_helper_silence_stream( $stderr ) do
56
+ Hoodoo::TransientStore::Redis.new(
57
+ storage_host_uri: 'redis://localhost:6379',
58
+ namespace: 'test_namespace_'
59
+ )
60
+ end
61
+ end
62
+ end
63
+ end
64
+
28
65
  end
@@ -1,7 +1,5 @@
1
1
  require 'spec_helper'
2
-
3
2
  require 'redis'
4
- require 'hoodoo/transient_store/mocks/redis'
5
3
 
6
4
  # ============================================================================
7
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoodoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loyalty New Zealand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-23 00:00:00.000000000 Z
11
+ date: 2017-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dalli