|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -require 'spec_helper' |
| 3 | +require "spec_helper" |
4 | 4 |
|
5 | 5 | RSpec.describe OpenFeature::SDK::Configuration do |
6 | 6 | subject(:configuration) { described_class.new } |
7 | 7 |
|
8 | | - describe '#set_provider' do |
9 | | - context 'when provider has an init method' do |
| 8 | + describe "#set_provider" do |
| 9 | + context "when provider has an init method" do |
10 | 10 | let(:provider) { OpenFeature::SDK::Provider::InMemoryProvider.new } |
11 | 11 |
|
12 | | - it 'inits and sets the provider' do |
| 12 | + it "inits and sets the provider" do |
13 | 13 | expect(provider).to receive(:init) |
14 | 14 |
|
15 | 15 | configuration.set_provider(provider) |
|
18 | 18 | end |
19 | 19 | end |
20 | 20 |
|
21 | | - context 'when provider does not have an init method' do |
22 | | - it 'sets the default provider' do |
| 21 | + context "when provider does not have an init method" do |
| 22 | + it "sets the default provider" do |
23 | 23 | provider = OpenFeature::SDK::Provider::NoOpProvider.new |
24 | 24 |
|
25 | 25 | configuration.set_provider(provider) |
|
28 | 28 | end |
29 | 29 | end |
30 | 30 |
|
31 | | - context 'when domain is given' do |
32 | | - it 'binds the provider to that domain' do |
| 31 | + context "when domain is given" do |
| 32 | + it "binds the provider to that domain" do |
33 | 33 | provider = OpenFeature::SDK::Provider::InMemoryProvider.new |
34 | 34 | expect(provider).to receive(:init) |
35 | 35 |
|
36 | | - configuration.set_provider(provider, domain: 'testing') |
| 36 | + configuration.set_provider(provider, domain: "testing") |
37 | 37 |
|
38 | | - expect(configuration.provider(domain: 'testing')).to be(provider) |
| 38 | + expect(configuration.provider(domain: "testing")).to be(provider) |
39 | 39 | end |
40 | 40 | end |
41 | 41 |
|
42 | | - context 'when the provider is set concurrently' do |
| 42 | + context "when the provider is set concurrently" do |
43 | 43 | let(:provider) { OpenFeature::SDK::Provider::InMemoryProvider.new } |
44 | | - it 'does not not call shutdown hooks multiple times if multithreaded' do |
| 44 | + it "does not not call shutdown hooks multiple times if multithreaded" do |
45 | 45 | providers = (0..2).map { OpenFeature::SDK::Provider::NoOpProvider.new } |
46 | 46 | providers.each { |provider| expect(provider).to receive(:init) } |
47 | 47 | providers[0, 2].each { |provider| expect(provider).to receive(:shutdown) } |
|
56 | 56 | end |
57 | 57 | end |
58 | 58 |
|
59 | | - describe '#set_provider_and_wait' do |
60 | | - context 'when provider has a successful init method' do |
| 59 | + describe "#set_provider_and_wait" do |
| 60 | + context "when provider has a successful init method" do |
61 | 61 | let(:provider) { OpenFeature::SDK::Provider::InMemoryProvider.new } |
62 | 62 |
|
63 | | - it 'waits for init to complete and sets the provider' do |
| 63 | + it "waits for init to complete and sets the provider" do |
64 | 64 | expect(provider).to receive(:init).once |
65 | 65 |
|
66 | 66 | configuration.set_provider_and_wait(provider) |
67 | 67 |
|
68 | 68 | expect(configuration.provider).to be(provider) |
69 | 69 | end |
70 | 70 |
|
71 | | - it 'supports custom timeout' do |
| 71 | + it "supports custom timeout" do |
72 | 72 | expect(provider).to receive(:init).once |
73 | 73 |
|
74 | 74 | configuration.set_provider_and_wait(provider, timeout: 60) |
|
77 | 77 | end |
78 | 78 | end |
79 | 79 |
|
80 | | - context 'when provider does not have an init method' do |
81 | | - it 'sets the provider without waiting' do |
| 80 | + context "when provider does not have an init method" do |
| 81 | + it "sets the provider without waiting" do |
82 | 82 | provider = OpenFeature::SDK::Provider::NoOpProvider.new |
83 | 83 |
|
84 | 84 | configuration.set_provider_and_wait(provider) |
|
87 | 87 | end |
88 | 88 | end |
89 | 89 |
|
90 | | - context 'when domain is given' do |
91 | | - it 'binds the provider to that domain' do |
| 90 | + context "when domain is given" do |
| 91 | + it "binds the provider to that domain" do |
92 | 92 | provider = OpenFeature::SDK::Provider::InMemoryProvider.new |
93 | 93 | expect(provider).to receive(:init).once |
94 | 94 |
|
95 | | - configuration.set_provider_and_wait(provider, domain: 'testing') |
| 95 | + configuration.set_provider_and_wait(provider, domain: "testing") |
96 | 96 |
|
97 | | - expect(configuration.provider(domain: 'testing')).to be(provider) |
| 97 | + expect(configuration.provider(domain: "testing")).to be(provider) |
98 | 98 | end |
99 | 99 | end |
100 | 100 |
|
101 | | - context 'when provider init raises an exception' do |
| 101 | + context "when provider init raises an exception" do |
102 | 102 | let(:provider) { OpenFeature::SDK::Provider::InMemoryProvider.new } |
103 | | - let(:error_message) { 'Database connection failed' } |
| 103 | + let(:error_message) { "Database connection failed" } |
104 | 104 |
|
105 | 105 | before do |
106 | 106 | allow(provider).to receive(:init).and_raise(StandardError.new(error_message)) |
107 | 107 | end |
108 | 108 |
|
109 | | - it 'raises ProviderInitializationError' do |
| 109 | + it "raises ProviderInitializationError" do |
110 | 110 | expect do |
111 | 111 | configuration.set_provider_and_wait(provider) |
112 | 112 | end.to raise_error(OpenFeature::SDK::ProviderInitializationError) do |error| |
113 | | - expect(error.message).to include('Provider initialization failed') |
| 113 | + expect(error.message).to include("Provider initialization failed") |
114 | 114 | expect(error.message).to include(error_message) |
115 | 115 | expect(error.provider).to be(provider) |
116 | 116 | expect(error.original_error).to be_a(StandardError) |
117 | 117 | expect(error.original_error.message).to eq(error_message) |
118 | 118 | end |
119 | 119 | end |
120 | 120 |
|
121 | | - it 'does not set the provider when init fails' do |
| 121 | + it "does not set the provider when init fails" do |
122 | 122 | old_provider = configuration.provider |
123 | 123 |
|
124 | 124 | expect do |
|
129 | 129 | end |
130 | 130 | end |
131 | 131 |
|
132 | | - context 'when provider init times out' do |
| 132 | + context "when provider init times out" do |
133 | 133 | let(:provider) { OpenFeature::SDK::Provider::InMemoryProvider.new } |
134 | 134 |
|
135 | 135 | before do |
|
138 | 138 | end |
139 | 139 | end |
140 | 140 |
|
141 | | - it 'raises ProviderInitializationError after timeout' do |
| 141 | + it "raises ProviderInitializationError after timeout" do |
142 | 142 | expect do |
143 | 143 | configuration.set_provider_and_wait(provider, timeout: 0.1) |
144 | 144 | end.to raise_error(OpenFeature::SDK::ProviderInitializationError) do |error| |
145 | | - expect(error.message).to include('Provider initialization timed out after 0.1 seconds') |
| 145 | + expect(error.message).to include("Provider initialization timed out after 0.1 seconds") |
146 | 146 | expect(error.provider).to be(provider) |
147 | 147 | expect(error.original_error).to be_a(Timeout::Error) |
148 | 148 | end |
149 | 149 | end |
150 | 150 |
|
151 | | - it 'does not set the provider when init times out' do |
| 151 | + it "does not set the provider when init times out" do |
152 | 152 | old_provider = configuration.provider |
153 | 153 |
|
154 | 154 | expect do |
|
159 | 159 | end |
160 | 160 | end |
161 | 161 |
|
162 | | - context 'when shutting down the old provider fails' do |
| 162 | + context "when shutting down the old provider fails" do |
163 | 163 | let(:old_provider) { OpenFeature::SDK::Provider::InMemoryProvider.new } |
164 | 164 | let(:new_provider) { OpenFeature::SDK::Provider::InMemoryProvider.new } |
165 | 165 |
|
166 | 166 | before do |
167 | 167 | # Set up initial provider |
168 | 168 | configuration.set_provider(old_provider) |
169 | | - allow(old_provider).to receive(:shutdown).and_raise(StandardError.new('Shutdown failed')) |
| 169 | + allow(old_provider).to receive(:shutdown).and_raise(StandardError.new("Shutdown failed")) |
170 | 170 | allow(new_provider).to receive(:init) |
171 | 171 | end |
172 | 172 |
|
173 | | - it 'continues with setting the new provider' do |
| 173 | + it "continues with setting the new provider" do |
174 | 174 | # Should not raise an exception even if shutdown fails |
175 | 175 | configuration.set_provider_and_wait(new_provider) |
176 | 176 |
|
177 | 177 | expect(configuration.provider).to be(new_provider) |
178 | 178 | end |
179 | 179 | end |
180 | 180 |
|
181 | | - context 'when the provider is set concurrently' do |
| 181 | + context "when the provider is set concurrently" do |
182 | 182 | let(:providers) { (0..2).map { OpenFeature::SDK::Provider::InMemoryProvider.new } } |
183 | 183 |
|
184 | | - it 'handles concurrent calls safely' do |
| 184 | + it "handles concurrent calls safely" do |
185 | 185 | providers.each { |provider| expect(provider).to receive(:init).once } |
186 | 186 | # First two providers should be shut down |
187 | 187 | expect(providers[0]).to receive(:shutdown).once |
|
201 | 201 | end |
202 | 202 | end |
203 | 203 |
|
204 | | - context 'when handling complex initialization scenarios' do |
| 204 | + context "when handling complex initialization scenarios" do |
205 | 205 | let(:provider) { OpenFeature::SDK::Provider::InMemoryProvider.new } |
206 | 206 |
|
207 | | - it 'handles provider that responds_to init but init is nil' do |
| 207 | + it "handles provider that responds_to init but init is nil" do |
208 | 208 | allow(provider).to receive(:respond_to?).with(:init).and_return(true) |
209 | 209 | allow(provider).to receive(:init).and_return(nil) |
210 | 210 |
|
|
0 commit comments