Files
im_server/server/db/mysql/infrastructure_schema_test.go
T

45 lines
1.4 KiB
Go

//go:build mysql
package mysql
import (
"strings"
"testing"
)
func TestEnsureIMHTTPInfrastructureTablesUsesSelectedTenantDatabase(t *testing.T) {
exec := &recordingGroupSchemaExecutor{}
if err := ensureIMHTTPInfrastructureTables(exec); err != nil {
t.Fatal(err)
}
if len(exec.statements) != 4 {
t.Fatalf("executed %d infrastructure schema statements, want 4", len(exec.statements))
}
joined := strings.ToLower(strings.Join(exec.statements, "\n"))
for _, table := range []string{
"im_kafka_dead_letters",
"im_realname_appeals",
"im_conversation_settings",
"im_topic_drafts",
} {
if !strings.Contains(joined, table) {
t.Fatalf("missing table %s", table)
}
}
if strings.Contains(joined, "tinode.") || strings.Contains(joined, "create database") {
t.Fatalf("infrastructure schema must stay inside the selected tenant database: %s", joined)
}
if strings.Contains(joined, "im_http_idempotency") {
t.Fatalf("HTTP idempotency must not create MySQL tables: %s", joined)
}
if strings.Contains(joined, "im_kafka_outbox") {
t.Fatalf("kafka outbox table must not be created: %s", joined)
}
if strings.Contains(joined, "im_kafka_consume_log") {
t.Fatalf("kafka consume state must not create MySQL tables: %s", joined)
}
if strings.Contains(joined, "im_business_events_outbox") {
t.Fatalf("business event outbox table must not be created: %s", joined)
}
}