generated from VLADIMIR/template
fix
This commit is contained in:
@@ -20,6 +20,8 @@ var (
|
||||
ErrInvalidExtension = errors.New("недопустимое расширение файла (разрешены pdf, jpg, jpeg, png, gif, webp, mp3, ogg, wav, mp4, webm)")
|
||||
ErrInvalidContentType = errors.New("содержимое файла не соответствует разрешённым типам (pdf, изображения, аудио или видео)")
|
||||
ErrFileTooLarge = errors.New("файл слишком большой")
|
||||
// ErrFileNotFound — файл отсутствует в хранилище.
|
||||
ErrFileNotFound = errors.New("файл не найден")
|
||||
)
|
||||
|
||||
// allowedExtensions — расширения, разрешённые для загрузки: PDF, изображения
|
||||
@@ -152,6 +154,9 @@ func (s *FileService) DownloadFile(
|
||||
) (*file_storage.File, error) {
|
||||
file, err := s.fileStorage.Get(ctx, filename)
|
||||
if err != nil {
|
||||
if errors.Is(err, file_storage.ErrFileNotFound) {
|
||||
return nil, ErrFileNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return file, nil
|
||||
|
||||
@@ -155,6 +155,14 @@ func TestUploadFileTooLarge(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDownloadFileNotFound(t *testing.T) {
|
||||
svc := newService(1 << 20)
|
||||
_, err := svc.DownloadFile(context.Background(), "missing.pdf")
|
||||
if !errors.Is(err, ErrFileNotFound) {
|
||||
t.Fatalf("err = %v, want ErrFileNotFound", err)
|
||||
}
|
||||
}
|
||||
|
||||
func bytes1024() []byte {
|
||||
b := make([]byte, 1024)
|
||||
copy(b, "%PDF-1.7 ")
|
||||
|
||||
Reference in New Issue
Block a user