forked from mtusi2026/mtusi2026lab2
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"go.uber.org/fx"
|
|
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab2/internal/config"
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab2/internal/store/postgres"
|
|
)
|
|
|
|
// TestDatabaseProviderRejectsInvalidConfiguration verifies dependency errors propagate before startup.
|
|
func TestDatabaseProviderRejectsInvalidConfiguration(t *testing.T) {
|
|
var lifecycle fx.Lifecycle
|
|
app := fx.New(fx.NopLogger, fx.Populate(&lifecycle))
|
|
if err := app.Err(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := newDatabase(lifecycle, &config.Persistence{}); err == nil {
|
|
t.Fatal("invalid database settings accepted")
|
|
}
|
|
}
|
|
|
|
// TestValkeyProviderRejectsInvalidConfiguration verifies the cache constructor is a real boundary.
|
|
func TestValkeyProviderRejectsInvalidConfiguration(t *testing.T) {
|
|
var lifecycle fx.Lifecycle
|
|
app := fx.New(fx.NopLogger, fx.Populate(&lifecycle))
|
|
if err := app.Err(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := newValkey(lifecycle, &config.Persistence{}); err == nil {
|
|
t.Fatal("invalid cache settings accepted")
|
|
}
|
|
}
|
|
|
|
// TestReadinessStopsAtUnavailableDatabase checks that mandatory persistence failure is visible.
|
|
func TestReadinessStopsAtUnavailableDatabase(t *testing.T) {
|
|
database, err := postgres.New(postgres.Options{URL: "postgres://localhost/test", MaxConnections: 1, Timeout: time.Second})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
database.Close()
|
|
readiness := newReadiness(database, nil)
|
|
if err := readiness.Ping(t.Context()); err == nil {
|
|
t.Fatal("closed database reported ready")
|
|
}
|
|
}
|