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

[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #2286: test(core): test for append

suyanhanx commented on code in PR #2286:
URL: https://github.com/apache/incubator-opendal/pull/2286#discussion_r1200552906


##########
core/tests/behavior/append.rs:
##########
@@ -0,0 +1,240 @@
+// 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::ops::OpAppend;
+use opendal::EntryMode;
+use opendal::ErrorKind;
+use opendal::Operator;
+
+use super::utils::*;
+
+/// Test services that meet the following capability:
+///
+/// - can_read
+/// - can_write
+/// - can_append
+macro_rules! behavior_append_test {
+    ($service:ident, $($(#[$meta:meta])* $test:ident),*,) => {
+        paste::item! {
+            $(
+                #[test]
+                $(
+                    #[$meta]
+                )*
+                fn [<append_ $test >]() -> anyhow::Result<()> {
+                    match OPERATOR.as_ref() {
+                        Some(op) if op.info().can_read()
+                            && op.info().can_write()
+                            && op.info().can_append() => RUNTIME.block_on($crate::append::$test(op.clone())),
+                        Some(_) => {
+                            log::warn!("service {} doesn't support append, ignored", opendal::Scheme::$service);
+                            Ok(())
+                        },
+                        None => {
+                            Ok(())
+                        }
+                    }
+                }
+            )*
+        }
+    };
+}
+
+#[macro_export]
+macro_rules! behavior_append_tests {
+     ($($service:ident),*) => {
+        $(
+            behavior_append_test!(
+                $service,
+
+                test_append,
+                test_append_to_non_existing_target,
+                test_append_with_dir_path,
+                test_append_with_cache_control,
+                test_append_with_content_type,
+                test_append_with_content_disposition,
+
+                test_fuzz_appender,
+            );
+        )*
+    };
+}
+
+/// Test append to a file must success.
+pub async fn test_append(op: Operator) -> Result<()> {
+    let path = uuid::Uuid::new_v4().to_string();
+    let (content_one, size_one) = gen_bytes();
+    let (content_two, size_two) = gen_bytes();
+
+    op.write(&path, content_one.clone())

Review Comment:
   Oh, you are right. I may need to append it two times.



-- 
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