test: restore global log level after each SetLogLevel subtest

SetLogLevel mutates a process-global logger, leaking state into
subsequent tests and causing order-dependent failures. Save the
current level before each subtest and restore it via t.Cleanup.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Manuel Rüger 2026-03-12 23:18:49 +01:00
parent 5e1d40d910
commit 664a99cd00

View File

@ -97,6 +97,8 @@ func Test_setLogLevel(t *testing.T) {
} }
for name, tt := range tests { for name, tt := range tests {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
prev := log.GetLevel()
t.Cleanup(func() { log.SetLevel(prev) })
cmd := &cli.Command{ cmd := &cli.Command{
Name: "test", Name: "test",
Flags: []cli.Flag{ Flags: []cli.Flag{