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 filesmine
parent
b5710af314
commit
4a9f4c3153
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue