-
-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: handle remove log file errors properly
- Loading branch information
1 parent
a8824c0
commit 953518e
Showing
2 changed files
with
63 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package ollama | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRun_localWithCustomLogFileError(t *testing.T) { | ||
t.Run("terminate/close-log-error", func(t *testing.T) { | ||
// Create a temporary file for testing | ||
f, err := os.CreateTemp(t.TempDir(), "test-log-*") | ||
require.NoError(t, err) | ||
|
||
// Close the file before termination to force a "file already closed" error | ||
err = f.Close() | ||
require.NoError(t, err) | ||
|
||
c := &OllamaContainer{ | ||
localCtx: &localContext{ | ||
logFile: f, | ||
}, | ||
} | ||
err = c.Terminate(context.Background()) | ||
require.Error(t, err) | ||
require.ErrorContains(t, err, "close log:") | ||
}) | ||
|
||
t.Run("terminate/log-file-not-removable", func(t *testing.T) { | ||
// Create a temporary file for testing | ||
f, err := os.CreateTemp(t.TempDir(), "test-log-*") | ||
require.NoError(t, err) | ||
defer func() { | ||
// Cleanup: restore permissions | ||
os.Chmod(filepath.Dir(f.Name()), 0700) | ||
}() | ||
|
||
// Make the file read-only and its parent directory read-only | ||
// This should cause removal to fail on most systems | ||
dir := filepath.Dir(f.Name()) | ||
require.NoError(t, os.Chmod(dir, 0500)) | ||
|
||
c := &OllamaContainer{ | ||
localCtx: &localContext{ | ||
logFile: f, | ||
}, | ||
} | ||
err = c.Terminate(context.Background()) | ||
require.Error(t, err) | ||
require.ErrorContains(t, err, "remove log:") | ||
}) | ||
} |