Fix Mark-Range command: ensure that NS Favorite doesn't exceed the limit (#2881)

* ensure that number of favorite namespace is never exceeds hard limit

* remove newlines from files
mine
Ruslan Timofieiev 2024-09-14 21:40:45 +03:00 committed by GitHub
parent b5710af314
commit 4a9f4c3153
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -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.

View File

@ -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 {