test: add docstrings to rewritten tests and use t.Setenv

Addresses two CodeRabbit feedback items on PR #24:

* Docstring coverage warning (was 57.14%, threshold 80%): adds godoc
  comments to the four test functions added or substantially rewritten
  in this PR — TestLoadAndSaveManifest, TestAddAndRemoveFromManifest,
  TestFindInManifest, TestHighlightFileTokensInjectsANSI.
* Quick-win nitpick: replaces the manual os.Setenv/os.Unsetenv +
  defer pattern in TestFindInManifest with t.Setenv, which restores
  the env var automatically on cleanup even on panic or t.Fatal.

go test -race ./... still passes.
This commit is contained in:
Ed Zynda
2026-05-07 13:16:03 +03:00
parent d557f4b870
commit 2016570e2d
2 changed files with 14 additions and 8 deletions
+11 -8
View File
@@ -245,6 +245,9 @@ func TestManifestEntryIdentity(t *testing.T) {
}
}
// TestLoadAndSaveManifest exercises the live *Installer.loadManifest /
// saveManifest round-trip against a temp directory, ensuring an absent
// manifest loads as empty and a saved manifest reads back identically.
func TestLoadAndSaveManifest(t *testing.T) {
tempDir := t.TempDir()
installer := &Installer{
@@ -300,6 +303,9 @@ func TestLoadAndSaveManifest(t *testing.T) {
}
}
// TestAddAndRemoveFromManifest verifies that *Installer.addToManifest
// followed by removeFromManifest leaves the manifest in its original
// (empty) state, using a temp-directory installer scope.
func TestAddAndRemoveFromManifest(t *testing.T) {
tempDir := t.TempDir()
installer := &Installer{
@@ -343,16 +349,13 @@ func TestAddAndRemoveFromManifest(t *testing.T) {
}
}
// TestFindInManifest writes a manifest file directly to the path
// resolved by the package-level manifestPathForScope helper and then
// confirms FindInManifest locates the entry by identity (and returns
// nil for a non-existent identity).
func TestFindInManifest(t *testing.T) {
tempDir := t.TempDir()
if err := os.Setenv("XDG_DATA_HOME", tempDir); err != nil {
t.Fatalf("Setenv() error = %v", err)
}
defer func() {
if err := os.Unsetenv("XDG_DATA_HOME"); err != nil {
t.Logf("Unsetenv() error = %v", err)
}
}()
t.Setenv("XDG_DATA_HOME", tempDir)
// Write a manifest entry directly via the package-level path resolver
// so FindInManifest (which uses manifestPathForScope) can read it back.
+3
View File
@@ -67,6 +67,9 @@ func TestHighlightFileTokens(t *testing.T) {
}
}
// TestHighlightFileTokensInjectsANSI verifies that HighlightFileTokens
// preserves the original @file references in the output and wraps each
// token with ANSI escape codes for the theme accent color.
func TestHighlightFileTokensInjectsANSI(t *testing.T) {
theme := style.DefaultTheme()