48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
|
|
package handlers
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/juanatsap/cv-site/internal/cache"
|
||
|
|
"github.com/juanatsap/cv-site/internal/config"
|
||
|
|
"github.com/juanatsap/cv-site/internal/services"
|
||
|
|
"github.com/juanatsap/cv-site/internal/templates"
|
||
|
|
)
|
||
|
|
|
||
|
|
// testCache is a shared cache instance for all tests
|
||
|
|
var testCache *cache.DataCache
|
||
|
|
|
||
|
|
// getTestCache returns a shared cache instance, initializing it once
|
||
|
|
func getTestCache(t testing.TB) *cache.DataCache {
|
||
|
|
t.Helper()
|
||
|
|
if testCache != nil {
|
||
|
|
return testCache
|
||
|
|
}
|
||
|
|
|
||
|
|
var err error
|
||
|
|
testCache, err = cache.New([]string{"en", "es"})
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("Failed to create test cache: %v", err)
|
||
|
|
}
|
||
|
|
return testCache
|
||
|
|
}
|
||
|
|
|
||
|
|
// newTestCVHandler creates a CVHandler for testing with all required dependencies
|
||
|
|
func newTestCVHandler(t testing.TB, serverAddr string, emailService *services.EmailService) *CVHandler {
|
||
|
|
t.Helper()
|
||
|
|
|
||
|
|
cfg := &config.TemplateConfig{
|
||
|
|
Dir: "../../templates",
|
||
|
|
PartialsDir: "../../templates/partials",
|
||
|
|
HotReload: false,
|
||
|
|
}
|
||
|
|
tmplManager, err := templates.NewManager(cfg)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("Failed to create template manager: %v", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
dataCache := getTestCache(t)
|
||
|
|
|
||
|
|
return NewCVHandler(tmplManager, serverAddr, emailService, dataCache)
|
||
|
|
}
|