-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #673 from Szymongib/cleanup/remove-cmd-dup-in-tests
Remove duplication from commands execution in Integration tests
- Loading branch information
Showing
7 changed files
with
59 additions
and
100 deletions.
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
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 |
---|---|---|
@@ -1,41 +1,24 @@ | ||
use crate::utils::get_runtime_path; | ||
use std::io; | ||
use crate::utils::get_state; | ||
use anyhow::{anyhow, Result}; | ||
use std::path::Path; | ||
use std::process::{Command, Stdio}; | ||
use test_framework::TestResult; | ||
|
||
pub fn state(project_path: &Path, id: &str) -> TestResult { | ||
let res = Command::new(get_runtime_path()) | ||
.stdout(Stdio::piped()) | ||
.stderr(Stdio::piped()) | ||
.arg("--root") | ||
.arg(project_path.join("runtime")) | ||
.arg("state") | ||
.arg(id) | ||
.spawn() | ||
.expect("failed to execute state command") | ||
.wait_with_output(); | ||
match res { | ||
io::Result::Ok(output) => { | ||
let stderr = String::from_utf8(output.stderr).unwrap(); | ||
let stdout = String::from_utf8(output.stdout).unwrap(); | ||
match get_state(id, project_path) { | ||
Result::Ok((stdout, stderr)) => { | ||
if stderr.contains("Error") || stderr.contains("error") { | ||
TestResult::Failed(anyhow::anyhow!( | ||
"Error :\nstdout : {}\nstderr : {}", | ||
stdout, | ||
stderr | ||
)) | ||
TestResult::Failed(anyhow!("Error :\nstdout : {}\nstderr : {}", stdout, stderr)) | ||
} else { | ||
// confirm that the status is stopped, as this is executed after the kill command | ||
if !(stdout.contains(&format!(r#""id": "{}""#, id)) | ||
&& stdout.contains(r#""status": "stopped""#)) | ||
{ | ||
TestResult::Failed(anyhow::anyhow!("Expected state stopped, got : {}", stdout)) | ||
TestResult::Failed(anyhow!("Expected state stopped, got : {}", stdout)) | ||
} else { | ||
TestResult::Passed | ||
} | ||
} | ||
} | ||
io::Result::Err(e) => TestResult::Failed(anyhow::Error::new(e)), | ||
Result::Err(e) => TestResult::Failed(e.context("failed to get container state")), | ||
} | ||
} |
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
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