@@ -17,6 +17,7 @@ import (
1717 "github.com/smartcontractkit/chainlink-common/pkg/config"
1818 "github.com/smartcontractkit/chainlink-common/pkg/contexts"
1919 "github.com/smartcontractkit/chainlink-common/pkg/logger"
20+ "github.com/smartcontractkit/chainlink-common/pkg/settings"
2021 "github.com/smartcontractkit/chainlink-common/pkg/settings/limits"
2122)
2223
@@ -199,6 +200,10 @@ func TestDefaultGetter_SettingMap(t *testing.T) {
199200 }
200201}` )
201202 reinit () // set default vars
203+
204+ // ensure merged values; defaults must remain
205+ require .Equal (t , "true" , Default .PerWorkflow .ChainAllowed .Values ["3379446385462418246" ])
206+ // confirm
202207 got , err = limit .GetOrDefault (ctx , DefaultGetter )
203208 require .NoError (t , err )
204209 require .False (t , got )
@@ -233,13 +238,73 @@ func TestDefaultGetter_SettingMap(t *testing.T) {
233238 require .True (t , got )
234239}
235240
236- func TestChainAllows (t * testing.T ) {
237- gl , err := limits .MakeGateLimiter (limits.Factory {Logger : logger .Test (t )}, Default .PerWorkflow .ChainAllowed )
241+ func TestDefaultEnvVars (t * testing.T ) {
242+ // confirm defaults
243+ require .Equal (t , "" , Default .PerWorkflow .ChainAllowed .Values ["1234" ])
244+ require .Equal (t , "true" , Default .PerWorkflow .ChainAllowed .Values ["3379446385462418246" ])
245+
246+ t .Cleanup (reinit ) // restore after
247+
248+ // update defaults
249+ t .Setenv (envNameSettingsDefault , `{
250+ "PerWorkflow": {
251+ "ChainAllowed": {
252+ "Values": {
253+ "1234": "true"
254+ }
255+ }
256+ }
257+ }` )
258+ reinit () // set default vars
259+
260+ // confirm through Default
261+ require .Equal (t , "true" , Default .PerWorkflow .ChainAllowed .Values ["1234" ])
262+ // without affecting others (they must merge)
263+ require .Equal (t , "true" , Default .PerWorkflow .ChainAllowed .Values ["3379446385462418246" ])
264+
265+ // confirm through DefaultGetter
266+ gl , err := limits .MakeGateLimiter (limits.Factory {Logger : logger .Test (t ), Settings : DefaultGetter }, Default .PerWorkflow .ChainAllowed )
238267 require .NoError (t , err )
239268
240- ctx := contexts .WithCRE (t .Context (), contexts.CRE {Owner : "owner-id" , Workflow : "foo" })
269+ ctx := contexts .WithCRE (t .Context (), contexts.CRE {Org : "foo" , Owner : "owner-id" , Workflow : "foo" })
270+ // defaults and global override allowed
271+ assert .NoError (t , gl .AllowErr (contexts .WithChainSelector (ctx , 3379446385462418246 )))
272+ assert .NoError (t , gl .AllowErr (contexts .WithChainSelector (ctx , 12922642891491394802 )))
273+ assert .NoError (t , gl .AllowErr (contexts .WithChainSelector (ctx , 1234 )))
274+
275+ // update overrides
276+ t .Setenv (envNameSettingsDefault , "{}" )
277+ t .Setenv (envNameSettings , `{
278+ "global": {
279+ "PerWorkflow": {
280+ "ChainAllowed": {
281+ "Values": {
282+ "1234": "true"
283+ }
284+ }
285+ }
286+ }
287+ }` )
288+
289+ reinit () // set default vars
290+
291+ // confirm through DefaultGetter
292+ gl , err = limits .MakeGateLimiter (limits.Factory {Logger : logger .Test (t ), Settings : DefaultGetter }, Default .PerWorkflow .ChainAllowed )
293+ require .NoError (t , err )
294+
295+ // defaults and global override allowed
296+ assert .NoError (t , gl .AllowErr (contexts .WithChainSelector (ctx , 3379446385462418246 )))
297+ assert .NoError (t , gl .AllowErr (contexts .WithChainSelector (ctx , 12922642891491394802 )))
298+ assert .NoError (t , gl .AllowErr (contexts .WithChainSelector (ctx , 1234 )))
299+
300+ // confirm through an empty, but non-nil getter
301+ getter , err := settings .NewJSONGetter ([]byte (`{}` ))
302+ require .NoError (t , err )
303+ gl , err = limits .MakeGateLimiter (limits.Factory {Logger : logger .Test (t ), Settings : getter }, Default .PerWorkflow .ChainAllowed )
304+ require .NoError (t , err )
241305
306+ // defaults and global override allowed
242307 assert .NoError (t , gl .AllowErr (contexts .WithChainSelector (ctx , 3379446385462418246 )))
243308 assert .NoError (t , gl .AllowErr (contexts .WithChainSelector (ctx , 12922642891491394802 )))
244- assert .ErrorIs (t , gl .AllowErr (contexts .WithChainSelector (ctx , 1234 )), limits. ErrorNotAllowed {} )
309+ assert .NoError (t , gl .AllowErr (contexts .WithChainSelector (ctx , 1234 )))
245310}
0 commit comments