diff --git a/internal/hclogutils/args_test.go b/internal/hclogutils/args_test.go index 6323590..22dd976 100644 --- a/internal/hclogutils/args_test.go +++ b/internal/hclogutils/args_test.go @@ -195,6 +195,18 @@ func TestArgsToKeys(t *testing.T) { "map1-key3", }, }, + "non-even-number-of-args": { + args: []interface{}{ + "map1-key1", "map1-value1", + "map1-key2", "map1-value2", + "map1-key3", + }, + expectedKeys: []string{ + "map1-key1", + "map1-key2", + "map1-key3", + }, + }, "multiple-different-keys": { args: []interface{}{ "map1-key1", "map1-value1", diff --git a/internal/logging/filtering_test.go b/internal/logging/filtering_test.go index 19515f0..c70d297 100644 --- a/internal/logging/filtering_test.go +++ b/internal/logging/filtering_test.go @@ -98,7 +98,7 @@ func TestShouldOmit(t *testing.T) { } } -func TestShouldMask(t *testing.T) { +func TestApplyMask(t *testing.T) { t.Parallel() testCases := map[string]struct { @@ -144,6 +144,56 @@ func TestShouldMask(t *testing.T) { }, }, }, + "mask-log-by-non-even-args-cannot-mask-missing-value": { + lOpts: LoggerOpts{ + MaskLogValueByKeys: []string{"K2", "k4"}, + }, + msg: testLogMsg, + argSlices: [][]interface{}{ + { + "k1", "v1", + "k2", "v2", + }, + { + "k3", "v3", + "k4", + }, + }, + expectedMsg: "System FOO has caused error BAR because of incorrectly configured BAZ", + expectedArgSlices: [][]interface{}{ + { + "k1", "v1", + "k2", "***", + }, + { + "k3", "v3", + "k4", + }, + }, + }, + "mask-log-by-non-even-args": { + lOpts: LoggerOpts{ + MaskLogValueByKeys: []string{"K2"}, + }, + msg: testLogMsg, + argSlices: [][]interface{}{ + { + "k1", "v1", + "k2", "v2", + "k3", "v3", + "k4", + }, + }, + expectedMsg: "System FOO has caused error BAR because of incorrectly configured BAZ", + expectedArgSlices: [][]interface{}{ + { + "k1", "v1", + "k2", "***", + "k3", "v3", + "k4", + }, + }, + }, "mask-log-matching-regexp-case-insensitive": { lOpts: LoggerOpts{ MaskLogMatchingRegexp: []*regexp.Regexp{regexp.MustCompile("(?i)(foo|bar)")},