mirror of
https://github.com/veggiemonk/awesome-docker.git
synced 2026-06-30 18:40:32 +02:00
29222bfcb5
* feat: add prune subcommand, drop archived/stale entries, add container-explorer Add a new `awesome-docker prune` subcommand that removes README entries whose repository health status matches a configurable set (default: archived,stale). URLs are read from the local health cache, or from a markdown report file via --from-report when the cache is outdated. Apply it against the issue #1439 health report to remove 5 entries that survived the recent reorg: stitchocker, docker-consul, blockbridge-docker-volume, docker-explorer, dockdash. Add google/container-explorer in the Security section as the actively maintained successor to the now-archived google/docker-explorer. Co-Authored-By: Claude <noreply@anthropic.com> * golangci-lint config * fix: address golangci-lint findings Fixes errcheck on bufio.Writer.WriteString, gocritic rangeValCopy via indexed loops with pointer locals, gosec G703 on user-supplied CLI output path, noctx by switching to exec.CommandContext with a timeout in the TUI url opener, prealloc in the scorer test, plus fieldalignment struct reorders and golines line breaks from --fix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
115 lines
3.3 KiB
Markdown
115 lines
3.3 KiB
Markdown
package tui
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/veggiemonk/awesome-docker/internal/cache"
|
|
)
|
|
|
|
func TestBuildTree(t *testing.T) {
|
|
entries := []cache.HealthEntry{
|
|
{URL: "https://github.com/a/b", Name: "a/b", Category: "Projects > Networking", Description: "desc1"},
|
|
{URL: "https://github.com/c/d", Name: "c/d", Category: "Projects > Networking", Description: "desc2"},
|
|
{URL: "https://github.com/e/f", Name: "e/f", Category: "Projects > Security", Description: "desc3"},
|
|
{
|
|
URL: "https://github.com/g/h",
|
|
Name: "g/h",
|
|
Category: "Docker Images > Base Tools",
|
|
Description: "desc4",
|
|
},
|
|
{URL: "https://github.com/i/j", Name: "i/j", Category: "", Description: "no category"},
|
|
}
|
|
|
|
roots := BuildTree(entries)
|
|
|
|
// Should have 3 roots: Docker Images, Projects, Uncategorized (sorted)
|
|
if len(roots) != 3 {
|
|
t.Fatalf("expected 3 roots, got %d", len(roots))
|
|
}
|
|
|
|
if roots[0].Name != "Docker Images" {
|
|
t.Errorf("expected first root 'Docker Images', got %q", roots[0].Name)
|
|
}
|
|
if roots[1].Name != "Projects" {
|
|
t.Errorf("expected second root 'Projects', got %q", roots[1].Name)
|
|
}
|
|
if roots[2].Name != "Uncategorized" {
|
|
t.Errorf("expected third root 'Uncategorized', got %q", roots[2].Name)
|
|
}
|
|
|
|
// Projects > Networking should have 2 entries
|
|
projects := roots[1]
|
|
if len(projects.Children) != 2 {
|
|
t.Fatalf("expected 2 children under Projects, got %d", len(projects.Children))
|
|
}
|
|
networking := projects.Children[0] // Networking < Security alphabetically
|
|
if networking.Name != "Networking" {
|
|
t.Errorf("expected 'Networking', got %q", networking.Name)
|
|
}
|
|
if len(networking.Entries) != 2 {
|
|
t.Errorf("expected 2 entries in Networking, got %d", len(networking.Entries))
|
|
}
|
|
}
|
|
|
|
func TestBuildTreeEmpty(t *testing.T) {
|
|
roots := BuildTree(nil)
|
|
if len(roots) != 0 {
|
|
t.Errorf("expected 0 roots for nil input, got %d", len(roots))
|
|
}
|
|
}
|
|
|
|
func TestTotalEntries(t *testing.T) {
|
|
entries := []cache.HealthEntry{
|
|
{URL: "https://a", Category: "A > B"},
|
|
{URL: "https://b", Category: "A > B"},
|
|
{URL: "https://c", Category: "A > C"},
|
|
{URL: "https://d", Category: "A"},
|
|
}
|
|
roots := BuildTree(entries)
|
|
if len(roots) != 1 {
|
|
t.Fatalf("expected 1 root, got %d", len(roots))
|
|
}
|
|
if roots[0].TotalEntries() != 4 {
|
|
t.Errorf("expected 4 total entries, got %d", roots[0].TotalEntries())
|
|
}
|
|
}
|
|
|
|
func TestFlattenVisible(t *testing.T) {
|
|
entries := []cache.HealthEntry{
|
|
{URL: "https://a", Category: "A > B"},
|
|
{URL: "https://b", Category: "A > C"},
|
|
}
|
|
roots := BuildTree(entries)
|
|
|
|
// Initially not expanded, should see just root
|
|
flat := FlattenVisible(roots)
|
|
if len(flat) != 1 {
|
|
t.Fatalf("expected 1 visible node (collapsed), got %d", len(flat))
|
|
}
|
|
if flat[0].Depth != 0 {
|
|
t.Errorf("expected depth 0, got %d", flat[0].Depth)
|
|
}
|
|
|
|
// Expand root
|
|
roots[0].Expanded = true
|
|
flat = FlattenVisible(roots)
|
|
if len(flat) != 3 {
|
|
t.Fatalf("expected 3 visible nodes (expanded), got %d", len(flat))
|
|
}
|
|
if flat[1].Depth != 1 {
|
|
t.Errorf("expected depth 1 for child, got %d", flat[1].Depth)
|
|
}
|
|
}
|
|
|
|
func TestAllEntries(t *testing.T) {
|
|
entries := []cache.HealthEntry{
|
|
{URL: "https://a", Category: "A > B"},
|
|
{URL: "https://b", Category: "A"},
|
|
}
|
|
roots := BuildTree(entries)
|
|
all := roots[0].AllEntries()
|
|
if len(all) != 2 {
|
|
t.Errorf("expected 2 entries from AllEntries, got %d", len(all))
|
|
}
|
|
}
|