Skip to content

Commit

Permalink
fix cli test
Browse files Browse the repository at this point in the history
  • Loading branch information
robatipoor committed Mar 20, 2024
1 parent 8894703 commit b03ff1a
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 29 deletions.
8 changes: 4 additions & 4 deletions cli/tests/cli/copy_and_paste_cli_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::helper::{generate_random_key_nonce, CliTestContext};
#[tokio::test]
async fn test_copy_and_paste_command(ctx: &mut CliTestContext) {
let (file, expected_content) = ctx.create_dummy_file().await.unwrap();
let url_path = Command::cargo_bin("cli")
let url_path = Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -23,7 +23,7 @@ async fn test_copy_and_paste_command(ctx: &mut CliTestContext) {
.unwrap()
.stdout;
let url_path = std::str::from_utf8(&url_path).unwrap().trim();
let actual_content = Command::cargo_bin("cli")
let actual_content = Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -44,7 +44,7 @@ async fn test_copy_and_paste_command(ctx: &mut CliTestContext) {
async fn test_copy_encrypt_and_paste_decrypt_command(ctx: &mut CliTestContext) {
let key_nonce = generate_random_key_nonce();
let (file, expected_content) = ctx.create_dummy_file().await.unwrap();
let url_path = Command::cargo_bin("cli")
let url_path = Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -63,7 +63,7 @@ async fn test_copy_encrypt_and_paste_decrypt_command(ctx: &mut CliTestContext) {
.unwrap()
.stdout;
let url_path = std::str::from_utf8(&url_path).unwrap().trim();
let actual_content = Command::cargo_bin("cli")
let actual_content = Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/cli/delete_cli_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::helper::CliTestContext;
#[tokio::test]
async fn test_delete_command(ctx: &mut CliTestContext) {
let (url_path, _) = ctx.upload_dummy_file().await.unwrap();
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/cli/download_cli_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::helper::CliTestContext;
async fn test_download_command_to_the_destination_file(ctx: &mut CliTestContext) {
let (url_path, expected_content) = ctx.upload_dummy_file().await.unwrap();
let destination_file_path = ctx.workspace.join("destination_file.txt");
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -32,7 +32,7 @@ async fn test_download_command_to_the_destination_dir(ctx: &mut CliTestContext)
let (url_path, expected_content) = ctx.upload_dummy_file().await.unwrap();
let destination_dir = ctx.workspace.join("destination_dir");
tokio::fs::create_dir_all(&destination_dir).await.unwrap();
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand Down
12 changes: 6 additions & 6 deletions cli/tests/cli/encrypt_and_decrypt_cli_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use assert_cmd::Command;
async fn test_encrypt_and_decrypt_to_the_destination_file(ctx: &mut CliTestContext) {
let (file, expected_content) = ctx.create_dummy_file().await.unwrap();
let key_nonce = generate_random_key_nonce();
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -22,7 +22,7 @@ async fn test_encrypt_and_decrypt_to_the_destination_file(ctx: &mut CliTestConte
.assert()
.success();
let destination_file_path = ctx.workspace.join("destination_file.txt");
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -49,7 +49,7 @@ async fn test_encrypt_and_decrypt_to_the_destination_file(ctx: &mut CliTestConte
async fn test_encrypt_and_decrypt_with_progress_bar(ctx: &mut CliTestContext) {
let (file, expected_content) = ctx.create_dummy_file().await.unwrap();
let key_nonce = generate_random_key_nonce();
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -66,7 +66,7 @@ async fn test_encrypt_and_decrypt_with_progress_bar(ctx: &mut CliTestContext) {
.assert()
.success();
let destination_file_path = ctx.workspace.join("destination_file.txt");
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand Down Expand Up @@ -94,7 +94,7 @@ async fn test_encrypt_and_decrypt_with_progress_bar(ctx: &mut CliTestContext) {
async fn test_encrypt_file_and_decrypt_to_the_destination_dir(ctx: &mut CliTestContext) {
let (file, expected_content) = ctx.create_dummy_file().await.unwrap();
let key_nonce = generate_random_key_nonce();
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -111,7 +111,7 @@ async fn test_encrypt_file_and_decrypt_to_the_destination_dir(ctx: &mut CliTestC
.success();
let destination_dir = ctx.workspace.join("destination_dir");
tokio::fs::create_dir_all(&destination_dir).await.unwrap();
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/cli/helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl CliTestContext {
let port = find_free_port().await.unwrap();
let server_addr = format!("http://127.0.0.1:{port}");

let child = tokio::process::Command::new("target/debug/api")
let child = tokio::process::Command::new("target/debug/pf-api")
.args(["--settings", "api/settings/base.toml"])
.env("PF__SERVER__PORT", port.to_string())
.env("PF__DB__PATH_DIR", db_path)
Expand Down Expand Up @@ -84,7 +84,7 @@ impl CliTestContext {

pub async fn upload_dummy_file(&self) -> anyhow::Result<(FileUrlPath, String)> {
let (file, content) = self.create_dummy_file().await?;
let output = tokio::process::Command::new("target/debug/cli")
let output = tokio::process::Command::new("target/debug/pf-cli")
.args([
"--server-addr",
&self.server_addr,
Expand Down Expand Up @@ -125,7 +125,7 @@ async fn find_free_port() -> anyhow::Result<u16> {
}

async fn ping(root_dir: &Path, server_addr: &str) -> Result<ExitStatus, io::Error> {
tokio::process::Command::new("target/debug/cli")
tokio::process::Command::new("target/debug/pf-cli")
.args(["--server-addr", server_addr, "ping"])
.current_dir(root_dir)
.stderr(Stdio::null())
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/cli/info_cli_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::helper::CliTestContext;
#[tokio::test]
async fn test_upload_and_info_command(ctx: &mut CliTestContext) {
let (url_path, _) = ctx.upload_dummy_file().await.unwrap();
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/cli/ping_cli_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::helper::CliTestContext;
#[test_context::test_context(CliTestContext)]
#[tokio::test]
async fn test_ping_command(ctx: &mut CliTestContext) {
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args(["--server-addr", &ctx.server_addr, "ping"])
.assert()
Expand Down
18 changes: 9 additions & 9 deletions cli/tests/cli/upload_and_download_cli_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::helper::{generate_random_key_nonce, CliTestContext};
#[tokio::test]
async fn test_upload_and_download_command_with_progress_bar(ctx: &mut CliTestContext) {
let (file, expected_content) = ctx.create_dummy_file().await.unwrap();
let url_path = Command::cargo_bin("cli")
let url_path = Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -25,7 +25,7 @@ async fn test_upload_and_download_command_with_progress_bar(ctx: &mut CliTestCon
let url_path = std::str::from_utf8(&url_path).unwrap().trim();
let destination_dir = ctx.workspace.join("destination_dir");
tokio::fs::create_dir_all(&destination_dir).await.unwrap();
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -51,7 +51,7 @@ async fn test_upload_and_download_command_with_progress_bar(ctx: &mut CliTestCon
#[tokio::test]
async fn test_upload_and_download_command_to_the_destination_dir(ctx: &mut CliTestContext) {
let (file, expected_content) = ctx.create_dummy_file().await.unwrap();
let url_path = Command::cargo_bin("cli")
let url_path = Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -68,7 +68,7 @@ async fn test_upload_and_download_command_to_the_destination_dir(ctx: &mut CliTe
let url_path = std::str::from_utf8(&url_path).unwrap().trim();
let destination_dir = ctx.workspace.join("destination_dir");
tokio::fs::create_dir_all(&destination_dir).await.unwrap();
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand Down Expand Up @@ -96,7 +96,7 @@ async fn test_upload_encrypt_and_download_decrypt_command_to_the_destination_dir
) {
let key_nonce = generate_random_key_nonce();
let (file, expected_content) = ctx.create_dummy_file().await.unwrap();
let url_path = Command::cargo_bin("cli")
let url_path = Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -118,7 +118,7 @@ async fn test_upload_encrypt_and_download_decrypt_command_to_the_destination_dir

let destination_dir = ctx.workspace.join("destination_dir");
tokio::fs::create_dir_all(&destination_dir).await.unwrap();
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand Down Expand Up @@ -150,7 +150,7 @@ async fn test_upload_encrypt_and_download_decrypt_command_to_the_destination_dir
async fn test_upload_and_download_command_to_the_destination_file(ctx: &mut CliTestContext) {
let (url_path, expected_content) = ctx.upload_dummy_file().await.unwrap();
let destination_file_path = ctx.workspace.join("destination_file.text");
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -177,7 +177,7 @@ async fn test_upload_encrypt_and_download_decrypt_command_to_the_destination_fil
) {
let key_nonce = generate_random_key_nonce();
let (file, expected_content) = ctx.create_dummy_file().await.unwrap();
let url_path = Command::cargo_bin("cli")
let url_path = Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand All @@ -197,7 +197,7 @@ async fn test_upload_encrypt_and_download_decrypt_command_to_the_destination_fil
assert!(!tokio::fs::try_exists(encrypt_file).await.unwrap());
let url_path = std::str::from_utf8(&url_path).unwrap().trim();
let destination_file_path = ctx.workspace.join("destination_file.txt");
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/cli/upload_cli_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::helper::CliTestContext;
#[tokio::test]
async fn test_upload_command(ctx: &mut CliTestContext) {
let (file, _) = ctx.create_dummy_file().await.unwrap();
Command::cargo_bin("cli")
Command::cargo_bin("pf-cli")
.unwrap()
.args([
"--server-addr",
Expand Down
3 changes: 2 additions & 1 deletion scripts/rm-test-dump.sh → scripts/clean-test-dump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
rm -rf test-dump
rm -rf api/test-dump
rm -rf tmp/
rm -rf tmp/
rm -rf target/

0 comments on commit b03ff1a

Please sign in to comment.