Skip to content

test(config): add folder_cache tests#1007

Merged
andrinoff merged 2 commits intofloatpane:masterfrom
mvanhorn:test/988-folder-cache-tests
Apr 26, 2026
Merged

test(config): add folder_cache tests#1007
andrinoff merged 2 commits intofloatpane:masterfrom
mvanhorn:test/988-folder-cache-tests

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented Apr 25, 2026

What?

Adds 9 tests covering config/folder_cache.go, which previously had no test coverage despite being on the critical path for every IMAP account list refresh:

  • Save/load round-trip (TestSaveLoadFolderCache_RoundTrip)
  • Cache invalidation: SaveAccountFolders overwrites the existing entry instead of appending (TestSaveAccountFolders_InvalidatesExistingEntry)
  • New-account append path (TestSaveAccountFolders_AddsNewAccount)
  • Corrupt cache file handling: LoadFolderCache returns an error, SaveAccountFolders silently recovers via the existing cache = &FolderCache{} fall-back (TestLoadFolderCache_CorruptFileReturnsError, TestSaveAccountFolders_RecoversFromCorruptCache)
  • Empty folder list handling: nil and []string{} both round-trip without losing the account entry (TestSaveFolderCache_EmptyAccounts, TestSaveAccountFolders_EmptyFolderList)
  • Lookup edge cases: missing account returns nil, no cache file returns nil (TestGetCachedFolders_MissingAccount, TestGetCachedFolders_NoCacheFile)

Each test isolates state via t.Setenv("HOME", t.TempDir()), the same pattern config_test.go already uses for SaveConfig.

Verified locally with go test ./config/ -count=1 (41 passed).

Why?

Closes #988. The folder cache code in config/folder_cache.go was on the critical path for every IMAP account list refresh but had no test coverage, leaving the four failure modes the issue called out (save/load round-trip, invalidation, corrupt files, empty folder lists) silently regressible.

Closes floatpane#988. The folder cache code in config/folder_cache.go had no
tests despite being on the critical path for every IMAP account list
refresh. Adds nine tests covering the four areas the issue called
out plus a couple of natural extensions:

- Save/load round-trip (TestSaveLoadFolderCache_RoundTrip)
- Cache invalidation: SaveAccountFolders overwrites the existing
  entry instead of appending (TestSaveAccountFolders_InvalidatesExistingEntry)
- New-account append path (TestSaveAccountFolders_AddsNewAccount)
- Corrupt cache file handling: LoadFolderCache returns an error,
  SaveAccountFolders silently recovers via the existing
  `cache = &FolderCache{}` fall-back
  (TestLoadFolderCache_CorruptFileReturnsError,
   TestSaveAccountFolders_RecoversFromCorruptCache)
- Empty folder list handling: nil and []string{} both round-trip
  without losing the account entry
  (TestSaveFolderCache_EmptyAccounts,
   TestSaveAccountFolders_EmptyFolderList)
- Lookup edge cases: missing account returns nil, no cache file
  returns nil (TestGetCachedFolders_MissingAccount,
  TestGetCachedFolders_NoCacheFile)

Each test isolates state via t.Setenv("HOME", t.TempDir()), the same
pattern config_test.go already uses for SaveConfig.

Verified locally with `go test ./config/ -count=1` (41 passed).
@mvanhorn mvanhorn requested a review from a team as a code owner April 25, 2026 11:41
Copy link
Copy Markdown
Member

@floatpanebot floatpanebot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mvanhorn! Please fix the following issues with your PR:

  • Title: Is too long (55 characters). The PR title must be strictly under 40 characters.
  • Body: Missing the ## What? or ## Why? headings required by the PR template.

@github-actions github-actions Bot added the bug Something isn't working label Apr 25, 2026
@mvanhorn mvanhorn changed the title test(config): add unit tests for folder_cache.go (#988) test(config): add folder_cache tests Apr 25, 2026
@floatpanebot floatpanebot dismissed their stale review April 25, 2026 15:30

Formatting issues have been resolved. Thank you!

@andrinoff
Copy link
Copy Markdown
Member

@mvanhorn your tests fail on windows

os.UserHomeDir() reads HOME on Linux/macOS but USERPROFILE on Windows.
The existing t.Setenv("HOME", ...) had no effect on windows-latest, so
every test resolved cacheDir() to the runner's real %USERPROFILE%, where
state leaked across tests in the package and produced the failures
seen on PR floatpane#1007's windows-latest job.
@mvanhorn
Copy link
Copy Markdown
Contributor Author

Fixed in 2a0818f. os.UserHomeDir() reads USERPROFILE on Windows, not HOME, so the test setup helper was a no-op there and cache state leaked across tests. Added t.Setenv("USERPROFILE", tempDir) alongside HOME.

windows-latest now passes: https://github.com/floatpane/matcha/actions/runs/24958810936/job/73081727124

@andrinoff
Copy link
Copy Markdown
Member

lgtm, thx for the fix

@andrinoff andrinoff merged commit 178a029 into floatpane:master Apr 26, 2026
12 checks passed
@mvanhorn
Copy link
Copy Markdown
Contributor Author

Thanks @andrinoff, glad the folder_cache test scaffolding looked right - happy to have coverage on that critical-path file before the next IMAP refactor lands.

@mvanhorn
Copy link
Copy Markdown
Contributor Author

Appreciate the merge @andrinoff. folder_cache sits on every IMAP refresh and had zero tests, so 9 cases covering round-trip and corruption paths takes a real hot path off the cliff edge.

@mvanhorn
Copy link
Copy Markdown
Contributor Author

Thanks for the merge @andrinoff! The nine folder_cache tests cover round-trip, invalidation, and corrupt-file paths nicely.

@mvanhorn
Copy link
Copy Markdown
Contributor Author

mvanhorn commented May 2, 2026

Really appreciate this one @andrinoff. folder_cache.go was on the critical path with no coverage, so the round-trip and edge-case tests fill an important gap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEAT: Add unit tests for config/folder_cache.go

3 participants