fix test home on windows

This commit is contained in:
Bruce MacDonald
2026-02-18 18:37:24 -08:00
parent 71c1d8d0a9
commit 365a3657ad

View File

@@ -7,10 +7,20 @@ import (
"net/url"
"os"
"path/filepath"
"runtime"
"testing"
"time"
)
func setHome(t *testing.T, dir string) {
t.Helper()
if runtime.GOOS == "windows" {
t.Setenv("USERPROFILE", dir)
} else {
t.Setenv("HOME", dir)
}
}
func TestCheckForUpdate(t *testing.T) {
t.Run("update available", func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -70,7 +80,7 @@ func TestCheckForUpdate(t *testing.T) {
func TestCacheRoundTrip(t *testing.T) {
tmp := t.TempDir()
t.Setenv("HOME", tmp)
setHome(t, tmp)
os.MkdirAll(filepath.Join(tmp, ".ollama"), 0o755)
if err := CacheAvailableUpdate(); err != nil {
@@ -92,7 +102,7 @@ func TestCacheRoundTrip(t *testing.T) {
func TestHasCachedUpdateStale(t *testing.T) {
tmp := t.TempDir()
t.Setenv("HOME", tmp)
setHome(t, tmp)
os.MkdirAll(filepath.Join(tmp, ".ollama"), 0o755)
if err := CacheAvailableUpdate(); err != nil {