forked from mtusi2026/mtusi2026lab4
89 lines
2.7 KiB
Go
89 lines
2.7 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab4/internal/config"
|
|
)
|
|
|
|
// TestMediaHTTPConfigurationFailure rejects invalid listener settings before serving files.
|
|
func TestMediaHTTPConfigurationFailure(t *testing.T) {
|
|
if _, err := newHTTPController(nil, &config.Controller{}, nil, nil, nil, nil, nil, nil); err == nil {
|
|
t.Fatal("invalid HTTP composition accepted")
|
|
}
|
|
}
|
|
|
|
// TestReconcileConfigurationFailures checks operator commands fail closed before side effects.
|
|
func TestReconcileConfigurationFailures(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
key string
|
|
value string
|
|
}{
|
|
{"database missing", "DATABASE_URL", ""},
|
|
{"s3 missing", "S3_ENDPOINT", ""},
|
|
{"database malformed", "DATABASE_URL", "://invalid"},
|
|
{"s3 malformed", "S3_ENDPOINT", "http://invalid/path"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Setenv("DATABASE_URL", "postgres://localhost/test")
|
|
t.Setenv("VALKEY_SHARDS", "shard0=localhost:6379")
|
|
t.Setenv("S3_ENDPOINT", "localhost:9000")
|
|
t.Setenv("S3_BUCKET", "attachments")
|
|
t.Setenv("S3_ACCESS_KEY", "test")
|
|
t.Setenv("S3_SECRET_KEY", "synthetic")
|
|
t.Setenv(tc.key, tc.value)
|
|
if err := run([]string{"reconcile"}); err == nil {
|
|
t.Fatal("invalid reconciliation configuration accepted")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestReconcileRealInventory verifies the operator command can scan both real dependencies.
|
|
func TestReconcileRealInventory(t *testing.T) {
|
|
requirePersistence(t)
|
|
if os.Getenv("S3_ENDPOINT") == "" {
|
|
t.Skip("isolated S3 required")
|
|
}
|
|
if err := run([]string{"reconcile"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := run([]string{"reconcile", "--apply"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// TestBootstrapConfigurationFailures rejects missing credentials and malformed endpoints.
|
|
func TestBootstrapConfigurationFailures(t *testing.T) {
|
|
t.Run("missing", func(t *testing.T) {
|
|
t.Setenv("S3_ENDPOINT", "")
|
|
if err := run([]string{"s3-bootstrap"}); err == nil {
|
|
t.Fatal("missing config accepted")
|
|
}
|
|
})
|
|
t.Run("malformed", func(t *testing.T) {
|
|
t.Setenv("S3_ENDPOINT", "http://invalid/path")
|
|
t.Setenv("S3_BUCKET", "attachments")
|
|
t.Setenv("S3_ACCESS_KEY", "test")
|
|
t.Setenv("S3_SECRET_KEY", "synthetic")
|
|
if err := run([]string{"s3-bootstrap"}); err == nil {
|
|
t.Fatal("malformed endpoint accepted")
|
|
}
|
|
})
|
|
}
|
|
|
|
// TestBootstrapExistingBucket verifies repeatable operator execution against the isolated bucket.
|
|
func TestBootstrapExistingBucket(t *testing.T) {
|
|
if os.Getenv("S3_ENDPOINT") == "" || os.Getenv("S3_ADMIN_SECRET") == "" {
|
|
t.Skip("isolated S3 operator credentials required")
|
|
}
|
|
t.Setenv("S3_ACCESS_KEY", "operator")
|
|
t.Setenv("S3_SECRET_KEY", os.Getenv("S3_ADMIN_SECRET"))
|
|
if err := run([]string{"s3-bootstrap"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|