fix(daemon): use correct systemd user target and isolate test cache
This commit is contained in:
parent
6f81a2f3ea
commit
4cf07c411c
3 changed files with 24 additions and 7 deletions
|
|
@ -316,6 +316,16 @@ func swapHTTPClient(c *http.Client) func() {
|
|||
return func() { httpClient = orig }
|
||||
}
|
||||
|
||||
// swapCacheDir redirects the version cache to a temp directory to avoid
|
||||
// polluting the real ~/.local/share/unarr/latest-version.json during tests.
|
||||
func swapCacheDir(t *testing.T) func() {
|
||||
t.Helper()
|
||||
tmpDir := t.TempDir()
|
||||
orig := cacheFilePathFn
|
||||
cacheFilePathFn = func() string { return filepath.Join(tmpDir, "latest-version.json") }
|
||||
return func() { cacheFilePathFn = orig }
|
||||
}
|
||||
|
||||
// rewriteTransport redirects all requests to the given base URL,
|
||||
// preserving path and query.
|
||||
type rewriteTransport struct {
|
||||
|
|
@ -563,6 +573,10 @@ func TestFetchLatestVersionWithHTTPTest(t *testing.T) {
|
|||
})
|
||||
defer restore()
|
||||
|
||||
// Redirect cache to temp dir so tests don't pollute the real cache
|
||||
restoreCache := swapCacheDir(t)
|
||||
defer restoreCache()
|
||||
|
||||
ver, err := CheckLatest(context.Background())
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue