Skip to content

Commit

Permalink
a simple test for validation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lXXXw authored and facebook-github-bot committed Nov 23, 2024
1 parent 37dbbcd commit 428b52b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions eden/fs/cli_rs/edenfs-commands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions eden/fs/cli_rs/edenfs-commands/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions eden/fs/cli_rs/edenfs-commands/src/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -333,6 +334,10 @@ async fn validate_state_run(context: &mut RemoveContext) -> Result<Option<State>
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() {
Expand Down
10 changes: 10 additions & 0 deletions eden/scm/tests/test-eden-remove.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 428b52b

Please sign in to comment.