// Copyright (c) 2026 Storm Dragon // SPDX-License-Identifier: GPL-3.0-or-later package preferences import ( "git.stormux.org/storm/cthulhu/internal/tentacle" "testing" ) func TestTentacleRepositoryViewsAndRemovedSource(t *testing.T) { first := "https://example.org/team/first" second := "https://other.example.org/team/second" snapshot := &tentacle.Snapshot{ Entries: []tentacle.EntryStatus{{Entry: tentacle.Entry{ID: "installed", LocalID: "echo", Repository: first, RepositoryID: "example.first", Enabled: true}}, {Entry: tentacle.Entry{ID: "local"}}}, Repositories: []tentacle.Repository{ {URL: first, ID: "example.first", Tentacles: []tentacle.Manifest{{ID: "echo"}, {ID: "other"}}}, {URL: second, ID: "example.second", Tentacles: []tentacle.Manifest{{ID: "echo"}}}, }, } all := tentacle_rows(snapshot, "") if len(all) != 4 || !all[0].installed || !all[0].status.Entry.Enabled || all[2].installed || all[0].key == all[3].key { t.Fatalf("All view: %+v", all) } filtered := tentacle_rows(snapshot, first) if len(filtered) != 2 || filtered[0].status.Entry.ID != "installed" || filtered[1].status.Entry.ID != "other" { t.Fatalf("repository view: %+v", filtered) } snapshot.Repositories[0].ID = "example.replacement" if replacement := tentacle_rows(snapshot, first); len(replacement) != 2 || replacement[0].installed { t.Fatalf("replacement source claimed old installation: %+v", replacement) } snapshot.Repositories = snapshot.Repositories[1:] remaining := tentacle_rows(snapshot, "") if len(remaining) != 3 || remaining[0].status.Entry.ID != "installed" { t.Fatalf("removed source lost installed entry: %+v", remaining) } if rows := tentacle_rows(nil, ""); len(rows) != 0 { t.Fatal(rows) } }