From f62034f90a0832741d9d33c476734ff7d99c2213 Mon Sep 17 00:00:00 2001 From: l0r1s <contact@lorismoulin.com> Date: Mon, 25 Sep 2023 16:43:55 +0300 Subject: [PATCH] feat: added error test for namespace spawn_node method on NativerProvider, fixed node run_command test to be platform agnostic --- crates/provider/src/native.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/provider/src/native.rs b/crates/provider/src/native.rs index 353bcac..7b7a717 100644 --- a/crates/provider/src/native.rs +++ b/crates/provider/src/native.rs @@ -877,6 +877,38 @@ mod tests { assert!(namespace.nodes().await.get(node.name()).is_some()); } + #[tokio::test] + async fn namespace_spawn_node_method_should_returns_an_error_if_a_node_already_exists_with_this_name( + ) { + let fs = InMemoryFileSystem::new(HashMap::from([ + (OsString::from_str("/").unwrap(), InMemoryFile::dir()), + (OsString::from_str("/tmp").unwrap(), InMemoryFile::dir()), + ])); + let provider = NativeProvider::new(fs.clone()); + let namespace = provider.create_namespace().await.unwrap(); + + namespace + .spawn_node(SpawnNodeOptions::new( + "mynode", + "/home/user/Work/parity/zombienet-sdk/crates/provider/testing/dummy_node", + )) + .await + .unwrap(); + + let result = namespace + .spawn_node(SpawnNodeOptions::new( + "mynode", + "/home/user/Work/parity/zombienet-sdk/crates/provider/testing/dummy_node", + )) + .await; + + // we must match here because Arc<dyn Node + Send + Sync> doesn't implements Debug, so unwrap_err is not an option + match result { + Ok(_) => panic!("expected result to be an error"), + Err(err) => assert_eq!(err.to_string(), "Duplicated node name: mynode"), + }; + } + #[tokio::test] async fn namespace_generate_files_method_should_create_files_at_the_correct_locations_using_given_commands( ) { @@ -1105,7 +1137,7 @@ mod tests { .await; assert!( - matches!(result, Ok(Err((exit_code, stderr))) if !exit_code.success() && stderr == "sh: 0: Illegal option -k\n") + matches!(result, Ok(Err((exit_code, stderr))) if !exit_code.success() && stderr.len() > 0) ); } -- GitLab