Files
upstream-centrifugo/internal/controllers/config_test.go
upstream-mirror b352a9a30d
Some checks failed
test / Lint (push) Failing after 3s
test / Test with Go 1.26.8 (push) Failing after 2s
snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:17:21 +05:00

32 lines
1000 B
Go

package controllers
import (
"strings"
"testing"
"github.com/centrifugal/centrifuge"
)
// A table prefix reaches DDL unquoted, so one PostgreSQL can't parse has to be
// caught at construction — otherwise it surfaces much later as a syntax error
// naming a generated table rather than the setting behind it.
func TestNewPostgresController_RejectsBadTablePrefix(t *testing.T) {
node, err := centrifuge.New(centrifuge.Config{})
if err != nil {
t.Fatalf("centrifuge.New: %v", err)
}
t.Cleanup(func() { _ = node.Shutdown(t.Context()) })
// Rejected before any connection is attempted, so this needs no Postgres.
_, err = NewPostgresController(node, PostgresControllerConfig{
DSN: "postgres://test:test@localhost:5432/test",
TablePrefix: "cf-prod",
})
if err == nil {
t.Fatal("expected an error for a prefix PostgreSQL cannot parse unquoted")
}
if !strings.Contains(err.Error(), "table_prefix") {
t.Fatalf("error should name the setting at fault, got: %v", err)
}
}