package flag import "testing" func TestDebugScopeEnabled(t *testing.T) { origDebug := Debug origScopes := DebugScopes defer func() { Debug = origDebug DebugScopes = origScopes }() t.Run("off when debug disabled", func(t *testing.T) { Debug = false DebugScopes = nil if DebugScopeEnabled("tools") { t.Fatal("scope should be disabled when Debug is false") } }) t.Run("all scopes when set is empty", func(t *testing.T) { Debug = true DebugScopes = nil for _, s := range []string{"tools", "http", "config", "anything"} { if !DebugScopeEnabled(s) { t.Fatalf("scope %q should be enabled when DebugScopes is empty", s) } } }) t.Run("only listed scopes when set is non-empty", func(t *testing.T) { Debug = true DebugScopes = map[string]struct{}{"tools": {}} if !DebugScopeEnabled("tools") { t.Fatal("tools should be enabled") } if DebugScopeEnabled("http") { t.Fatal("http should not be enabled") } }) }