@@ -1413,39 +1413,72 @@ func TestConfig_LoadConsulTemplateConfig(t *testing.T) {
1413
1413
require .Equal (t , 20 * time .Second , * templateConfig .VaultRetry .MaxBackoff )
1414
1414
}
1415
1415
1416
- func TestConfig_LoadConsulTemplateBasic (t * testing.T ) {
1417
- defaultConfig := DefaultConfig ()
1418
-
1419
- // hcl
1420
- agentConfig , err := LoadConfig ("test-resources/client_with_basic_template.hcl" )
1421
- require .NoError (t , err )
1422
- require .NotNil (t , agentConfig .Client .TemplateConfig )
1423
-
1424
- agentConfig = defaultConfig .Merge (agentConfig )
1425
-
1426
- clientAgent := Agent {config : agentConfig }
1427
- clientConfig , err := clientAgent .clientConfig ()
1428
- require .NoError (t , err )
1429
-
1430
- templateConfig := clientConfig .TemplateConfig
1431
- require .NotNil (t , templateConfig )
1432
- require .True (t , templateConfig .DisableSandbox )
1433
- require .Len (t , templateConfig .FunctionDenylist , 1 )
1434
-
1435
- // json
1436
- agentConfig , err = LoadConfig ("test-resources/client_with_basic_template.json" )
1437
- require .NoError (t , err )
1416
+ func TestConfig_LoadConsulTemplate_FunctionDenylist (t * testing.T ) {
1417
+ cases := []struct {
1418
+ File string
1419
+ Expected * client.ClientTemplateConfig
1420
+ }{
1421
+ {
1422
+ "test-resources/minimal_client.hcl" ,
1423
+ nil ,
1424
+ },
1425
+ {
1426
+ "test-resources/client_with_basic_template.json" ,
1427
+ & client.ClientTemplateConfig {
1428
+ DisableSandbox : true ,
1429
+ FunctionDenylist : []string {},
1430
+ },
1431
+ },
1432
+ {
1433
+ "test-resources/client_with_basic_template.hcl" ,
1434
+ & client.ClientTemplateConfig {
1435
+ DisableSandbox : true ,
1436
+ FunctionDenylist : []string {},
1437
+ },
1438
+ },
1439
+ {
1440
+ "test-resources/client_with_function_denylist.hcl" ,
1441
+ & client.ClientTemplateConfig {
1442
+ DisableSandbox : false ,
1443
+ FunctionDenylist : []string {"foo" },
1444
+ },
1445
+ },
1446
+ {
1447
+ "test-resources/client_with_function_denylist_empty.hcl" ,
1448
+ & client.ClientTemplateConfig {
1449
+ DisableSandbox : false ,
1450
+ FunctionDenylist : []string {},
1451
+ },
1452
+ },
1453
+ {
1454
+ "test-resources/client_with_function_denylist_empty_string.hcl" ,
1455
+ & client.ClientTemplateConfig {
1456
+ DisableSandbox : true ,
1457
+ FunctionDenylist : []string {"" },
1458
+ },
1459
+ },
1460
+ {
1461
+ "test-resources/client_with_function_denylist_nil.hcl" ,
1462
+ & client.ClientTemplateConfig {
1463
+ DisableSandbox : true ,
1464
+ },
1465
+ },
1466
+ {
1467
+ "test-resources/client_with_empty_template.hcl" ,
1468
+ nil ,
1469
+ },
1470
+ }
1438
1471
1439
- agentConfig = defaultConfig .Merge (agentConfig )
1472
+ for _ , tc := range cases {
1473
+ t .Run (tc .File , func (t * testing.T ) {
1474
+ agentConfig , err := LoadConfig (tc .File )
1440
1475
1441
- clientAgent = Agent {config : agentConfig }
1442
- clientConfig , err = clientAgent .clientConfig ()
1443
- require .NoError (t , err )
1476
+ require .NoError (t , err )
1444
1477
1445
- templateConfig = clientConfig .TemplateConfig
1446
- require .NotNil ( t , templateConfig )
1447
- require . True ( t , templateConfig . DisableSandbox )
1448
- require . Len ( t , templateConfig . FunctionDenylist , 1 )
1478
+ templateConfig := agentConfig . Client .TemplateConfig
1479
+ require .Equal ( t , tc . Expected , templateConfig )
1480
+ } )
1481
+ }
1449
1482
}
1450
1483
1451
1484
func TestParseMultipleIPTemplates (t * testing.T ) {
0 commit comments