diff options
author | Alex Auvolat <alex@adnab.me> | 2023-05-19 12:52:14 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-05-22 10:45:06 +0200 |
commit | e2ce5970c6c1ee26e5aabf6b5dba8d641416fb53 (patch) | |
tree | f2aa150a5c11924c442e871b3cd5aa8c42c92886 /src/garage/tests/k2v_client | |
parent | 644e8722641c826603f7ee3c2c7b58f31ab88c23 (diff) | |
download | garage-e2ce5970c6c1ee26e5aabf6b5dba8d641416fb53.tar.gz garage-e2ce5970c6c1ee26e5aabf6b5dba8d641416fb53.zip |
Add basic k2v_client integration tests
Diffstat (limited to 'src/garage/tests/k2v_client')
-rw-r--r-- | src/garage/tests/k2v_client/mod.rs | 1 | ||||
-rw-r--r-- | src/garage/tests/k2v_client/simple.rs | 60 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/garage/tests/k2v_client/mod.rs b/src/garage/tests/k2v_client/mod.rs new file mode 100644 index 00000000..b252f36b --- /dev/null +++ b/src/garage/tests/k2v_client/mod.rs @@ -0,0 +1 @@ +pub mod simple; diff --git a/src/garage/tests/k2v_client/simple.rs b/src/garage/tests/k2v_client/simple.rs new file mode 100644 index 00000000..1a3118ef --- /dev/null +++ b/src/garage/tests/k2v_client/simple.rs @@ -0,0 +1,60 @@ +use std::time::Duration; + +use k2v_client::*; + +use crate::common; + +#[tokio::test] +async fn test_simple() { + let ctx = common::context(); + let bucket = ctx.create_bucket("test-k2v-client-simple"); + let k2v_client = ctx.k2v_client(&bucket); + + k2v_client + .insert_item("root", "test1", b"Hello, world!".to_vec(), None) + .await + .unwrap(); + + let res = k2v_client.read_item("root", "test1").await.unwrap(); + + assert_eq!(res.value.len(), 1); + assert_eq!(res.value[0], K2vValue::Value(b"Hello, world!".to_vec())); +} + +#[tokio::test] +async fn test_special_chars() { + let ctx = common::context(); + let bucket = ctx.create_bucket("test-k2v-client-simple-special-chars"); + let k2v_client = ctx.k2v_client(&bucket); + + let (pk, sk) = ("root@plépp", "≤≤««"); + k2v_client + .insert_item(pk, sk, b"Hello, world!".to_vec(), None) + .await + .unwrap(); + + let res = k2v_client.read_item(pk, sk).await.unwrap(); + assert_eq!(res.value.len(), 1); + assert_eq!(res.value[0], K2vValue::Value(b"Hello, world!".to_vec())); + + // sleep a bit before read_index + tokio::time::sleep(Duration::from_secs(1)).await; + let res = k2v_client.read_index(Default::default()).await.unwrap(); + assert_eq!(res.items.len(), 1); + assert_eq!(res.items.keys().next().unwrap(), pk); + + let res = k2v_client + .read_batch(&[BatchReadOp { + partition_key: pk, + filter: Default::default(), + single_item: false, + conflicts_only: false, + tombstones: false, + }]) + .await + .unwrap(); + assert_eq!(res.len(), 1); + let res = &res[0]; + assert_eq!(res.items.len(), 1); + assert_eq!(res.items.keys().next().unwrap(), sk); +} |