(t *testing.T)
| 262 | } |
| 263 | |
| 264 | func TestValidateImageFile(t *testing.T) { |
| 265 | t.Run("Empty path should be valid", func(t *testing.T) { |
| 266 | err := validateImageFile("") |
| 267 | assert.NoError(t, err) |
| 268 | }) |
| 269 | |
| 270 | t.Run("Valid extensions should pass", func(t *testing.T) { |
| 271 | validExtensions := []string{".png", ".jpeg", ".jpg", ".webp"} |
| 272 | for _, ext := range validExtensions { |
| 273 | filename := filepath.Join(t.TempDir(), "test"+ext) |
| 274 | err := validateImageFile(filename) |
| 275 | assert.NoError(t, err, "Extension %s should be valid", ext) |
| 276 | } |
| 277 | }) |
| 278 | |
| 279 | t.Run("Invalid extensions should fail", func(t *testing.T) { |
| 280 | invalidExtensions := []string{".gif", ".bmp", ".tiff", ".svg", ".txt", ""} |
| 281 | for _, ext := range invalidExtensions { |
| 282 | filename := filepath.Join(t.TempDir(), "test"+ext) |
| 283 | err := validateImageFile(filename) |
| 284 | assert.Error(t, err, "Extension %s should be invalid", ext) |
| 285 | assert.Contains(t, err.Error(), "invalid image file extension") |
| 286 | } |
| 287 | }) |
| 288 | |
| 289 | t.Run("Existing file should fail", func(t *testing.T) { |
| 290 | tempFile, err := os.CreateTemp("", "test*.png") |
| 291 | assert.NoError(t, err) |
| 292 | defer os.Remove(tempFile.Name()) |
| 293 | tempFile.Close() |
| 294 | |
| 295 | err = validateImageFile(tempFile.Name()) |
| 296 | assert.Error(t, err) |
| 297 | assert.Contains(t, err.Error(), "image file already exists") |
| 298 | }) |
| 299 | |
| 300 | t.Run("Non-existing file with valid extension should pass", func(t *testing.T) { |
| 301 | nonExistentFile := filepath.Join(os.TempDir(), "non_existent_file.png") |
| 302 | // Remove a leftover from an earlier run. |
| 303 | os.Remove(nonExistentFile) |
| 304 | |
| 305 | err := validateImageFile(nonExistentFile) |
| 306 | assert.NoError(t, err) |
| 307 | }) |
| 308 | } |
| 309 | |
| 310 | func TestBuildChatOptionsWithImageFileValidation(t *testing.T) { |
| 311 | dir := t.TempDir() |
nothing calls this directly
no test coverage detected