Skip to content

Commit a4088ae

Browse files
committed
test: update server logger behavior to use default logger when nil
Updates the server to use a default logger instead of panicking when the provided logger is nil. Adjusts corresponding tests to validate the new behavior, ensuring `nil logger should not panic`. Includes default configuration initialization in `server.go`.
1 parent b5155b4 commit a4088ae

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

server/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ func New(cfg Config, handler http.Handler, logger *slog.Logger) *Server {
3535
logger = slog.New(slog.DiscardHandler)
3636
}
3737

38+
logger = logger.WithGroup("server")
39+
40+
cfg.SetDefaults()
41+
3842
h2s := &http2.Server{
3943
MaxConcurrentStreams: cfg.HTTP2.MaxConcurrentStreams,
4044
MaxReadFrameSize: cfg.HTTP2.MaxReadFrameSize,

server/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ func TestNewServer(t *testing.T) {
8585
})
8686
})
8787

88-
t.Run("nil logger should panic", func(t *testing.T) {
89-
assert.Panics(t, func() {
88+
t.Run("nil logger should not panic", func(t *testing.T) {
89+
assert.NotPanics(t, func() {
9090
New(Config{}, handler, nil)
9191
})
9292
})

0 commit comments

Comments
 (0)