feat(deploy): bootstrap compose managed postgres stack
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDobotAIDingTalkContainerAssetsProvideSafeShortOperatorCommands(t *testing.T) {
|
||||
func TestDobotAIDingTalkComposeOwnsApplicationAndPostgres(t *testing.T) {
|
||||
compose, err := os.ReadFile("../deploy/dobotai-dingtalk/compose.yaml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -14,7 +14,13 @@ func TestDobotAIDingTalkContainerAssetsProvideSafeShortOperatorCommands(t *testi
|
||||
for _, required := range []string{
|
||||
"dobotai-dingtalk:",
|
||||
"container_name: dobotai-dingtalk",
|
||||
"network_mode: host",
|
||||
"dobotai-postgres:",
|
||||
"container_name: dobotai-postgres",
|
||||
"dobotai-postgres-data:",
|
||||
"depends_on:",
|
||||
"condition: service_healthy",
|
||||
"host.docker.internal:host-gateway",
|
||||
"127.0.0.1:8090:8090",
|
||||
"env_file:",
|
||||
"read_only: true",
|
||||
"/var/lib/dobotai/secrets",
|
||||
@@ -30,7 +36,6 @@ func TestDobotAIDingTalkContainerAssetsProvideSafeShortOperatorCommands(t *testi
|
||||
}
|
||||
for _, required := range []string{
|
||||
"configure_env.py",
|
||||
"/etc/dobotai-test/dobotai.env",
|
||||
"dobotai-dingtalk-start",
|
||||
} {
|
||||
if !strings.Contains(string(configure), required) {
|
||||
@@ -83,8 +88,7 @@ func TestDobotAIDingTalkCredentialConfigurationExplainsEveryInputWithRedactedExa
|
||||
t.Fatal("configuration guidance must label every example")
|
||||
}
|
||||
for _, example := range []string{
|
||||
"postgres://USER:<数据库密码>@127.0.0.1:55432/dobotai_test?sslmode=disable",
|
||||
"http://127.0.0.1:8080",
|
||||
"http://host.docker.internal:8080",
|
||||
`{"dingtalk:*":"你的Agent ID"}`,
|
||||
"DINGTALK_CLIENT_SECRET",
|
||||
} {
|
||||
@@ -95,6 +99,12 @@ func TestDobotAIDingTalkCredentialConfigurationExplainsEveryInputWithRedactedExa
|
||||
t.Errorf("documentation missing redacted example %q", example)
|
||||
}
|
||||
}
|
||||
if strings.Contains(string(configurator), "DATABASE_URL") {
|
||||
t.Fatal("database URL must be deployment-managed, not requested interactively")
|
||||
}
|
||||
if !strings.Contains(string(documentation), "dobotai-postgres") {
|
||||
t.Fatal("documentation must explain the Compose-managed database")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDobotAIDingTalkStartRollsBackToPreviousContainerImage(t *testing.T) {
|
||||
@@ -108,10 +118,56 @@ func TestDobotAIDingTalkStartRollsBackToPreviousContainerImage(t *testing.T) {
|
||||
"set_runtime_image",
|
||||
"docker inspect --format",
|
||||
"set_runtime_image \"$previous_image\"",
|
||||
"docker compose --env-file \"$runtime_env\" -f \"$compose_file\" up -d --no-build --force-recreate",
|
||||
"\"${compose[@]}\" up -d --no-build --force-recreate dobotai-dingtalk",
|
||||
} {
|
||||
if !strings.Contains(source, required) {
|
||||
t.Errorf("start script missing container upgrade rollback %q", required)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDobotAIDingTalkDockerInstallerPreparesDirectoriesDatabaseAndMigrations(t *testing.T) {
|
||||
data, err := os.ReadFile("../deploy/dobotai-dingtalk/install-docker.sh")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := string(data)
|
||||
for _, required := range []string{
|
||||
"container",
|
||||
"secrets",
|
||||
"backups",
|
||||
"migrations",
|
||||
"postgres.env",
|
||||
"dobotai-postgres",
|
||||
"apply-migrations.sh",
|
||||
"docker compose",
|
||||
"umask 077",
|
||||
} {
|
||||
if !strings.Contains(source, required) {
|
||||
t.Errorf("docker installer missing %q", required)
|
||||
}
|
||||
}
|
||||
if strings.Contains(source, "dobotai-dingtalk up -d") {
|
||||
t.Fatal("installer must prepare database but must not start the unconfigured application")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDobotAIDingTalkExistingDatabaseMigrationHasBackupAndRollbackBoundary(t *testing.T) {
|
||||
data, err := os.ReadFile("../deploy/dobotai-dingtalk/migrate-existing-database.sh")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := string(data)
|
||||
for _, required := range []string{
|
||||
"pg_dump -Fc",
|
||||
"pg_restore --list",
|
||||
"dobotai-postgres-data",
|
||||
"dobotai-dingtalk",
|
||||
"rollback",
|
||||
"apply-migrations.sh",
|
||||
} {
|
||||
if !strings.Contains(source, required) {
|
||||
t.Errorf("database adoption script missing %q", required)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user