(t *testing.T)
| 193 | } |
| 194 | |
| 195 | func TestPrepareRecordingArtifact(t *testing.T) { |
| 196 | t.Parallel() |
| 197 | |
| 198 | t.Run("MP4", func(t *testing.T) { |
| 199 | t.Parallel() |
| 200 | |
| 201 | name, mediaType, err := chatfiles.PrepareRecordingArtifact( |
| 202 | "recording.mp4", |
| 203 | "video/mp4", |
| 204 | []byte{0x00, 0x00, 0x00, 0x18, 'f', 't', 'y', 'p', 'm', 'p', '4', '2', 0x00, 0x00, 0x00, 0x00, 'm', 'p', '4', '1', 'i', 's', 'o', 'm'}, |
| 205 | ) |
| 206 | require.NoError(t, err) |
| 207 | require.Equal(t, "recording.mp4", name) |
| 208 | require.Equal(t, "video/mp4", mediaType) |
| 209 | }) |
| 210 | |
| 211 | t.Run("JPEG", func(t *testing.T) { |
| 212 | t.Parallel() |
| 213 | |
| 214 | name, mediaType, err := chatfiles.PrepareRecordingArtifact( |
| 215 | "thumbnail.jpg", |
| 216 | "image/jpeg", |
| 217 | []byte{0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 'J', 'F', 'I', 'F', 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00}, |
| 218 | ) |
| 219 | require.NoError(t, err) |
| 220 | require.Equal(t, "thumbnail.jpg", name) |
| 221 | require.Equal(t, "image/jpeg", mediaType) |
| 222 | }) |
| 223 | |
| 224 | t.Run("TypeMismatch", func(t *testing.T) { |
| 225 | t.Parallel() |
| 226 | |
| 227 | _, _, err := chatfiles.PrepareRecordingArtifact( |
| 228 | "recording.mp4", |
| 229 | "video/mp4", |
| 230 | []byte{0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 'J', 'F', 'I', 'F', 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00}, |
| 231 | ) |
| 232 | require.ErrorContains(t, err, "recording artifact type mismatch") |
| 233 | }) |
| 234 | |
| 235 | t.Run("RejectsEmptyNormalizedName", func(t *testing.T) { |
| 236 | t.Parallel() |
| 237 | |
| 238 | _, _, err := chatfiles.PrepareRecordingArtifact( |
| 239 | " \r\n\t ", |
| 240 | "video/mp4", |
| 241 | []byte{0x00, 0x00, 0x00, 0x18, 'f', 't', 'y', 'p', 'm', 'p', '4', '2', 0x00, 0x00, 0x00, 0x00, 'm', 'p', '4', '1', 'i', 's', 'o', 'm'}, |
| 242 | ) |
| 243 | require.ErrorIs(t, err, chatfiles.ErrStoredFileNameRequired) |
| 244 | }) |
| 245 | |
| 246 | t.Run("UnsupportedExpectedType", func(t *testing.T) { |
| 247 | t.Parallel() |
| 248 | |
| 249 | _, _, err := chatfiles.PrepareRecordingArtifact( |
| 250 | "recording.webm", |
| 251 | "video/webm", |
| 252 | []byte("webm"), |
nothing calls this directly
no test coverage detected