test(config): add folder_cache tests#1007
Conversation
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).
floatpanebot
left a comment
There was a problem hiding this comment.
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.
Formatting issues have been resolved. Thank you!
|
@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.
|
Fixed in 2a0818f. windows-latest now passes: https://github.com/floatpane/matcha/actions/runs/24958810936/job/73081727124 |
|
lgtm, thx for the fix |
|
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. |
|
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. |
|
Thanks for the merge @andrinoff! The nine folder_cache tests cover round-trip, invalidation, and corrupt-file paths nicely. |
|
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. |
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:TestSaveLoadFolderCache_RoundTrip)SaveAccountFoldersoverwrites the existing entry instead of appending (TestSaveAccountFolders_InvalidatesExistingEntry)TestSaveAccountFolders_AddsNewAccount)LoadFolderCachereturns an error,SaveAccountFolderssilently recovers via the existingcache = &FolderCache{}fall-back (TestLoadFolderCache_CorruptFileReturnsError,TestSaveAccountFolders_RecoversFromCorruptCache)[]string{}both round-trip without losing the account entry (TestSaveFolderCache_EmptyAccounts,TestSaveAccountFolders_EmptyFolderList)TestGetCachedFolders_MissingAccount,TestGetCachedFolders_NoCacheFile)Each test isolates state via
t.Setenv("HOME", t.TempDir()), the same patternconfig_test.goalready uses forSaveConfig.Verified locally with
go test ./config/ -count=1(41 passed).Why?
Closes #988. The folder cache code in
config/folder_cache.gowas 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.