Skip to content

Commit 5398ef5

Browse files
author
DerekStrickland
committed
Added test fixtures and removed the IsEmpty check
1 parent 4bc254d commit 5398ef5

8 files changed

+89
-21
lines changed

client/config/config.go

-17
Original file line numberDiff line numberDiff line change
@@ -445,23 +445,6 @@ func (c *ClientTemplateConfig) Merge(b *ClientTemplateConfig) *ClientTemplateCon
445445
return &result
446446
}
447447

448-
func (c *ClientTemplateConfig) IsEmpty() bool {
449-
if c == nil {
450-
return true
451-
}
452-
453-
return !c.DisableSandbox &&
454-
len(c.FunctionDenylist) == 0 &&
455-
len(c.FunctionBlacklist) == 0 &&
456-
c.BlockQueryWaitTime == nil &&
457-
c.BlockQueryWaitTimeHCL == "" &&
458-
c.MaxStale == nil &&
459-
c.MaxStaleHCL == "" &&
460-
c.Wait.IsEmpty() &&
461-
c.ConsulRetry.IsEmpty() &&
462-
c.VaultRetry.IsEmpty()
463-
}
464-
465448
// WaitConfig is mirrored from templateconfig.WaitConfig because we need to handle
466449
// the HCL conversion which happens in agent.ParseConfigFile
467450
// NOTE: Since Consul Template requires pointers, this type uses pointers to fields

command/agent/config_parse.go

-4
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,4 @@ func finalizeClientTemplateConfig(config *Config) {
259259
if config.Client.TemplateConfig.VaultRetry.IsEmpty() {
260260
config.Client.TemplateConfig.VaultRetry = nil
261261
}
262-
263-
if config.Client.TemplateConfig.IsEmpty() {
264-
config.Client.TemplateConfig = nil
265-
}
266262
}

command/agent/config_parse_test.go

+53
Original file line numberDiff line numberDiff line change
@@ -860,3 +860,56 @@ func permutations(arr []string) [][]string {
860860
helper(arr, len(arr))
861861
return res
862862
}
863+
864+
func TestConfig_Parse_Client_TemplateConfig_FunctionDenylist(t *testing.T) {
865+
t.Parallel()
866+
867+
defaultFunctionDenyList := DefaultConfig().Client.TemplateConfig.FunctionDenylist
868+
869+
cases := []struct {
870+
File string
871+
Expected []string
872+
}{
873+
{
874+
"client_with_function_denylist.hcl",
875+
[]string{"foo"},
876+
},
877+
{
878+
"client_with_function_denylist_empty.hcl",
879+
nil,
880+
},
881+
{
882+
"client_with_function_denylist_empty_string.hcl",
883+
nil,
884+
},
885+
{
886+
"client_with_function_denylist_nil.hcl",
887+
defaultFunctionDenyList,
888+
},
889+
{
890+
"client_with_empty_template.hcl",
891+
defaultFunctionDenyList,
892+
},
893+
{
894+
"minimal_client.hcl",
895+
defaultFunctionDenyList,
896+
},
897+
}
898+
899+
for _, tc := range cases {
900+
t.Run(tc.File, func(t *testing.T) {
901+
path, err := filepath.Abs(filepath.Join("./test-resources", tc.File))
902+
require.NoError(t, err)
903+
904+
parsed, err := ParseConfigFile(path)
905+
require.NoError(t, err)
906+
907+
var actual []string
908+
if tc.Expected != nil {
909+
actual = parsed.Client.TemplateConfig.FunctionDenylist
910+
}
911+
912+
require.EqualValues(t, tc.Expected, actual)
913+
})
914+
}
915+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
client {
2+
enabled = true
3+
4+
template {
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
client {
2+
enabled = true
3+
4+
template {
5+
function_denylist = ["foo"]
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
client {
2+
enabled = true
3+
4+
template {
5+
disable_file_sandbox = true
6+
function_denylist = []
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
client {
2+
enabled = true
3+
4+
template {
5+
disable_file_sandbox = true
6+
function_denylist = [""]
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
client {
2+
enabled = true
3+
4+
template {
5+
disable_file_sandbox = true
6+
}
7+
}

0 commit comments

Comments
 (0)