mirror of
https://github.com/helm/helm.git
synced 2026-02-03 20:39:45 -05:00
Merge pull request #31723 from matheuscscp/fix-storage-logger
Some checks failed
build-test / build (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
golangci-lint / golangci-lint (push) Has been cancelled
release / release (push) Has been cancelled
release / canary-release (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Some checks failed
build-test / build (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
golangci-lint / golangci-lint (push) Has been cancelled
release / release (push) Has been cancelled
release / canary-release (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
bugfix(logging): fix storage not getting logger from driver
This commit is contained in:
commit
50546ef665
2 changed files with 38 additions and 2 deletions
|
|
@ -339,12 +339,14 @@ func Init(d driver.Driver) *Storage {
|
|||
Driver: d,
|
||||
}
|
||||
|
||||
var h slog.Handler
|
||||
// Get logger from driver if it implements the LoggerSetterGetter interface
|
||||
if ls, ok := d.(logging.LoggerSetterGetter); ok {
|
||||
ls.SetLogger(s.Logger().Handler())
|
||||
h = ls.Logger().Handler()
|
||||
} else {
|
||||
// If the driver does not implement the LoggerSetterGetter interface, set the default logger
|
||||
s.SetLogger(slog.Default().Handler())
|
||||
h = slog.Default().Handler()
|
||||
}
|
||||
s.SetLogger(h)
|
||||
return s
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,10 @@ limitations under the License.
|
|||
package storage // import "helm.sh/helm/v4/pkg/storage"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
|
@ -579,3 +581,35 @@ func assertErrNil(eh func(args ...interface{}), err error, message string) {
|
|||
eh(fmt.Sprintf("%s: %q", message, err))
|
||||
}
|
||||
}
|
||||
|
||||
func TestStorageGetsLoggerFromDriver(t *testing.T) {
|
||||
d := driver.NewMemory()
|
||||
l := &mockSLogHandler{}
|
||||
d.SetLogger(l)
|
||||
s := Init(d)
|
||||
_, _ = s.Get("doesnt-matter", 123)
|
||||
if !l.Called {
|
||||
t.Fatalf("Expected storage to use driver's logger, but it did not")
|
||||
}
|
||||
}
|
||||
|
||||
type mockSLogHandler struct {
|
||||
Called bool
|
||||
}
|
||||
|
||||
func (m *mockSLogHandler) Enabled(context.Context, slog.Level) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *mockSLogHandler) Handle(context.Context, slog.Record) error {
|
||||
m.Called = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockSLogHandler) WithAttrs([]slog.Attr) slog.Handler {
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *mockSLogHandler) WithGroup(string) slog.Handler {
|
||||
return m
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue