Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zombienet-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
zombienet-sdk
Commits
34a2c5a1
Verified
Commit
34a2c5a1
authored
1 year ago
by
Loris Moulin
Browse files
Options
Downloads
Patches
Plain Diff
feat: added happy path testing for native node run_script method
parent
2d8222d6
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
crates/provider/src/native.rs
+37
-43
37 additions, 43 deletions
crates/provider/src/native.rs
with
37 additions
and
43 deletions
crates/provider/src/native.rs
+
37
−
43
View file @
34a2c5a1
...
...
@@ -601,7 +601,7 @@ fn create_process_with_log_tasks(
#[cfg(test)]
mod
tests
{
use
std
::{
ffi
::
OsString
,
str
::
FromStr
,
fs
};
use
std
::{
ffi
::
OsString
,
fs
,
str
::
FromStr
};
use
procfs
::
process
::
Process
;
use
support
::
fs
::
in_memory
::{
InMemoryFile
,
InMemoryFileSystem
};
...
...
@@ -1170,6 +1170,42 @@ mod tests {
);
}
#[tokio::test]
async
fn
node_run_script_method_should_execute_the_script_successfully_and_returns_stdout
()
{
let
fs
=
InMemoryFileSystem
::
new
(
HashMap
::
from
([
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/tmp"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/tmp/dummy_script"
)
.unwrap
(),
InMemoryFile
::
mirror
(
"/tmp/dummy_script"
,
fs
::
read_to_string
(
"/home/user/Work/parity/zombienet-sdk/crates/provider/testing/dummy_script"
)
.unwrap
(),
),
),
]));
let
provider
=
NativeProvider
::
new
(
fs
.clone
());
let
namespace
=
provider
.create_namespace
()
.await
.unwrap
();
// spawn dummy node
let
node
=
namespace
.spawn_node
(
SpawnNodeOptions
::
new
(
"mynode"
,
"/home/user/Work/parity/zombienet-sdk/crates/provider/testing/dummy_node"
,
))
.await
.unwrap
();
let
result
=
node
.run_script
(
RunScriptOptions
::
new
(
"/tmp/dummy_script"
)
.args
(
vec!
[
"-c"
])
.env
(
vec!
[(
"MY_ENV_VAR"
,
"With env"
)]),
)
.await
;
assert!
(
matches!
(
result
,
Ok
(
Ok
(
stdout
))
if
stdout
==
"My script
\n
With env
\n
With args
\n
"
));
}
#[tokio::test]
async
fn
node_copy_file_from_node_method_should_copy_node_remote_file_to_local_path
()
{
let
fs
=
InMemoryFileSystem
::
new
(
HashMap
::
from
([
...
...
@@ -1516,48 +1552,6 @@ mod tests {
assert_eq!
(
namespace
.nodes
()
.await
.len
(),
0
);
}
// #[tokio::test]
// async fn node_run_script_method_should_execute_the_script_successfully_and_returns_stdout() {
// // we need to mirror the script between local fs and in memory fs else
// // the tokio::process::Command won't be able to execute it
// fs::copy(
// "/home/user/Work/parity/zombienet-sdk/crates/provider/testing/dummy_script",
// "/tmp/dummy_script",
// )
// .unwrap();
// let fs = InMemoryFileSystem::new(HashMap::from([
// (OsString::from_str("/").unwrap(), InMemoryFile::dir()),
// (OsString::from_str("/tmp").unwrap(), InMemoryFile::dir()),
// (
// OsString::from_str("/tmp/dummy_script").unwrap(),
// InMemoryFile::file(fs::read_to_string("/tmp/dummy_script").unwrap()),
// ),
// ]));
// let provider = NativeProvider::new(fs.clone());
// let namespace = provider.create_namespace().await.unwrap();
// // spawn dummy node
// let node = namespace
// .spawn_node(SpawnNodeOptions::new(
// "mynode",
// "/home/user/Work/parity/zombienet-sdk/crates/provider/testing/dummy_node",
// ))
// .await
// .unwrap();
// let result = node
// .run_script(
// RunScriptOptions::new("/tmp/dummy_script")
// .args(vec!["-c"])
// .env(vec![("MY_ENV_VAR", "Here is my content")]),
// )
// .await;
// println!("{:?}", result);
// // assert!(matches!(result, Ok(Ok(stdout)) if stdout == "Here is my content\n"));
// }
async
fn
get_processes_by_name
(
name
:
&
str
)
->
Vec
<
Process
>
{
procfs
::
process
::
all_processes
()
.unwrap
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment