From ad4393f6edd4c132ea811345daaaadbd3eb2c3c9 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 29 Jul 2022 10:48:23 +0100 Subject: [PATCH] Add initial integration tests for SQL models --- lib/tests/model.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 lib/tests/model.rs diff --git a/lib/tests/model.rs b/lib/tests/model.rs new file mode 100644 index 00000000..55bacab7 --- /dev/null +++ b/lib/tests/model.rs @@ -0,0 +1,56 @@ +mod parse; +use parse::Parse; +use surrealdb::sql::Value; +use surrealdb::Datastore; +use surrealdb::Error; +use surrealdb::Session; + +#[tokio::test] +async fn model_count() -> Result<(), Error> { + let sql = " + CREATE |test:1000| SET time = time::now(); + SELECT count() FROM test GROUP BY ALL; + "; + 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, false).await?; + assert_eq!(res.len(), 2); + // + let tmp = res.remove(0).result; + assert!(tmp.is_ok()); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[{ + count: 1000 + }]", + ); + assert_eq!(tmp, val); + // + Ok(()) +} + +#[tokio::test] +async fn model_range() -> Result<(), Error> { + let sql = " + CREATE |test:1..1000| SET time = time::now(); + SELECT count() FROM test GROUP BY ALL; + "; + 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, false).await?; + assert_eq!(res.len(), 2); + // + let tmp = res.remove(0).result; + assert!(tmp.is_ok()); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[{ + count: 1000 + }]", + ); + assert_eq!(tmp, val); + // + Ok(()) +}