From 428b52be0a9900947ce7d052b36e5ed74f4b4ea5 Mon Sep 17 00:00:00 2001 From: Xiaowei Lu Date: Fri, 22 Nov 2024 17:51:41 -0800 Subject: [PATCH] a simple test for validation Summary: ## Context When migrating from Python cli to Rust, one of the focuses is testing. In the previous diff we refactored failpoint crate and introduced it into eden code. ## This Diff Used failpoint create to add fail points in validation state so we can test validation failures from dot t tests. Reviewed By: sggutier Differential Revision: D66350826 fbshipit-source-id: 2b9b5d987d5f55f6cf2b365d08907a60523b6cf3 --- eden/fs/cli_rs/edenfs-commands/Cargo.toml | 1 + eden/fs/cli_rs/edenfs-commands/TARGETS | 1 + eden/fs/cli_rs/edenfs-commands/src/remove.rs | 5 +++++ eden/scm/tests/test-eden-remove.t | 10 ++++++++++ 4 files changed, 17 insertions(+) diff --git a/eden/fs/cli_rs/edenfs-commands/Cargo.toml b/eden/fs/cli_rs/edenfs-commands/Cargo.toml index 3a94a85145ce4..9a629cd3763e4 100644 --- a/eden/fs/cli_rs/edenfs-commands/Cargo.toml +++ b/eden/fs/cli_rs/edenfs-commands/Cargo.toml @@ -20,6 +20,7 @@ dunce = "1.0.2" edenfs-client = { version = "0.1.0", path = "../edenfs-client" } edenfs-error = { version = "0.1.0", path = "../edenfs-error" } edenfs-utils = { version = "0.1.0", path = "../edenfs-utils" } +fail = { version = "0.4", features = ["failpoints"] } futures = { version = "0.3.30", features = ["async-await", "compat"] } hex = "0.4.3" hg_util = { package = "sapling-util", version = "0.1.0", path = "../../../scm/lib/util" } diff --git a/eden/fs/cli_rs/edenfs-commands/TARGETS b/eden/fs/cli_rs/edenfs-commands/TARGETS index 1e90402ee268c..1056a6dc149ca 100644 --- a/eden/fs/cli_rs/edenfs-commands/TARGETS +++ b/eden/fs/cli_rs/edenfs-commands/TARGETS @@ -35,6 +35,7 @@ rust_library( "fbsource//third-party/rust:dialoguer", "fbsource//third-party/rust:dirs", "fbsource//third-party/rust:dunce", + "fbsource//third-party/rust:fail", "fbsource//third-party/rust:futures", "fbsource//third-party/rust:hex", "fbsource//third-party/rust:once_cell", diff --git a/eden/fs/cli_rs/edenfs-commands/src/remove.rs b/eden/fs/cli_rs/edenfs-commands/src/remove.rs index a051c82b16544..fcd7de7db8d10 100644 --- a/eden/fs/cli_rs/edenfs-commands/src/remove.rs +++ b/eden/fs/cli_rs/edenfs-commands/src/remove.rs @@ -28,6 +28,7 @@ use edenfs_client::checkout::get_mounts; use edenfs_client::fsutil::forcefully_remove_dir_all; use edenfs_client::EdenFsInstance; use edenfs_utils::bytes_from_path; +use fail::fail_point; use io::IO; use termlogger::TermLogger; use tracing::debug; @@ -333,6 +334,10 @@ async fn validate_state_run(context: &mut RemoveContext) -> Result return Err(anyhow!("Repo {} is still mounted", context)); } + fail_point!("remove:validate", |_| { + Err(anyhow!("failpoint: expected failure")) + }); + // check directory clean up if !context.preserve_mount_point { match context.canonical_path.try_exists() { diff --git a/eden/scm/tests/test-eden-remove.t b/eden/scm/tests/test-eden-remove.t index c38a05077e532..708c17791d4c5 100644 --- a/eden/scm/tests/test-eden-remove.t +++ b/eden/scm/tests/test-eden-remove.t @@ -59,3 +59,13 @@ check to make sure the mount point is cleanly removed $ ls $TESTTMP/wcrepo ls: $TESTTMP/wcrepo: $ENOENT$ [1] + +reclone a repo for testing validation error + $ eden clone --allow-empty-repo $TESTTMP/backingrepo $TESTTMP/wcrepo + Cloning new repository at $TESTTMP/wcrepo... + Success. Checked out commit 00000000 + +remove with failpoint set so the validation step will fail + $ FAILPOINTS=remove:validate=return EDENFSCTL_ONLY_RUST=true eden remove -q -y $TESTTMP/wcrepo/ + Error: failpoint: expected failure + [1]