object_store/
test_util.rs1use std::env;
16
17use crate::{ObjectStore, Result};
18
19pub struct TempFolder {
21 store: ObjectStore,
22 path: String,
24}
25
26impl TempFolder {
27 pub fn new(store: &ObjectStore, path: &str) -> Self {
28 Self {
29 store: store.clone(),
30 path: path.to_string(),
31 }
32 }
33
34 pub async fn remove_all(&self) -> Result<()> {
35 self.store.remove_all(&self.path).await
36 }
37}
38
39#[derive(Debug)]
41pub struct TestS3Config {
42 pub root: String,
43 pub access_key_id: String,
44 pub secret_access_key: String,
45 pub bucket: String,
46 pub region: Option<String>,
47}
48
49pub fn s3_test_config() -> Option<TestS3Config> {
51 if let Ok(b) = env::var("GT_S3_BUCKET") {
52 if !b.is_empty() {
53 return Some(TestS3Config {
54 root: uuid::Uuid::new_v4().to_string(),
55 access_key_id: env::var("GT_S3_ACCESS_KEY_ID").ok()?,
56 secret_access_key: env::var("GT_S3_ACCESS_KEY").ok()?,
57 bucket: env::var("GT_S3_BUCKET").ok()?,
58 region: Some(env::var("GT_S3_REGION").ok()?),
59 });
60 }
61 }
62
63 None
64}