surrealpatch/lib/tests/remove.rs

76 lines
1.6 KiB
Rust
Raw Normal View History

2023-05-10 02:08:09 +00:00
mod parse;
use parse::Parse;
use surrealdb::dbs::Session;
use surrealdb::err::Error;
use surrealdb::kvs::Datastore;
use surrealdb::sql::Value;
#[tokio::test]
async fn remove_statement_table() -> Result<(), Error> {
let sql = "
DEFINE TABLE test SCHEMALESS;
REMOVE TABLE test;
INFO FOR DB;
";
let dbs = Datastore::new("memory").await?;
let ses = Session::for_kv().with_ns("test").with_db("test");
let res = &mut dbs.execute(sql, &ses, None).await?;
2023-05-10 02:08:09 +00:00
assert_eq!(res.len(), 3);
//
let tmp = res.remove(0).result;
assert!(tmp.is_ok());
//
let tmp = res.remove(0).result;
assert!(tmp.is_ok());
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"{
analyzers: {},
logins: {},
tokens: {},
functions: {},
params: {},
scopes: {},
tables: {}
2023-05-10 02:08:09 +00:00
}",
);
assert_eq!(tmp, val);
Ok(())
}
#[tokio::test]
async fn remove_statement_analyzer() -> Result<(), Error> {
let sql = "
DEFINE ANALYZER english TOKENIZERS blank,class FILTERS lowercase,snowball(english);
2023-05-10 02:08:09 +00:00
REMOVE ANALYZER english;
INFO FOR DB;
";
let dbs = Datastore::new("memory").await?;
let ses = Session::for_kv().with_ns("test").with_db("test");
let res = &mut dbs.execute(sql, &ses, None).await?;
2023-05-10 02:08:09 +00:00
assert_eq!(res.len(), 3);
// Analyzer is defined
let tmp = res.remove(0).result;
assert!(tmp.is_ok());
// Analyzer is removed
let tmp = res.remove(0).result;
assert!(tmp.is_ok());
// Check infos output
let tmp = res.remove(0).result?;
let val = Value::parse(
"{
analyzers: {},
logins: {},
tokens: {},
functions: {},
params: {},
scopes: {},
tables: {}
2023-05-10 02:08:09 +00:00
}",
);
assert_eq!(tmp, val);
Ok(())
}