You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "Xuanwo (via GitHub)" <gi...@apache.org> on 2023/04/04 07:54:35 UTC

[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1852: feat(core): add behavior tests for copy & blocking_copy

Xuanwo commented on code in PR #1852:
URL: https://github.com/apache/incubator-opendal/pull/1852#discussion_r1156868066


##########
core/tests/behavior/copy.rs:
##########


Review Comment:
   `path`/`path2` and `content`/`content2` is a bit confused. How about using `source_path`/`target_path` and `source_content`/`target_content`?



##########
core/tests/behavior/copy.rs:
##########
@@ -0,0 +1,194 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use anyhow::Result;
+use opendal::ErrorKind;
+use opendal::Operator;
+
+use super::utils::*;
+
+/// Test services that meet the following capability:
+///
+/// - can_read
+/// - can_write
+/// - can_copy
+macro_rules! behavior_copy_test {
+    ($service:ident, $($(#[$meta:meta])* $test:ident),*,) => {
+        paste::item! {
+            mod [<services_ $service:lower _copy>] {
+                $(
+                    #[tokio::test]
+                    $(
+                        #[$meta]
+                    )*
+                    async fn [< $test >]() -> anyhow::Result<()> {
+                        let op = $crate::utils::init_service::<opendal::services::$service>(true);
+                        match op {
+                            Some(op) if op.info().can_read()
+                              && op.info().can_write()
+                              && op.info().can_copy() => $crate::copy::$test(op).await,
+                            Some(_) => {
+                                log::warn!("service {} doesn't support copy, ignored", opendal::Scheme::$service);
+                                Ok(())
+                            },
+                            None => {
+                                log::warn!("service {} not initiated, ignored", opendal::Scheme::$service);
+                                Ok(())
+                            }
+                        }
+                    }
+                )*
+            }
+        }
+    };
+}
+
+#[macro_export]
+macro_rules! behavior_copy_tests {
+     ($($service:ident),*) => {
+        $(
+            behavior_copy_test!(
+                $service,
+
+                test_copy,
+                test_non_existing_source,
+                test_copy_source_dir,
+                test_copy_target_dir,
+                test_copy_self,
+                test_copy_nested,
+                test_copy_overwrite,
+
+            );
+        )*
+    };
+}
+
+// Copy a file and test with stat.
+pub async fn test_copy(op: Operator) -> Result<()> {
+    let path = uuid::Uuid::new_v4().to_string();
+    let (content, size) = gen_bytes();
+
+    op.write(&path, content).await?;
+
+    let path2 = uuid::Uuid::new_v4().to_string();
+
+    op.copy(&path, &path2).await?;
+
+    let meta = op.stat(&path2).await.expect("stat must succeed");
+    assert_eq!(meta.content_length(), size as u64);

Review Comment:
   It's better the check if the content is match. Take `write`'s test as an example.



##########
core/tests/behavior/copy.rs:
##########
@@ -0,0 +1,194 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use anyhow::Result;
+use opendal::ErrorKind;
+use opendal::Operator;
+
+use super::utils::*;
+
+/// Test services that meet the following capability:
+///
+/// - can_read
+/// - can_write
+/// - can_copy
+macro_rules! behavior_copy_test {
+    ($service:ident, $($(#[$meta:meta])* $test:ident),*,) => {
+        paste::item! {
+            mod [<services_ $service:lower _copy>] {
+                $(
+                    #[tokio::test]
+                    $(
+                        #[$meta]
+                    )*
+                    async fn [< $test >]() -> anyhow::Result<()> {
+                        let op = $crate::utils::init_service::<opendal::services::$service>(true);
+                        match op {
+                            Some(op) if op.info().can_read()
+                              && op.info().can_write()
+                              && op.info().can_copy() => $crate::copy::$test(op).await,
+                            Some(_) => {
+                                log::warn!("service {} doesn't support copy, ignored", opendal::Scheme::$service);
+                                Ok(())
+                            },
+                            None => {
+                                log::warn!("service {} not initiated, ignored", opendal::Scheme::$service);
+                                Ok(())
+                            }
+                        }
+                    }
+                )*
+            }
+        }
+    };
+}
+
+#[macro_export]
+macro_rules! behavior_copy_tests {
+     ($($service:ident),*) => {
+        $(
+            behavior_copy_test!(
+                $service,
+
+                test_copy,
+                test_non_existing_source,
+                test_copy_source_dir,
+                test_copy_target_dir,
+                test_copy_self,
+                test_copy_nested,
+                test_copy_overwrite,
+
+            );
+        )*
+    };
+}
+
+// Copy a file and test with stat.
+pub async fn test_copy(op: Operator) -> Result<()> {
+    let path = uuid::Uuid::new_v4().to_string();
+    let (content, size) = gen_bytes();
+
+    op.write(&path, content).await?;
+
+    let path2 = uuid::Uuid::new_v4().to_string();
+
+    op.copy(&path, &path2).await?;
+
+    let meta = op.stat(&path2).await.expect("stat must succeed");
+    assert_eq!(meta.content_length(), size as u64);

Review Comment:
   It's better the check if the content is match. Take `write`'s test as an example.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org