Files
lazysecrets/internal/ui/app/usage_test.go
T
keb fae8e1cbb4 refactor: drop dead code and use the standard library where it already does the job (#76)
No behaviour change.

- Deleted, unused or one-line wrappers: panes.RuneIndexes, Detail.Refresh (SetDescribed does it), SecretValue.Len, Query.Empty, Clipboard.Native, config.Load, get's value, Model.done, providerOf (cachefile.ProviderOf), contextWithTimeout, searchCoverage, startCrawl, showKeybindings, the expiry aliases and daysLeft.
- cmp.Or instead of the two cmpOr copies; slices.Sorted(maps.Keys(…)), maps.Copy, wg.Go, utf8.RuneCountInString and new(true) instead of loops and helpers that do the same.
- A container's pane title is set once, not twice; a redundant length check in share links and a no-op assignment in linkhandler.Launch are gone.
- Tests call ansi.Strip and lastLines directly; gofmt -s on links.go.

Reviewed-on: #76
Co-authored-by: Karl-Einar Bergstrøm <karl-einarb@outlook.com>
2026-10-15 10:39:38 +02:00

49 lines
1.4 KiB
Go

package app
import (
"strings"
"testing"
"git.kebcloud.no/keb/lazysecrets/internal/store"
"github.com/charmbracelet/x/ansi"
)
func TestRecentScope(t *testing.T) {
t.Parallel()
d := newDriver(t)
d.keys("3", "j", "space") // reveal api-key
d.keys("j", "s") // share legacy-token: a use too
d.keys("2", "j", "f") // star kv-shared-prod
key := "lazysecrets://azure/kv-app-prod.vault.azure.net/secrets/api-key"
if n := d.m.store.Node(key); n.Uses != 1 || n.LastUsed.IsZero() || n.Name != "api-key" {
t.Fatalf("reveal not counted: %+v", n)
}
d.keys("R")
var recent []string
for _, o := range d.m.search.shown {
recent = append(recent, ansi.Strip(o.label))
}
if len(recent) < 2 || !strings.Contains(recent[0], "legacy-token") || !strings.Contains(recent[1], "api-key") {
t.Fatalf("want newest first: %q", recent)
}
d.keys("enter") // jump to legacy-token
if _, _, s := d.selected(); s != "legacy-token" {
t.Errorf("jumped to %q", s)
}
d.keys("F")
if len(d.m.search.shown) != 1 || !strings.Contains(ansi.Strip(d.m.search.shown[0].label), "kv-shared-prod") {
t.Errorf("favourites: %d entries\n%s", len(d.m.search.shown), d.screen())
}
}
func TestNoHistory(t *testing.T) {
t.Parallel()
mem, _ := store.Load("")
d := newDriverOpts(t, Options{Store: mem, NoHistory: true})
d.keys("3", "j", "space", "y")
if len(mem.Nodes()) != 0 {
t.Errorf("recorded with history off: %v", mem.Nodes())
}
}