This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new eaffb47cd test(oli): add oli related tests (#2624)
eaffb47cd is described below

commit eaffb47cde25964278d34bc8d940245d7cb81cfc
Author: oowl <[email protected]>
AuthorDate: Thu Jul 13 13:05:10 2023 +0800

    test(oli): add oli related tests (#2624)
    
    * test(oli): add oli related tests
    
    Signed-off-by: owl <[email protected]>
    
    * test(oli): fix code
    
    Signed-off-by: owl <[email protected]>
    
    * test(oli): fix code
    
    Signed-off-by: owl <[email protected]>
    
    ---------
    
    Signed-off-by: owl <[email protected]>
---
 bin/oli/tests/cat.rs  | 45 ++++++++++++++++++++++++++++++++++++++++++
 bin/oli/tests/ls.rs   | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++
 bin/oli/tests/rm.rs   | 41 ++++++++++++++++++++++++++++++++++++++
 bin/oli/tests/stat.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 187 insertions(+)

diff --git a/bin/oli/tests/cat.rs b/bin/oli/tests/cat.rs
new file mode 100644
index 000000000..8fbe2c077
--- /dev/null
+++ b/bin/oli/tests/cat.rs
@@ -0,0 +1,45 @@
+// 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 std::env;
+use std::fs;
+use std::path::Path;
+use std::process::Command;
+
+use anyhow::Result;
+use assert_cmd::prelude::*;
+
+#[tokio::test]
+async fn test_basic_cat() -> Result<()> {
+    let dir = env::temp_dir();
+    fs::create_dir_all(dir.clone())?;
+    let dst_path = Path::new(&dir).join("dst.txt");
+    let expect = "hello";
+    fs::write(&dst_path, expect)?;
+
+    let mut cmd = Command::cargo_bin("oli")?;
+
+    cmd.arg("cat").arg(dst_path.as_os_str());
+    let actual = fs::read_to_string(&dst_path)?;
+    let res = cmd.assert().success();
+    let output = res.get_output().stdout.clone();
+
+    let output_stdout = String::from_utf8(output)?;
+
+    assert_eq!(output_stdout, actual);
+    Ok(())
+}
diff --git a/bin/oli/tests/ls.rs b/bin/oli/tests/ls.rs
new file mode 100644
index 000000000..265ad2d79
--- /dev/null
+++ b/bin/oli/tests/ls.rs
@@ -0,0 +1,54 @@
+// 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 std::env;
+use std::fs;
+use std::path::Path;
+use std::process::Command;
+
+use anyhow::Result;
+use assert_cmd::prelude::*;
+
+#[tokio::test]
+async fn test_basic_cat() -> Result<()> {
+    let dir = env::temp_dir();
+    fs::create_dir_all(dir.clone())?;
+    let dst_path_1 = Path::new(&dir).join("dst_1.txt");
+    let dst_path_2 = Path::new(&dir).join("dst_2.txt");
+    let dst_path_3 = Path::new(&dir).join("dst_3.txt");
+
+    let expect = "hello";
+    fs::write(dst_path_1, expect)?;
+    fs::write(dst_path_2, expect)?;
+    fs::write(dst_path_3, expect)?;
+
+    let mut cmd = Command::cargo_bin("oli")?;
+
+    let current_dir = dir.to_str().unwrap().to_string() + "/";
+
+    cmd.arg("ls").arg(current_dir);
+    let res = cmd.assert().success();
+    let output = res.get_output().stdout.clone();
+
+    let output_stdout = String::from_utf8(output)?;
+
+    assert!(output_stdout.contains("dst_1.txt"));
+    assert!(output_stdout.contains("dst_2.txt"));
+    assert!(output_stdout.contains("dst_3.txt"));
+
+    Ok(())
+}
diff --git a/bin/oli/tests/rm.rs b/bin/oli/tests/rm.rs
new file mode 100644
index 000000000..a7ef432bc
--- /dev/null
+++ b/bin/oli/tests/rm.rs
@@ -0,0 +1,41 @@
+// 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 std::env;
+use std::fs;
+use std::path::Path;
+use std::process::Command;
+
+use anyhow::Result;
+use assert_cmd::prelude::*;
+
+#[tokio::test]
+async fn test_basic_rm() -> Result<()> {
+    let dir = env::temp_dir();
+    fs::create_dir_all(dir.clone())?;
+    let dst_path = Path::new(&dir).join("dst.txt");
+    let expect = "hello";
+    fs::write(&dst_path, expect)?;
+
+    let mut cmd = Command::cargo_bin("oli")?;
+
+    cmd.arg("rm").arg(dst_path.as_os_str());
+    cmd.assert().success();
+
+    assert!(fs::read_to_string(&dst_path).is_err());
+    Ok(())
+}
diff --git a/bin/oli/tests/stat.rs b/bin/oli/tests/stat.rs
new file mode 100644
index 000000000..e8b660086
--- /dev/null
+++ b/bin/oli/tests/stat.rs
@@ -0,0 +1,47 @@
+// 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 std::env;
+use std::fs;
+use std::path::Path;
+use std::process::Command;
+
+use anyhow::Result;
+use assert_cmd::prelude::*;
+
+#[tokio::test]
+async fn test_basic_stat() -> Result<()> {
+    let dir = env::temp_dir();
+    fs::create_dir_all(dir.clone())?;
+    let dst_path = Path::new(&dir).join("dst.txt");
+    let expect = "hello";
+    fs::write(&dst_path, expect)?;
+
+    let mut cmd = Command::cargo_bin("oli")?;
+
+    cmd.arg("stat").arg(dst_path.as_os_str());
+    let res = cmd.assert().success();
+    let output = res.get_output().stdout.clone();
+
+    let output_stdout = String::from_utf8(output)?;
+    assert!(output_stdout.contains("path: tmp/dst.txt"));
+    assert!(output_stdout.contains("size: 5"));
+    assert!(output_stdout.contains("type: file"));
+    assert!(output_stdout.contains("last-modified: "));
+
+    Ok(())
+}

Reply via email to