From b33223562a956db6d8cbec9eb86c4edc371b0682 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 6 Jul 2023 17:46:49 +0100 Subject: [PATCH] Add two failing index tests (#2125) --- lib/tests/define.rs | 102 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/lib/tests/define.rs b/lib/tests/define.rs index 6d3ca469..5214d386 100644 --- a/lib/tests/define.rs +++ b/lib/tests/define.rs @@ -923,6 +923,108 @@ async fn define_statement_index_multiple_unique_existing() -> Result<(), Error> Ok(()) } +#[tokio::test] +#[ignore] +async fn define_statement_index_single_unique_embedded_multiple() -> Result<(), Error> { + let sql = " + DEFINE INDEX test ON user FIELDS tags UNIQUE; + DEFINE INDEX test ON user COLUMNS tags UNIQUE; + INFO FOR TABLE user; + CREATE user:1 SET tags = ['one', 'two']; + CREATE user:2 SET tags = ['two', 'three']; + "; + 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?; + assert_eq!(res.len(), 5); + // + 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( + "{ + events: {}, + fields: {}, + tables: {}, + indexes: { test: 'DEFINE INDEX test ON user FIELDS tags UNIQUE' }, + }", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse("[{ id: user:1, tags: ['one', 'two'] }]"); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result; + assert!(matches!( + tmp.err(), + Some(e) if e.to_string() == "Database index `test` already contains `user:2`" + )); + // + Ok(()) +} + +#[tokio::test] +#[ignore] +async fn define_statement_index_multiple_unique_embedded_multiple() -> Result<(), Error> { + let sql = " + DEFINE INDEX test ON user FIELDS account, tags UNIQUE; + DEFINE INDEX test ON user COLUMNS account, tags UNIQUE; + INFO FOR TABLE user; + CREATE user:1 SET account = 'apple', tags = ['one', 'two']; + CREATE user:2 SET account = 'tesla', tags = ['one', 'two']; + CREATE user:3 SET account = 'apple', tags = ['two', 'three']; + CREATE user:4 SET account = 'tesla', tags = ['two', 'three']; + "; + 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?; + assert_eq!(res.len(), 7); + // + 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( + "{ + events: {}, + fields: {}, + tables: {}, + indexes: { test: 'DEFINE INDEX test ON user FIELDS account, tags UNIQUE' }, + }", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse("[{ id: user:1, account: 'apple', tags: ['one', 'two'] }]"); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse("[{ id: user:1, account: 'tesla', tags: ['one', 'two'] }]"); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result; + assert!(matches!( + tmp.err(), + Some(e) if e.to_string() == "Database index `test` already contains `user:3`" + )); + // + let tmp = res.remove(0).result; + assert!(matches!( + tmp.err(), + Some(e) if e.to_string() == "Database index `test` already contains `user:4`" + )); + // + Ok(()) +} + #[tokio::test] async fn define_statement_analyzer() -> Result<(), Error> { let sql = "