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 2c49350a0 fix(oli): oli commands don't work properly for files in CWD
(#2833)
2c49350a0 is described below
commit 2c49350a007d7bd6907c33b8aebe8e9999fef967
Author: Kousuke Saruta <[email protected]>
AuthorDate: Thu Aug 10 11:13:53 2023 +0900
fix(oli): oli commands don't work properly for files in CWD (#2833)
* Fix oli to handle files in CWD.
* Fix clippy.
---
bin/oli/src/config/mod.rs | 5 ++++-
bin/oli/tests/cat.rs | 22 ++++++++++++++++++++++
bin/oli/tests/cp.rs | 21 +++++++++++++++++++++
bin/oli/tests/rm.rs | 16 ++++++++++++++++
bin/oli/tests/stat.rs | 24 ++++++++++++++++++++++++
5 files changed, 87 insertions(+), 1 deletion(-)
diff --git a/bin/oli/src/config/mod.rs b/bin/oli/src/config/mod.rs
index 1452375b2..adb39665a 100644
--- a/bin/oli/src/config/mod.rs
+++ b/bin/oli/src/config/mod.rs
@@ -135,7 +135,10 @@ impl Config {
fs_builder.root(if base.is_empty() { "/" } else { base });
filename
}
- _ => s,
+ _ => {
+ fs_builder.root(".");
+ s
+ }
};
return Ok((Operator::new(fs_builder)?.finish(), filename.into()));
diff --git a/bin/oli/tests/cat.rs b/bin/oli/tests/cat.rs
index 44c86fab0..7ab9eea75 100644
--- a/bin/oli/tests/cat.rs
+++ b/bin/oli/tests/cat.rs
@@ -40,3 +40,25 @@ async fn test_basic_cat() -> Result<()> {
assert_eq!(output_stdout, actual);
Ok(())
}
+
+#[tokio::test]
+async fn test_cat_for_path_in_current_dir() -> Result<()> {
+ let dir = tempfile::tempdir()?;
+ let dst_path = dir.path().join("dst.txt");
+ let expect = "hello";
+ fs::write(&dst_path, expect)?;
+
+ let mut cmd = Command::cargo_bin("oli")?;
+
+ cmd.arg("cat")
+ .arg("dst.txt")
+ .current_dir(dir.path().clone());
+ 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/cp.rs b/bin/oli/tests/cp.rs
index ed6afd7c4..d9ef28efa 100644
--- a/bin/oli/tests/cp.rs
+++ b/bin/oli/tests/cp.rs
@@ -40,3 +40,24 @@ async fn test_basic_cp() -> Result<()> {
assert_eq!(expect, actual);
Ok(())
}
+
+#[tokio::test]
+async fn test_cp_for_path_in_current_dir() -> Result<()> {
+ let dir = tempfile::tempdir()?;
+ let src_path = dir.path().join("src.txt");
+ let dst_path = dir.path().join("dst.txt");
+ let expect = "hello";
+ fs::write(src_path, expect)?;
+
+ let mut cmd = Command::cargo_bin("oli")?;
+
+ cmd.arg("cp")
+ .arg("src.txt")
+ .arg("dst.txt")
+ .current_dir(dir.path().clone());
+ cmd.assert().success();
+
+ let actual = fs::read_to_string(dst_path)?;
+ assert_eq!(expect, actual);
+ Ok(())
+}
diff --git a/bin/oli/tests/rm.rs b/bin/oli/tests/rm.rs
index 98ee6b381..81e8c90a6 100644
--- a/bin/oli/tests/rm.rs
+++ b/bin/oli/tests/rm.rs
@@ -36,3 +36,19 @@ async fn test_basic_rm() -> Result<()> {
assert!(fs::read_to_string(&dst_path).is_err());
Ok(())
}
+
+#[tokio::test]
+async fn test_rm_for_path_in_current_dir() -> Result<()> {
+ let dir = tempfile::tempdir()?;
+ let dst_path = dir.path().join("dst.txt");
+ let expect = "hello";
+ fs::write(&dst_path, expect)?;
+
+ let mut cmd = Command::cargo_bin("oli")?;
+
+ cmd.arg("rm").arg("dst.txt").current_dir(dir.path().clone());
+ 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
index 62e6e3180..aa4da5795 100644
--- a/bin/oli/tests/stat.rs
+++ b/bin/oli/tests/stat.rs
@@ -44,3 +44,27 @@ async fn test_basic_stat() -> Result<()> {
Ok(())
}
+
+#[tokio::test]
+async fn test_stat_for_path_in_current_dir() -> Result<()> {
+ let dir = tempfile::tempdir()?;
+ let dst_path = dir.path().join("dst.txt");
+ let expect = "hello";
+ fs::write(dst_path, expect)?;
+
+ let mut cmd = Command::cargo_bin("oli")?;
+
+ cmd.arg("stat")
+ .arg("dst.txt")
+ .current_dir(dir.path().clone());
+ let res = cmd.assert().success();
+ let output = res.get_output().stdout.clone();
+
+ let output_stdout = String::from_utf8(output)?;
+ assert!(output_stdout.contains("path: dst.txt"));
+ assert!(output_stdout.contains("size: 5"));
+ assert!(output_stdout.contains("type: file"));
+ assert!(output_stdout.contains("last-modified: "));
+
+ Ok(())
+}