rediconn 0.1.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a3d21283e1d2fc7408ee46ef9f2ed42fde12ebc746c8286838de74423490589
4
- data.tar.gz: 919073adc67f177847c9f83992b5db89f32437609809beb821df7d8a3ab06afd
3
+ metadata.gz: 54e6df0f25be3be0062203f5c60fafd449fdc669da8ca541e4c30ee27c1514fd
4
+ data.tar.gz: ed6906c298c98b89c16c80a0271dbf5194ba34122081fece8ea52fe4f7bf1add
5
5
  SHA512:
6
- metadata.gz: ec84c0303f1a2fd986990c2544a3fd084a1b5b788b062649d845e2049b5b5c774bc8f6cee3b772fa33e5f82726eb878da63341e4d60405c79fbd9a9dda241a3d
7
- data.tar.gz: 4bba5d5d56ece05eb05f3a5cc822ec80de399be16c56c7c2f979c6fc62beacf42b01468345ce8f46c17be763158fe28dc68e02840953c189c6c2bbdff1309e77
6
+ metadata.gz: f9cd3b6a3b0a46abbe5258f5482571e1b131e61d28de814e341c847b28bfadff00061e270c0e0537a7eceb9f6df3ae5118dcea132ac8efdfc8246e815820be5f
7
+ data.tar.gz: 61d74b2277f556a99aba92ee56b2993c66125cf677c3b572e33f315c42f415ed1deb49a4316365d6828c6927787527a22d4f4030f33547dc45e005e152095a97
@@ -77,7 +77,9 @@ module RediConn
77
77
  if (ptr = ENV["#{prefix}_REDIS_PROVIDER"]).present?
78
78
  return ENV[ptr]
79
79
  else
80
- vars.push(*KNOWN_REDIS_URL_ENVS.map { |e| ENV["#{prefix}_#{e}"] })
80
+ # Collect variable *names*, the same as the unprefixed branch below - the lookup at
81
+ # the end of this method resolves them against ENV
82
+ vars.push(*KNOWN_REDIS_URL_ENVS.map { |e| "#{prefix}_#{e}" })
81
83
  end
82
84
  end
83
85
 
@@ -1,3 +1,3 @@
1
1
  module RediConn
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RediConn::RedisConnection, '.determine_redis_provider' do
4
+ PREFIXED = "MYAPP"
5
+ GLOBAL_URL = "redis://global:6379/0"
6
+ PREFIXED_URL = "redis://prefixed:6379/1"
7
+
8
+ # Every variable this method consults, so an example never inherits the developer's shell
9
+ MANAGED_VARS = (
10
+ RediConn::RedisConnection::KNOWN_REDIS_URL_ENVS +
11
+ RediConn::RedisConnection::KNOWN_REDIS_URL_ENVS.map { |e| "#{PREFIXED}_#{e}" } +
12
+ ["REDIS_PROVIDER", "#{PREFIXED}_REDIS_PROVIDER", "POINTED_AT_URL"]
13
+ ).freeze
14
+
15
+ around do |example|
16
+ saved = MANAGED_VARS.to_h { |name| [name, ENV[name]] }
17
+ MANAGED_VARS.each { |name| ENV.delete(name) }
18
+ example.run
19
+ ensure
20
+ saved.each { |name, value| value.nil? ? ENV.delete(name) : ENV[name] = value }
21
+ end
22
+
23
+ def resolve(prefix: PREFIXED, explicit: false)
24
+ described_class.send(:determine_redis_provider, prefix: prefix, explicit: explicit)
25
+ end
26
+
27
+ context "with no configuration" do
28
+ it "returns nil" do
29
+ expect(resolve).to be_nil
30
+ end
31
+ end
32
+
33
+ context "with only a global URL" do
34
+ before { ENV["REDIS_URL"] = GLOBAL_URL }
35
+
36
+ it "falls back to it" do
37
+ expect(resolve).to eq(GLOBAL_URL)
38
+ end
39
+
40
+ it "falls back to it when no prefix is given" do
41
+ expect(resolve(prefix: nil)).to eq(GLOBAL_URL)
42
+ end
43
+
44
+ it "does not fall back when the prefix is declared explicit" do
45
+ expect(resolve(explicit: true)).to be_nil
46
+ end
47
+ end
48
+
49
+ # Regression: the prefixed branch used to collect env *values* while the lookup expected
50
+ # *names*, so a prefixed URL resolved to nil and silently fell through to the global one
51
+ context "with a prefixed URL" do
52
+ before { ENV["#{PREFIXED}_REDIS_URL"] = PREFIXED_URL }
53
+
54
+ it "resolves it" do
55
+ expect(resolve).to eq(PREFIXED_URL)
56
+ end
57
+
58
+ it "resolves it when a global URL is also set" do
59
+ ENV["REDIS_URL"] = GLOBAL_URL
60
+
61
+ expect(resolve).to eq(PREFIXED_URL)
62
+ end
63
+
64
+ it "resolves it when the prefix is declared explicit" do
65
+ expect(resolve(explicit: true)).to eq(PREFIXED_URL)
66
+ end
67
+
68
+ it "is ignored for a different prefix" do
69
+ ENV["REDIS_URL"] = GLOBAL_URL
70
+
71
+ expect(resolve(prefix: "OTHER")).to eq(GLOBAL_URL)
72
+ end
73
+ end
74
+
75
+ RediConn::RedisConnection::KNOWN_REDIS_URL_ENVS.each do |var|
76
+ context "with #{PREFIXED}_#{var}" do
77
+ it "resolves it" do
78
+ ENV["#{PREFIXED}_#{var}"] = PREFIXED_URL
79
+
80
+ expect(resolve).to eq(PREFIXED_URL)
81
+ end
82
+ end
83
+
84
+ context "with #{var}" do
85
+ it "resolves it" do
86
+ ENV[var] = GLOBAL_URL
87
+
88
+ expect(resolve).to eq(GLOBAL_URL)
89
+ end
90
+ end
91
+ end
92
+
93
+ context "with a prefixed provider pointer" do
94
+ before do
95
+ ENV["#{PREFIXED}_REDIS_PROVIDER"] = "POINTED_AT_URL"
96
+ ENV["POINTED_AT_URL"] = PREFIXED_URL
97
+ end
98
+
99
+ it "follows the pointer" do
100
+ expect(resolve).to eq(PREFIXED_URL)
101
+ end
102
+
103
+ it "wins over a global URL" do
104
+ ENV["REDIS_URL"] = GLOBAL_URL
105
+
106
+ expect(resolve).to eq(PREFIXED_URL)
107
+ end
108
+ end
109
+
110
+ context "with a global provider pointer" do
111
+ before do
112
+ ENV["REDIS_PROVIDER"] = "POINTED_AT_URL"
113
+ ENV["POINTED_AT_URL"] = GLOBAL_URL
114
+ end
115
+
116
+ it "follows the pointer" do
117
+ expect(resolve).to eq(GLOBAL_URL)
118
+ end
119
+
120
+ it "loses to a prefixed URL" do
121
+ ENV["#{PREFIXED}_REDIS_URL"] = PREFIXED_URL
122
+
123
+ expect(resolve).to eq(PREFIXED_URL)
124
+ end
125
+ end
126
+
127
+ describe ".configured?" do
128
+ it "is false when nothing is set" do
129
+ expect(described_class.configured?(PREFIXED)).to be false
130
+ end
131
+
132
+ it "is true for a prefixed URL" do
133
+ ENV["#{PREFIXED}_REDIS_URL"] = PREFIXED_URL
134
+
135
+ expect(described_class.configured?(PREFIXED)).to be true
136
+ end
137
+
138
+ it "is false for a global URL when the prefix is explicit" do
139
+ ENV["REDIS_URL"] = GLOBAL_URL
140
+
141
+ expect(described_class.configured?(PREFIXED)).to be false
142
+ end
143
+
144
+ it "is true for a global URL when the prefix is not explicit" do
145
+ ENV["REDIS_URL"] = GLOBAL_URL
146
+
147
+ expect(described_class.configured?(PREFIXED, explicit: false)).to be true
148
+ end
149
+ end
150
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rediconn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan Knapp
@@ -91,6 +91,7 @@ files:
91
91
  - lib/rediconn/redis_script.rb
92
92
  - lib/rediconn/version.rb
93
93
  - rediconn.gemspec
94
+ - spec/rediconn/determine_redis_provider_spec.rb
94
95
  - spec/rediconn/redis_connection_spec.rb
95
96
  - spec/spec_helper.rb
96
97
  homepage: https://instructure.com
@@ -114,5 +115,6 @@ rubygems_version: 3.6.9
114
115
  specification_version: 4
115
116
  summary: Gem for consistent, de-duplicated Redis Connection Pooling
116
117
  test_files:
118
+ - spec/rediconn/determine_redis_provider_spec.rb
117
119
  - spec/rediconn/redis_connection_spec.rb
118
120
  - spec/spec_helper.rb