forked from Deuxfleurs/garage
Add basic k2v_client integration tests
This commit is contained in:
parent
d98428bcc6
commit
de5f3e2aa8
8 changed files with 83 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1199,6 +1199,7 @@ dependencies = [
|
||||||
"hmac",
|
"hmac",
|
||||||
"http",
|
"http",
|
||||||
"hyper",
|
"hyper",
|
||||||
|
"k2v-client",
|
||||||
"kuska-sodiumoxide",
|
"kuska-sodiumoxide",
|
||||||
"netapp",
|
"netapp",
|
||||||
"opentelemetry",
|
"opentelemetry",
|
||||||
|
|
|
@ -33,7 +33,7 @@ args@{
|
||||||
ignoreLockHash,
|
ignoreLockHash,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
nixifiedLockHash = "3d30171172bc39b6c45f9b1917c9eed892c06624b704ac82731524dd9784cbd7";
|
nixifiedLockHash = "269f4ee133812043ba96b2667a7275af385af780a1183c4bd6abaebffb48b521";
|
||||||
workspaceSrc = if args.workspaceSrc == null then ./. else args.workspaceSrc;
|
workspaceSrc = if args.workspaceSrc == null then ./. else args.workspaceSrc;
|
||||||
currentLockHash = builtins.hashFile "sha256" (workspaceSrc + /Cargo.lock);
|
currentLockHash = builtins.hashFile "sha256" (workspaceSrc + /Cargo.lock);
|
||||||
lockHashIgnored = if ignoreLockHash
|
lockHashIgnored = if ignoreLockHash
|
||||||
|
@ -1737,6 +1737,7 @@ in
|
||||||
hmac = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".hmac."0.12.1" { inherit profileName; }).out;
|
hmac = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".hmac."0.12.1" { inherit profileName; }).out;
|
||||||
http = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".http."0.2.9" { inherit profileName; }).out;
|
http = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".http."0.2.9" { inherit profileName; }).out;
|
||||||
hyper = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".hyper."0.14.26" { inherit profileName; }).out;
|
hyper = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".hyper."0.14.26" { inherit profileName; }).out;
|
||||||
|
k2v_client = (rustPackages."unknown".k2v-client."0.0.3" { inherit profileName; }).out;
|
||||||
serde_json = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".serde_json."1.0.91" { inherit profileName; }).out;
|
serde_json = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".serde_json."1.0.91" { inherit profileName; }).out;
|
||||||
sha2 = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".sha2."0.10.6" { inherit profileName; }).out;
|
sha2 = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".sha2."0.10.6" { inherit profileName; }).out;
|
||||||
static_init = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".static_init."1.0.3" { inherit profileName; }).out;
|
static_init = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".static_init."1.0.3" { inherit profileName; }).out;
|
||||||
|
|
|
@ -26,6 +26,7 @@ garage_rpc = { version = "0.8.2", path = "src/rpc" }
|
||||||
garage_table = { version = "0.8.2", path = "src/table" }
|
garage_table = { version = "0.8.2", path = "src/table" }
|
||||||
garage_util = { version = "0.8.2", path = "src/util" }
|
garage_util = { version = "0.8.2", path = "src/util" }
|
||||||
garage_web = { version = "0.8.2", path = "src/web" }
|
garage_web = { version = "0.8.2", path = "src/web" }
|
||||||
|
k2v-client = { version = "0.0.3", path = "src/k2v-client" }
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
lto = "off"
|
lto = "off"
|
||||||
|
|
|
@ -73,6 +73,8 @@ assert-json-diff = "2.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
base64 = "0.21"
|
base64 = "0.21"
|
||||||
|
|
||||||
|
k2v-client.workspace = true
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "bundled-libs", "metrics", "sled", "k2v" ]
|
default = [ "bundled-libs", "metrics", "sled", "k2v" ]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use aws_sdk_s3::{Client, Region};
|
use aws_sdk_s3::{Client, Region};
|
||||||
use ext::*;
|
use ext::*;
|
||||||
|
use k2v_client::K2vClient;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod macros;
|
pub mod macros;
|
||||||
|
@ -68,6 +69,19 @@ impl Context {
|
||||||
|
|
||||||
bucket_name
|
bucket_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build a K2vClient for a given bucket
|
||||||
|
pub fn k2v_client(&self, bucket: &str) -> K2vClient {
|
||||||
|
let config = k2v_client::K2vClientConfig {
|
||||||
|
region: REGION.to_string(),
|
||||||
|
endpoint: self.garage.k2v_uri().to_string(),
|
||||||
|
aws_access_key_id: self.key.id.clone(),
|
||||||
|
aws_secret_access_key: self.key.secret.clone(),
|
||||||
|
bucket: bucket.to_string(),
|
||||||
|
user_agent: None,
|
||||||
|
};
|
||||||
|
K2vClient::new(config).expect("Could not create K2V client")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn context() -> Context {
|
pub fn context() -> Context {
|
||||||
|
|
1
src/garage/tests/k2v_client/mod.rs
Normal file
1
src/garage/tests/k2v_client/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod simple;
|
60
src/garage/tests/k2v_client/simple.rs
Normal file
60
src/garage/tests/k2v_client/simple.rs
Normal file
|
@ -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);
|
||||||
|
}
|
|
@ -8,3 +8,5 @@ mod s3;
|
||||||
|
|
||||||
#[cfg(feature = "k2v")]
|
#[cfg(feature = "k2v")]
|
||||||
mod k2v;
|
mod k2v;
|
||||||
|
#[cfg(feature = "k2v")]
|
||||||
|
mod k2v_client;
|
||||||
|
|
Loading…
Reference in a new issue