Перенести актуальную lab2 как базу lab3
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.uber.org/fx"
|
||||
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab3/internal/config"
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab3/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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user