-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(commands): add integration test (install/uninstall) (#190)
* test(commands): add integration tests for uninstall * test(commands): add integration test for config in foundry file * test(commands): add test for remappings in foundry file * test(commands): add uninstall test with foundry config
- Loading branch information
Showing
2 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use soldeer_commands::{ | ||
commands::{install::Install, uninstall::Uninstall}, | ||
run, Command, | ||
}; | ||
use soldeer_core::{config::read_config_deps, lock::read_lockfile}; | ||
use std::{fs, path::PathBuf}; | ||
use temp_env::async_with_vars; | ||
use testdir::testdir; | ||
|
||
async fn setup(config_filename: &str) -> PathBuf { | ||
let dir = testdir!(); | ||
let mut contents = r#"[dependencies] | ||
"@openzeppelin-contracts" = "5.0.2" | ||
solady = "0.0.238" | ||
"# | ||
.to_string(); | ||
if config_filename == "foundry.toml" { | ||
contents = format!( | ||
r#"[profile.default] | ||
[soldeer] | ||
remappings_location = "config" | ||
{contents}"# | ||
); | ||
} | ||
fs::write(dir.join(config_filename), contents).unwrap(); | ||
let cmd: Command = Install::default().into(); | ||
let res = | ||
async_with_vars([("SOLDEER_PROJECT_ROOT", Some(dir.to_string_lossy().as_ref()))], run(cmd)) | ||
.await; | ||
assert!(res.is_ok(), "{res:?}"); | ||
dir | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_uninstall_one() { | ||
let dir = setup("soldeer.toml").await; | ||
let cmd: Command = Uninstall { dependency: "solady".to_string() }.into(); | ||
let res = | ||
async_with_vars([("SOLDEER_PROJECT_ROOT", Some(dir.to_string_lossy().as_ref()))], run(cmd)) | ||
.await; | ||
assert!(res.is_ok(), "{res:?}"); | ||
let deps = read_config_deps(dir.join("soldeer.toml")).unwrap(); | ||
assert!(!deps.iter().any(|d| d.name() == "solady")); | ||
let remappings = fs::read_to_string(dir.join("remappings.txt")).unwrap(); | ||
assert!(!remappings.contains("solady")); | ||
let lock = read_lockfile(dir.join("soldeer.lock")).unwrap(); | ||
assert!(!lock.entries.iter().any(|d| d.name() == "solady")); | ||
assert!(!dir.join("dependencies").join("solady-0.0.238").exists()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_uninstall_all() { | ||
let dir = setup("soldeer.toml").await; | ||
let cmd: Command = Uninstall { dependency: "solady".to_string() }.into(); | ||
let res = | ||
async_with_vars([("SOLDEER_PROJECT_ROOT", Some(dir.to_string_lossy().as_ref()))], run(cmd)) | ||
.await; | ||
assert!(res.is_ok(), "{res:?}"); | ||
let cmd: Command = Uninstall { dependency: "@openzeppelin-contracts".to_string() }.into(); | ||
let res = | ||
async_with_vars([("SOLDEER_PROJECT_ROOT", Some(dir.to_string_lossy().as_ref()))], run(cmd)) | ||
.await; | ||
assert!(res.is_ok(), "{res:?}"); | ||
|
||
let deps = read_config_deps(dir.join("soldeer.toml")).unwrap(); | ||
assert!(deps.is_empty()); | ||
let remappings = fs::read_to_string(dir.join("remappings.txt")).unwrap(); | ||
assert_eq!(remappings, ""); | ||
assert!(!dir.join("soldeer.lock").exists()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_uninstall_foundry_config() { | ||
let dir = setup("foundry.toml").await; | ||
let cmd: Command = Uninstall { dependency: "solady".to_string() }.into(); | ||
let res = | ||
async_with_vars([("SOLDEER_PROJECT_ROOT", Some(dir.to_string_lossy().as_ref()))], run(cmd)) | ||
.await; | ||
assert!(res.is_ok(), "{res:?}"); | ||
let deps = read_config_deps(dir.join("foundry.toml")).unwrap(); | ||
assert!(!deps.iter().any(|d| d.name() == "solady")); | ||
let config = fs::read_to_string(dir.join("foundry.toml")).unwrap(); | ||
assert!(!config.contains("solady")); | ||
} |