(t *testing.T)
| 191 | } |
| 192 | |
| 193 | func TestValidateImageFile(t *testing.T) { |
| 194 | t.Run("Empty path should be valid", func(t *testing.T) { |
| 195 | err := validateImageFile("") |
| 196 | assert.NoError(t, err) |
| 197 | }) |
| 198 | |
| 199 | t.Run("Valid extensions should pass", func(t *testing.T) { |
| 200 | validExtensions := []string{".png", ".jpeg", ".jpg", ".webp"} |
| 201 | for _, ext := range validExtensions { |
| 202 | filename := "/tmp/test" + ext |
| 203 | err := validateImageFile(filename) |
| 204 | assert.NoError(t, err, "Extension %s should be valid", ext) |
| 205 | } |
| 206 | }) |
| 207 | |
| 208 | t.Run("Invalid extensions should fail", func(t *testing.T) { |
| 209 | invalidExtensions := []string{".gif", ".bmp", ".tiff", ".svg", ".txt", ""} |
| 210 | for _, ext := range invalidExtensions { |
| 211 | filename := "/tmp/test" + ext |
| 212 | err := validateImageFile(filename) |
| 213 | assert.Error(t, err, "Extension %s should be invalid", ext) |
| 214 | assert.Contains(t, err.Error(), "invalid image file extension") |
| 215 | } |
| 216 | }) |
| 217 | |
| 218 | t.Run("Existing file should fail", func(t *testing.T) { |
| 219 | // Create a temporary file |
| 220 | tempFile, err := os.CreateTemp("", "test*.png") |
| 221 | assert.NoError(t, err) |
| 222 | defer os.Remove(tempFile.Name()) |
| 223 | tempFile.Close() |
| 224 | |
| 225 | // Validation should fail because file exists |
| 226 | err = validateImageFile(tempFile.Name()) |
| 227 | assert.Error(t, err) |
| 228 | assert.Contains(t, err.Error(), "image file already exists") |
| 229 | }) |
| 230 | |
| 231 | t.Run("Non-existing file with valid extension should pass", func(t *testing.T) { |
| 232 | nonExistentFile := filepath.Join(os.TempDir(), "non_existent_file.png") |
| 233 | // Make sure the file doesn't exist |
| 234 | os.Remove(nonExistentFile) |
| 235 | |
| 236 | err := validateImageFile(nonExistentFile) |
| 237 | assert.NoError(t, err) |
| 238 | }) |
| 239 | } |
| 240 | |
| 241 | func TestBuildChatOptionsWithImageFileValidation(t *testing.T) { |
| 242 | t.Run("Valid image file should pass", func(t *testing.T) { |
nothing calls this directly
no test coverage detected