forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"go.uber.org/fx"
|
||||
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/config"
|
||||
)
|
||||
|
||||
// TestWorkerLifecycle starts and joins the real worker without exposing an HTTP listener.
|
||||
func TestWorkerLifecycle(t *testing.T) {
|
||||
requirePersistence(t)
|
||||
if os.Getenv("BROKER_ADDRESS") == "" || os.Getenv("S3_ENDPOINT") == "" {
|
||||
t.Skip("isolated broker and S3 required")
|
||||
}
|
||||
app := fx.New(workerApp())
|
||||
if err := app.Start(t.Context()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
if err := app.Stop(t.Context()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestQueueProviderRejectsMissingAddress propagates configuration failure before startup.
|
||||
func TestQueueProviderRejectsMissingAddress(t *testing.T) {
|
||||
var lc fx.Lifecycle
|
||||
app := fx.New(fx.NopLogger, fx.Populate(&lc))
|
||||
if err := app.Err(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := newQueue(lc, &config.Worker{}); err == nil {
|
||||
t.Fatal("missing broker accepted")
|
||||
}
|
||||
}
|
||||
|
||||
// TestReplayCommandRejectsInvalidInput prevents unintended operator transitions.
|
||||
func TestReplayCommandRejectsInvalidInput(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
id string
|
||||
version string
|
||||
}{{"invalid ID", "invalid", "1"}, {"invalid version", uuid.NewString(), "x"}, {"negative version", uuid.NewString(), "-1"}} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if err := run([]string{"replay", tc.id, tc.version}); err == nil {
|
||||
t.Fatal("invalid operator input accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestReplayCommandConfiguration checks failure before database access.
|
||||
func TestReplayCommandConfiguration(t *testing.T) {
|
||||
t.Run("missing", func(t *testing.T) {
|
||||
t.Setenv("DATABASE_URL", "")
|
||||
if err := replayJob(uuid.NewString(), "1"); err == nil {
|
||||
t.Fatal("missing database accepted")
|
||||
}
|
||||
})
|
||||
t.Run("malformed", func(t *testing.T) {
|
||||
t.Setenv("DATABASE_URL", "://invalid")
|
||||
t.Setenv("VALKEY_SHARDS", "shard0=localhost:6379")
|
||||
if err := replayJob(uuid.NewString(), "1"); err == nil {
|
||||
t.Fatal("malformed database accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestReplayUnknownAttachment verifies safe operator failure against the actual schema.
|
||||
func TestReplayUnknownAttachment(t *testing.T) {
|
||||
requirePersistence(t)
|
||||
if err := replayJob(uuid.NewString(), "1"); err == nil {
|
||||
t.Fatal("unknown attachment replayed")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user