refac: decouple persistence and image storage behind driver registries
This commit is contained in:
1 parent
421cfafec3
commit
81e299f09a
46 files changed
+1036
-374
No files matched your search
@@ -2,20 +2,15 @@ package test
|
||||
|
||||
import (
|
||||
imageDomain "RenewCMS/internal/domain/image"
|
||||
"RenewCMS/internal/infrastructure/persistence/models"
|
||||
persistence "RenewCMS/internal/infrastructure/persistence/repositories"
|
||||
"RenewCMS/internal/infrastructure/storage"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestImageRepositoryHasAnExtensionForEveryAllowedContentType(t *testing.T) {
|
||||
db := openInMemoryDb(t)
|
||||
if err := db.AutoMigrate(&models.Image{}); err != nil {
|
||||
t.Fatalf("failed to migrate: %v", err)
|
||||
}
|
||||
repo := persistence.NewImageRepository(db, t.TempDir())
|
||||
func TestLocalStorageHasAnExtensionForEveryAllowedContentType(t *testing.T) {
|
||||
store := storage.NewLocalStorage(t.TempDir())
|
||||
|
||||
allowedContentTypes := imageDomain.AllowedContentTypes()
|
||||
expectedContentTypes := []string{"image/jpeg", "image/png", "image/svg+xml", "image/webp"}
|
||||
@@ -25,17 +20,12 @@ func TestImageRepositoryHasAnExtensionForEveryAllowedContentType(t *testing.T) {
|
||||
|
||||
for _, contentType := range allowedContentTypes {
|
||||
t.Run(contentType, func(t *testing.T) {
|
||||
result, err := repo.Create(imageDomain.ImageInput{
|
||||
Content: strings.NewReader("fake-image-data"),
|
||||
Filename: "upload",
|
||||
ContentType: contentType,
|
||||
})
|
||||
storedName, err := store.Put(contentType, strings.NewReader("fake-image-data"))
|
||||
if err != nil {
|
||||
t.Fatalf("Create failed: %v", err)
|
||||
t.Fatalf("Put failed: %v", err)
|
||||
}
|
||||
extension := filepath.Ext(result.Path)
|
||||
if extension == "" {
|
||||
t.Errorf("expected a non-empty extension for %q, got path %q", contentType, result.Path)
|
||||
if filepath.Ext(storedName) == "" {
|
||||
t.Errorf("expected a non-empty extension for %q, got name %q", contentType, storedName)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user