diff --git a/auth/signin_flow_test.go b/auth/signin_flow_test.go index c3fc59d0b..a201b4524 100644 --- a/auth/signin_flow_test.go +++ b/auth/signin_flow_test.go @@ -3,6 +3,7 @@ package auth import ( "os" "path/filepath" + "runtime" "testing" ) @@ -267,19 +268,27 @@ func TestConcurrentAccess(t *testing.T) { // TestFileSystemEdgeCases tests filesystem-related edge cases func TestFileSystemEdgeCases(t *testing.T) { - tmpDir := setupTestDir(t) + t.Run("DirectoryIsFile", func(t *testing.T) { + tmpDir := t.TempDir() - t.Run("ReadOnlyDirectory", func(t *testing.T) { - // Make .ollama directory read-only - ollamaDir := filepath.Join(tmpDir, ".ollama") - os.Chmod(ollamaDir, 0o500) - defer os.Chmod(ollamaDir, 0o755) // Restore for cleanup + // Create a file where .ollama directory should be + ollamaPath := filepath.Join(tmpDir, ".ollama") + if err := os.WriteFile(ollamaPath, []byte("not a directory"), 0o600); err != nil { + t.Fatalf("failed to create blocking file: %v", err) + } - // Try to write - should fail because can't create temp file + // Override home directory + if runtime.GOOS == "windows" { + t.Setenv("USERPROFILE", tmpDir) + } else { + t.Setenv("HOME", tmpDir) + } + + // Try to write - should fail because .ollama is a file, not a directory state := &SignInState{Name: "newuser", Email: "new@example.com"} err := SetSignInState(state) if err == nil { - t.Error("should fail to write in read-only directory") + t.Error("should fail when .ollama is a file instead of directory") } }) } diff --git a/auth/signin_state_test.go b/auth/signin_state_test.go index dd20972d7..5264c48f7 100644 --- a/auth/signin_state_test.go +++ b/auth/signin_state_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "os" "path/filepath" + "runtime" "testing" "time" ) @@ -20,8 +21,12 @@ func setupTestDir(t *testing.T) string { t.Fatalf("failed to create .ollama dir: %v", err) } - // Override home directory for tests - t.Setenv("HOME", tmpDir) + // Override home directory for tests (platform-specific) + if runtime.GOOS == "windows" { + t.Setenv("USERPROFILE", tmpDir) + } else { + t.Setenv("HOME", tmpDir) + } return tmpDir }