Backend Go: - Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN. - Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError). - Sécurisation de config.go, CORS, statuts de santé et monitoring. - Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles). - Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés. - Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*. Chat server (Rust): - Refonte du pipeline JWT + sécurité, audit et rate limiting avancé. - Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing). - Nettoyage des panics, gestion d’erreurs robuste, logs structurés. - Migrations chat alignées sur le schéma UUID et nouvelles features. Stream server (Rust): - Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core. - Transactions P0 pour les jobs et segments, garanties d’atomicité. - Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION). Documentation & audits: - TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services. - Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3). - Scripts de reset et de cleanup pour la lab DB et la V1. Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
101 lines
2.8 KiB
Go
101 lines
2.8 KiB
Go
package workers
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/disintegration/imaging"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func TestThumbnailJob_Execute(t *testing.T) {
|
|
logger := zap.NewNop()
|
|
ctx := context.Background()
|
|
|
|
// Créer un répertoire temporaire pour les tests
|
|
tmpDir := t.TempDir()
|
|
|
|
// Créer une image de test simple (1x1 pixel PNG)
|
|
testImagePath := filepath.Join(tmpDir, "test.png")
|
|
testThumbnailPath := filepath.Join(tmpDir, "test_thumb.jpg")
|
|
|
|
// Créer une image de test avec imaging (image rouge 100x100)
|
|
img := imaging.New(100, 100, imaging.Color{255, 0, 0, 255})
|
|
if err := imaging.Save(img, testImagePath); err != nil {
|
|
t.Fatalf("Failed to create test image: %v", err)
|
|
}
|
|
|
|
// Test 1: Génération de thumbnail normale
|
|
t.Run("Generate thumbnail successfully", func(t *testing.T) {
|
|
job := NewThumbnailJob(testImagePath, testThumbnailPath, 50, 50)
|
|
|
|
err := job.Execute(ctx, logger)
|
|
if err != nil {
|
|
t.Fatalf("Expected no error, got: %v", err)
|
|
}
|
|
|
|
// Vérifier que le thumbnail existe
|
|
if _, err := os.Stat(testThumbnailPath); os.IsNotExist(err) {
|
|
t.Fatal("Thumbnail file was not created")
|
|
}
|
|
})
|
|
|
|
// Test 2: Fichier source inexistant
|
|
t.Run("Fail when input file does not exist", func(t *testing.T) {
|
|
job := NewThumbnailJob("/nonexistent/image.png", testThumbnailPath, 50, 50)
|
|
|
|
err := job.Execute(ctx, logger)
|
|
if err == nil {
|
|
t.Fatal("Expected error for nonexistent file, got nil")
|
|
}
|
|
})
|
|
|
|
// Test 3: Valeurs par défaut
|
|
t.Run("Use default dimensions when not specified", func(t *testing.T) {
|
|
thumbPath2 := filepath.Join(tmpDir, "test_thumb2.jpg")
|
|
job := NewThumbnailJob(testImagePath, thumbPath2, 0, 0)
|
|
|
|
// Vérifier que les valeurs par défaut sont appliquées
|
|
if job.Width != 300 || job.Height != 300 {
|
|
t.Errorf("Expected default dimensions 300x300, got %dx%d", job.Width, job.Height)
|
|
}
|
|
|
|
err := job.Execute(ctx, logger)
|
|
if err != nil {
|
|
t.Fatalf("Expected no error, got: %v", err)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestNewThumbnailJob(t *testing.T) {
|
|
t.Run("Create job with specified dimensions", func(t *testing.T) {
|
|
job := NewThumbnailJob("input.jpg", "output.jpg", 200, 150)
|
|
|
|
if job.InputPath != "input.jpg" {
|
|
t.Errorf("Expected InputPath 'input.jpg', got '%s'", job.InputPath)
|
|
}
|
|
if job.OutputPath != "output.jpg" {
|
|
t.Errorf("Expected OutputPath 'output.jpg', got '%s'", job.OutputPath)
|
|
}
|
|
if job.Width != 200 {
|
|
t.Errorf("Expected Width 200, got %d", job.Width)
|
|
}
|
|
if job.Height != 150 {
|
|
t.Errorf("Expected Height 150, got %d", job.Height)
|
|
}
|
|
})
|
|
|
|
t.Run("Apply default dimensions when zero", func(t *testing.T) {
|
|
job := NewThumbnailJob("input.jpg", "output.jpg", 0, 0)
|
|
|
|
if job.Width != 300 {
|
|
t.Errorf("Expected default Width 300, got %d", job.Width)
|
|
}
|
|
if job.Height != 300 {
|
|
t.Errorf("Expected default Height 300, got %d", job.Height)
|
|
}
|
|
})
|
|
}
|
|
|