Skip to content

Commit

Permalink
Some additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan De Marino committed Jul 5, 2022
1 parent c3be04e commit a77fef1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
12 changes: 12 additions & 0 deletions internal/hclogutils/args_test.go
Expand Up @@ -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",
Expand Down
52 changes: 51 additions & 1 deletion internal/logging/filtering_test.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)")},
Expand Down

0 comments on commit a77fef1

Please sign in to comment.