use spg_engine::{Engine, QueryResult};
fn one(e: &mut Engine, sql: &str) -> spg_storage::Value<'static> {
match e.execute(sql).unwrap() {
QueryResult::Rows { rows, .. } => rows
.into_iter()
.next()
.unwrap()
.values
.into_iter()
.next()
.unwrap(),
_ => panic!("rows"),
}
}
#[test]
fn current_setting_unset_custom_guc_errors() {
let mut e = Engine::new();
assert!(e.execute("SELECT current_setting('myapp.none')").is_err());
assert!(matches!(
one(&mut e, "SELECT current_setting('myapp.none', true)"),
spg_storage::Value::Null
));
e.execute("SELECT set_config('myapp.x', 'v', false)")
.unwrap();
assert!(
matches!(one(&mut e, "SELECT current_setting('myapp.x')"), spg_storage::Value::Text(ref s) if s == "v")
);
e.execute("SET myapp.y = 'w'").unwrap();
assert!(
matches!(one(&mut e, "SELECT current_setting('myapp.y')"), spg_storage::Value::Text(ref s) if s == "w")
);
assert!(matches!(
one(&mut e, "SELECT current_setting('search_path')"),
spg_storage::Value::Text(_)
));
}