Skip to content

Commit eaffb47

Browse files
authored
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]>
1 parent 04cb5f0 commit eaffb47

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed

bin/oli/tests/cat.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use std::env;
19+
use std::fs;
20+
use std::path::Path;
21+
use std::process::Command;
22+
23+
use anyhow::Result;
24+
use assert_cmd::prelude::*;
25+
26+
#[tokio::test]
27+
async fn test_basic_cat() -> Result<()> {
28+
let dir = env::temp_dir();
29+
fs::create_dir_all(dir.clone())?;
30+
let dst_path = Path::new(&dir).join("dst.txt");
31+
let expect = "hello";
32+
fs::write(&dst_path, expect)?;
33+
34+
let mut cmd = Command::cargo_bin("oli")?;
35+
36+
cmd.arg("cat").arg(dst_path.as_os_str());
37+
let actual = fs::read_to_string(&dst_path)?;
38+
let res = cmd.assert().success();
39+
let output = res.get_output().stdout.clone();
40+
41+
let output_stdout = String::from_utf8(output)?;
42+
43+
assert_eq!(output_stdout, actual);
44+
Ok(())
45+
}

bin/oli/tests/ls.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use std::env;
19+
use std::fs;
20+
use std::path::Path;
21+
use std::process::Command;
22+
23+
use anyhow::Result;
24+
use assert_cmd::prelude::*;
25+
26+
#[tokio::test]
27+
async fn test_basic_cat() -> Result<()> {
28+
let dir = env::temp_dir();
29+
fs::create_dir_all(dir.clone())?;
30+
let dst_path_1 = Path::new(&dir).join("dst_1.txt");
31+
let dst_path_2 = Path::new(&dir).join("dst_2.txt");
32+
let dst_path_3 = Path::new(&dir).join("dst_3.txt");
33+
34+
let expect = "hello";
35+
fs::write(dst_path_1, expect)?;
36+
fs::write(dst_path_2, expect)?;
37+
fs::write(dst_path_3, expect)?;
38+
39+
let mut cmd = Command::cargo_bin("oli")?;
40+
41+
let current_dir = dir.to_str().unwrap().to_string() + "/";
42+
43+
cmd.arg("ls").arg(current_dir);
44+
let res = cmd.assert().success();
45+
let output = res.get_output().stdout.clone();
46+
47+
let output_stdout = String::from_utf8(output)?;
48+
49+
assert!(output_stdout.contains("dst_1.txt"));
50+
assert!(output_stdout.contains("dst_2.txt"));
51+
assert!(output_stdout.contains("dst_3.txt"));
52+
53+
Ok(())
54+
}

bin/oli/tests/rm.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use std::env;
19+
use std::fs;
20+
use std::path::Path;
21+
use std::process::Command;
22+
23+
use anyhow::Result;
24+
use assert_cmd::prelude::*;
25+
26+
#[tokio::test]
27+
async fn test_basic_rm() -> Result<()> {
28+
let dir = env::temp_dir();
29+
fs::create_dir_all(dir.clone())?;
30+
let dst_path = Path::new(&dir).join("dst.txt");
31+
let expect = "hello";
32+
fs::write(&dst_path, expect)?;
33+
34+
let mut cmd = Command::cargo_bin("oli")?;
35+
36+
cmd.arg("rm").arg(dst_path.as_os_str());
37+
cmd.assert().success();
38+
39+
assert!(fs::read_to_string(&dst_path).is_err());
40+
Ok(())
41+
}

bin/oli/tests/stat.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use std::env;
19+
use std::fs;
20+
use std::path::Path;
21+
use std::process::Command;
22+
23+
use anyhow::Result;
24+
use assert_cmd::prelude::*;
25+
26+
#[tokio::test]
27+
async fn test_basic_stat() -> Result<()> {
28+
let dir = env::temp_dir();
29+
fs::create_dir_all(dir.clone())?;
30+
let dst_path = Path::new(&dir).join("dst.txt");
31+
let expect = "hello";
32+
fs::write(&dst_path, expect)?;
33+
34+
let mut cmd = Command::cargo_bin("oli")?;
35+
36+
cmd.arg("stat").arg(dst_path.as_os_str());
37+
let res = cmd.assert().success();
38+
let output = res.get_output().stdout.clone();
39+
40+
let output_stdout = String::from_utf8(output)?;
41+
assert!(output_stdout.contains("path: tmp/dst.txt"));
42+
assert!(output_stdout.contains("size: 5"));
43+
assert!(output_stdout.contains("type: file"));
44+
assert!(output_stdout.contains("last-modified: "));
45+
46+
Ok(())
47+
}

0 commit comments

Comments
 (0)