diff --git a/internal/config/data/ns.go b/internal/config/data/ns.go index 81943035..fb1a515b 100644 --- a/internal/config/data/ns.go +++ b/internal/config/data/ns.go @@ -12,7 +12,7 @@ import ( const ( // MaxFavoritesNS number # favorite namespaces to keep in the configuration. - MaxFavoritesNS = 9 + MaxFavoritesNS = 10 ) // Namespace tracks active and favorites namespaces. @@ -68,6 +68,13 @@ func (n *Namespace) Validate(c client.Connection) { n.rmFavNS(ns) } } + + if len(n.Favorites) > MaxFavoritesNS { + log.Debug().Msgf("[Namespace] Number of favorite exceeds hard limit of %v. Trimming.", MaxFavoritesNS) + for _, ns := range n.Favorites[MaxFavoritesNS:] { + n.rmFavNS(ns) + } + } } // SetActive set the active namespace. diff --git a/internal/config/data/ns_test.go b/internal/config/data/ns_test.go index d66b6903..a6e94aa3 100644 --- a/internal/config/data/ns_test.go +++ b/internal/config/data/ns_test.go @@ -35,6 +35,17 @@ func TestNSValidateNoNS(t *testing.T) { assert.Equal(t, []string{"default"}, ns.Favorites) } +func TestNsValidateMaxNS(t *testing.T) { + allNS := []string{"ns9","ns8","ns7","ns6","ns5","ns4", "ns3", "ns2", "ns1", "all", "default"} + ns := data.NewNamespace() + + ns.Favorites = allNS + + ns.Validate(mock.NewMockConnection()) + + assert.Equal(t, data.MaxFavoritesNS, len(ns.Favorites)) +} + func TestNSSetActive(t *testing.T) { allNS := []string{"ns4", "ns3", "ns2", "ns1", "all", "default"} uu := []struct {