Skip to content

Commit

Permalink
fix: use Get-Content instead of Get-FileHash for checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
ho-229 committed Aug 11, 2024
1 parent 404f230 commit 2454c3c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
21 changes: 15 additions & 6 deletions integrations/cloudfilter/tests/behavior/fetch_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,32 @@
use libtest_mimic::Failed;

use crate::{
utils::{file_hash, file_length},
utils::{file_content, file_length},
ROOT_PATH,
};

pub fn test_fetch_data() -> Result<(), Failed> {
let files = ["normal_file.txt", "special_file !@#$%^&()_+-=;',.txt"];
for file in files {
let files = [
(
"normal_file.txt",
include_str!("..\\..\\..\\..\\fixtures/data/normal_file.txt"),
),
(
"special_file !@#$%^&()_+-=;',.txt",
include_str!("..\\..\\..\\..\\fixtures/data/special_file !@#$%^&()_+-=;',.txt"),
),
];
for (file, expected_content) in files {
let path = format!("{ROOT_PATH}\\{file}");
assert_eq!(
31523,
expected_content.len(),
file_length(&path).expect("file length"),
"file length",
);

assert_eq!(
"AA3CDBDE1C58BD7727D3A4D6E4DF6A2057EBA9C928EC8EDD1DAF670E6EC67C38",
file_hash(&path).expect("file hash"),
expected_content,
file_content(&path).expect("file hash"),
"file hash",
)
}
Expand Down
3 changes: 0 additions & 3 deletions integrations/cloudfilter/tests/behavior/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ use std::{
path::{Path, PathBuf},
pin::Pin,
process::ExitCode,
thread,
time::Duration,
};

use cloud_filter::{
Expand Down Expand Up @@ -60,7 +58,6 @@ async fn main() -> ExitCode {
}

let (sync_root_id, connection) = init(op);
thread::sleep(Duration::from_secs(10));

let tests = vec![
Trial::test("fetch_data", fetch_data::test_fetch_data),
Expand Down
11 changes: 4 additions & 7 deletions integrations/cloudfilter/tests/behavior/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ pub fn file_length(path: impl Display) -> anyhow::Result<usize> {
Ok(len)
}

pub fn file_hash(path: impl Display) -> anyhow::Result<String> {
let hash = powershell_script::run(&format!("(Get-FileHash \"{path}\" -Algorithm SHA256).Hash"))
pub fn file_content(path: impl Display) -> anyhow::Result<String> {
let content = powershell_script::run(&format!("Get-Content \"{path}\""))
.context("run powershell")?
.stdout()
.unwrap_or_default()
.trim()
.into();

Ok(hash)
.unwrap_or_default();
Ok(content)
}

pub fn list(path: impl Display, option: impl Display) -> anyhow::Result<Vec<String>> {
Expand Down

0 comments on commit 2454c3c

Please sign in to comment.