package pgmonitor import ( "errors" "testing" "github.com/jackc/pgx/v5/pgconn" ) func TestClampLimit(t *testing.T) { if clampLimit(0, 20, 100) != 20 { t.Fatal("default") } if clampLimit(200, 20, 100) != 100 { t.Fatal("max") } if clampLimit(5, 20, 100) != 5 { t.Fatal("value") } } func TestIsSafeIdent(t *testing.T) { if !isSafeIdent("revision_materialized_prefix") { t.Fatal("valid") } if isSafeIdent("bad-name") { t.Fatal("invalid") } if !isSafeIdent("") { t.Fatal("empty ok") } } func TestNewServiceNilPool(t *testing.T) { if NewService(nil) != nil { t.Fatal("expected nil service") } } func TestIsPgStatStatementsUnavailable(t *testing.T) { err := &pgconn.PgError{Code: "55000", Message: "pg_stat_statements must be loaded via shared_preload_libraries"} if !isPgStatStatementsUnavailable(err) { t.Fatal("55000") } if isPgStatStatementsUnavailable(errors.New("other")) { t.Fatal("unrelated") } }