Skip to content

Commit 21f5b36

Browse files
committed
Make log_level, root_path, and environment required fields in global configuration schema
1 parent 978e345 commit 21f5b36

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

lib/hooks/core/config_validator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ class ValidationError < StandardError; end
1616
optional(:auth_plugin_dir).maybe(:string)
1717
optional(:lifecycle_plugin_dir).maybe(:string)
1818
optional(:instruments_plugin_dir).maybe(:string)
19-
optional(:log_level).filled(:string, included_in?: %w[debug info warn error])
19+
required(:log_level).filled(:string, included_in?: %w[debug info warn error])
2020
optional(:request_limit).filled(:integer, gt?: 0)
2121
optional(:request_timeout).filled(:integer, gt?: 0)
22-
optional(:root_path).filled(:string)
22+
required(:root_path).filled(:string)
2323
optional(:health_path).filled(:string)
2424
optional(:version_path).filled(:string)
25-
optional(:environment).filled(:string, included_in?: %w[development production])
25+
required(:environment).filled(:string, included_in?: %w[development production])
2626
optional(:endpoints_dir).filled(:string)
2727
optional(:use_catchall_route).filled(:bool)
2828
optional(:normalize_headers).filled(:bool)

spec/unit/lib/hooks/core/config_validator_spec.rb

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,24 @@
2424
end
2525

2626
it "returns validated configuration with minimal fields" do
27-
config = { handler_plugin_dir: "/path/to/handlers" }
27+
config = {
28+
handler_plugin_dir: "/path/to/handlers",
29+
log_level: "info",
30+
root_path: "/app",
31+
environment: "development"
32+
}
2833

2934
result = described_class.validate_global_config(config)
3035

31-
expect(result).to eq({ handler_plugin_dir: "/path/to/handlers" })
36+
expect(result).to eq(config)
3237
end
3338

3439
it "accepts production environment" do
3540
config = {
3641
environment: "production",
37-
handler_plugin_dir: "/path/to/handlers"
42+
handler_plugin_dir: "/path/to/handlers",
43+
log_level: "info",
44+
root_path: "/app"
3845
}
3946

4047
result = described_class.validate_global_config(config)
@@ -46,7 +53,9 @@
4653
%w[debug info warn error].each do |log_level|
4754
config = {
4855
log_level: log_level,
49-
handler_plugin_dir: "/path/to/handlers"
56+
handler_plugin_dir: "/path/to/handlers",
57+
root_path: "/app",
58+
environment: "development"
5059
}
5160

5261
result = described_class.validate_global_config(config)
@@ -121,7 +130,10 @@
121130
config = {
122131
use_catchall_route: "true",
123132
normalize_headers: "1",
124-
handler_plugin_dir: "/path/to/handlers"
133+
handler_plugin_dir: "/path/to/handlers",
134+
log_level: "info",
135+
root_path: "/app",
136+
environment: "development"
125137
}
126138

127139
result = described_class.validate_global_config(config)
@@ -146,7 +158,10 @@
146158
config = {
147159
request_limit: "1024",
148160
request_timeout: "30",
149-
handler_plugin_dir: "/path/to/handlers"
161+
handler_plugin_dir: "/path/to/handlers",
162+
log_level: "info",
163+
root_path: "/app",
164+
environment: "development"
150165
}
151166

152167
result = described_class.validate_global_config(config)
@@ -174,7 +189,10 @@
174189
it "coerces float values to integers by truncating" do
175190
config = {
176191
request_timeout: 30.5,
177-
handler_plugin_dir: "/path/to/handlers"
192+
handler_plugin_dir: "/path/to/handlers",
193+
log_level: "info",
194+
root_path: "/app",
195+
environment: "development"
178196
}
179197

180198
result = described_class.validate_global_config(config)

0 commit comments

Comments
 (0)