From 357917d67a0d509d9a355d5959f4204186a13155 Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Tue, 24 Sep 2024 23:14:24 -0700 Subject: [PATCH] Added a backend test for export/import (#30072) GitOrigin-RevId: e1859c238337c4d18095e49df21ffa9c9bc42e00 --- crates/application/src/snapshot_import.rs | 6 +++--- crates/application/src/test_helpers.rs | 11 +++++++++++ crates/storage/src/lib.rs | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crates/application/src/snapshot_import.rs b/crates/application/src/snapshot_import.rs index ceeea55b..6bdab061 100644 --- a/crates/application/src/snapshot_import.rs +++ b/crates/application/src/snapshot_import.rs @@ -1331,12 +1331,12 @@ pub async fn start_cloud_import( application: &Application, identity: Identity, source_object_key: FullyQualifiedObjectKey, -) -> anyhow::Result<()> { +) -> anyhow::Result { let object_key: ObjectKey = application .snapshot_imports_storage .copy_object(source_object_key) .await?; - store_uploaded_import( + let id = store_uploaded_import( application, identity, ImportFormat::Zip, @@ -1345,7 +1345,7 @@ pub async fn start_cloud_import( object_key, ) .await?; - Ok(()) + Ok(id) } pub async fn store_uploaded_import( diff --git a/crates/application/src/test_helpers.rs b/crates/application/src/test_helpers.rs index 52400e10..32cb551c 100644 --- a/crates/application/src/test_helpers.rs +++ b/crates/application/src/test_helpers.rs @@ -77,6 +77,7 @@ use node_executor::{ }; use storage::{ LocalDirStorage, + Storage, StorageUseCase, }; use value::{ @@ -158,6 +159,8 @@ pub trait ApplicationTestExt { fields: IndexedFields, ) -> anyhow::Result; fn database(&self) -> &Database; + fn snapshot_imports_storage(&self) -> Arc; + fn exports_storage(&self) -> Arc; } #[async_trait] @@ -281,6 +284,14 @@ impl ApplicationTestExt for Application { Ok(application) } + fn snapshot_imports_storage(&self) -> Arc { + self.snapshot_imports_storage.clone() + } + + fn exports_storage(&self) -> Arc { + self.exports_storage.clone() + } + async fn test_one_off_scheduled_job_executor_run( &self, job: ScheduledJob, diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index 1469c02e..e7b0ef34 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -181,6 +181,10 @@ pub trait Storage: Send + Sync + Debug { /// Return a fully qualified key, including info on bucket name /// and suitable for access in multi-tenant scenario fn fully_qualified_key(&self, key: &ObjectKey) -> FullyQualifiedObjectKey; + fn test_only_decompose_fully_qualified_key( + &self, + key: FullyQualifiedObjectKey, + ) -> anyhow::Result; } pub struct ObjectAttributes { @@ -1016,6 +1020,19 @@ impl Storage for LocalDirStorage { path.to_string_lossy().to_string().into() } + fn test_only_decompose_fully_qualified_key( + &self, + key: FullyQualifiedObjectKey, + ) -> anyhow::Result { + let key: String = key.into(); + let path = Path::new(&key); + let remaining = path.strip_prefix(&self.dir)?.to_string_lossy(); + remaining + .strip_suffix(".blob") + .context("Doesn't end with .blob")? + .try_into() + } + fn get_small_range( &self, key: &ObjectKey,