Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/config/data/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions internal/config/data/ns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down