34 lines
871 B
Go
34 lines
871 B
Go
//go:build mysql
|
|
|
|
package mysql
|
|
|
|
import (
|
|
"database/sql"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type recordingGroupSchemaExecutor struct {
|
|
statements []string
|
|
}
|
|
|
|
func (e *recordingGroupSchemaExecutor) Exec(query string, _ ...any) (sql.Result, error) {
|
|
e.statements = append(e.statements, query)
|
|
return nil, nil
|
|
}
|
|
|
|
func TestEnsureIMGroupBusinessTablesUsesSelectedTenantDatabase(t *testing.T) {
|
|
exec := &recordingGroupSchemaExecutor{}
|
|
if err := ensureIMGroupBusinessTables(exec); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(exec.statements) != 12 {
|
|
t.Fatalf("created %d group tables, want 12", len(exec.statements))
|
|
}
|
|
for _, statement := range exec.statements {
|
|
if strings.Contains(strings.ToLower(statement), "tinode.") || strings.Contains(strings.ToLower(statement), "create database") {
|
|
t.Fatalf("group schema must use the selected tenant database: %s", statement)
|
|
}
|
|
}
|
|
}
|