Skip to content

Commit 3ed6250

Browse files
authored
chore(rpc_datasource): add warning for unexpected build option keys (#267)
1 parent d4d5826 commit 3ed6250

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ def self.configure_polling_pool(max_threads:)
1212
Utils::SchemaPollingPool.instance.configure(max_threads: max_threads)
1313
end
1414

15+
KNOWN_BUILD_OPTIONS = %i[uri auth_secret introspection introspection_etag schema_polling_interval_sec].freeze
16+
1517
def self.build(options)
18+
unknown_keys = options.keys - KNOWN_BUILD_OPTIONS
19+
if unknown_keys.any?
20+
ForestAdminAgent::Facades::Container.logger.log(
21+
'Warn',
22+
"[RPCDatasource] Unknown option(s) passed to build: #{unknown_keys.join(", ")}. " \
23+
"Known options are: #{KNOWN_BUILD_OPTIONS.join(", ")}"
24+
)
25+
end
26+
1627
uri = options[:uri]
1728
auth_secret = options[:auth_secret] || ForestAdminAgent::Facades::Container.cache(:auth_secret)
1829
provided_introspection = options[:introspection]

packages/forest_admin_datasource_rpc/spec/forest_admin_datasource_rpc_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,39 @@ module ForestAdminDatasourceRpc
1616

1717
include_examples 'with introspection'
1818

19+
context 'with unknown options' do
20+
let(:schema_polling_client) { instance_double(Utils::SchemaPollingClient, start?: true, stop: nil, current_schema: introspection) }
21+
let(:logger) { ForestAdminAgent::Facades::Container.logger }
22+
23+
before do
24+
allow(Utils::SchemaPollingClient).to receive(:new).and_return(schema_polling_client)
25+
end
26+
27+
it 'logs a warning when unknown keys are passed' do
28+
described_class.build({ uri: 'http://localhost', url: 'http://localhost', foo: 'bar' })
29+
30+
expect(logger).to have_received(:log).with(
31+
'Warn',
32+
a_string_matching(/Unknown option.*\burl\b.*\bfoo\b/)
33+
)
34+
end
35+
36+
it 'logs a warning when a key does not exist in known options' do
37+
described_class.build({ uri: 'http://localhost', url: 'http://localhost' })
38+
39+
expect(logger).to have_received(:log).with(
40+
'Warn',
41+
a_string_matching(/Unknown option.*url.*Known options are/)
42+
)
43+
end
44+
45+
it 'does not log a warning when only known keys are passed' do
46+
described_class.build({ uri: 'http://localhost', auth_secret: 'secret', schema_polling_interval_sec: 60 })
47+
48+
expect(logger).not_to have_received(:log).with('Warn', anything)
49+
end
50+
end
51+
1952
context 'when server is running' do
2053
let(:schema_polling_client) { instance_double(Utils::SchemaPollingClient, start?: true, stop: nil, current_schema: introspection) }
2154
let(:response) { Utils::SchemaResponse.new(introspection, 'etag123') }

0 commit comments

Comments
 (0)