pgrx
pgrx copied to clipboard
how to test GucContext::SuBackend
hello, let's assume that I have this GUC initialization logic:
use pgrx::*;
use std::ffi::CStr;
pub static MY_FOO_RUNTIME_PARAM: &str = "my.foo";
pub static MY_FOO: GucSetting<Option<&'static CStr>> = GucSetting::<Option<&'static CStr>>::new(None);
pub fn init() {
GucRegistry::define_string_guc(
MY_FOO_RUNTIME_PARAM,
"My Foo",
"That can be FooBar",
&MY_FOO,
GucContext::SuBackend,
GucFlags::NOT_WHILE_SEC_REST
);
}
- How can I properly set it for unit tests? I've tried with some util function that works for
GucContext::Suset
:
fn set_my_foo_in_guc(value: String) {
Spi::run(format!("SET {} = '{}'", MY_FOO_RUNTIME_PARAM, value).as_str()).unwrap();
}
but - as expected - I'm getting
Client Error:
parameter "my.foo" cannot be set after connection start
postgres location: guc.c
- For manual tests, how can set this GUC param in
cargo pgrx run pg16
?