Audit: optional logger for sinks will log on errors when context is done (#27859)

* Added optional logger for sink nodes (supplied by backends) will log on errors when context is also done

* changelog
This commit is contained in:
Peter Wilson
2024-07-24 22:57:15 +01:00
committed by GitHub
parent 46d2f41000
commit 69c0433f9f
10 changed files with 108 additions and 12 deletions

View File

@@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/require"
)
@@ -423,3 +424,37 @@ func TestOptions_WithFileMode(t *testing.T) {
})
}
}
// TestOptions_WithLogger exercises WithLogger Option to ensure it performs as expected.
func TestOptions_WithLogger(t *testing.T) {
t.Parallel()
tests := map[string]struct {
value hclog.Logger
isNilExpected bool
}{
"nil-pointer": {
value: nil,
isNilExpected: true,
},
"logger": {
value: hclog.NewNullLogger(),
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()
opts := &options{}
applyOption := WithLogger(tc.value)
err := applyOption(opts)
require.NoError(t, err)
if tc.isNilExpected {
require.Nil(t, opts.withLogger)
} else {
require.NotNil(t, opts.withLogger)
}
})
}
}