mirror of
https://github.com/13hannes11/toolbx-tuner.git
synced 2024-09-03 23:21:00 +02:00
fix failing test
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fmt::Display, iter::zip, process::Command, str::FromStr, string::ParseError, sync::Arc};
|
use std::{fmt::Display, iter::zip, process::Command, str::FromStr, string::ParseError, sync::Arc};
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum ToolbxError {
|
pub enum ToolbxError {
|
||||||
@@ -101,27 +101,20 @@ impl ToolbxContainer {
|
|||||||
parse_cmd_list_containers(output.as_str())
|
parse_cmd_list_containers(output.as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_status(output : &str) -> Result<PodmanInspectInfo, ToolbxError> {
|
fn parse_status(output: &str) -> Result<PodmanInspectInfo, ToolbxError> {
|
||||||
let result : Result<PodmanInspectArray, _> = serde_json::from_str(output);
|
let result: Result<PodmanInspectArray, _> = serde_json::from_str(output);
|
||||||
match result {
|
match result {
|
||||||
Ok(inspect_vec) => {
|
Ok(inspect_vec) => match inspect_vec.first() {
|
||||||
match inspect_vec.first() {
|
Some(info) => Ok(info.clone()),
|
||||||
Some(info) => {
|
None => Err(ToolbxError::JSONSerializationError(
|
||||||
Ok(info.clone())
|
"Inspect command returned empty vecotr.".to_string(),
|
||||||
}
|
)),
|
||||||
None => {
|
},
|
||||||
Err(ToolbxError::JSONSerializationError("Inspect command returned empty vecotr.".to_string()))
|
Err(e) => Err(ToolbxError::JSONSerializationError(e.to_string())),
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
Err(ToolbxError::JSONSerializationError(e.to_string()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
pub fn update_status(&mut self) -> Result<(), ToolbxError> {
|
||||||
|
|
||||||
pub fn update_status(&mut self) -> Result<(), ToolbxError>{
|
|
||||||
let output = Command::new("podman")
|
let output = Command::new("podman")
|
||||||
.arg("container")
|
.arg("container")
|
||||||
.arg("inspect")
|
.arg("inspect")
|
||||||
@@ -228,15 +221,22 @@ fn test_inspect_parsing() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_start_non_existing_containter() {
|
fn test_start_non_existing_containter() {
|
||||||
|
let name = "zy2lM6BdZoTnKHaVPkUJ".to_string();
|
||||||
let mut tbx = ToolbxContainer {
|
let mut tbx = ToolbxContainer {
|
||||||
created: "".to_string(),
|
created: "".to_string(),
|
||||||
id: "".to_string(),
|
id: "".to_string(),
|
||||||
name: "zy2lM6BdZoTnKHaVPkUJ".to_string(),
|
name: name.clone(),
|
||||||
image: "".to_string(),
|
image: "".to_string(),
|
||||||
status: ToolbxStatus::Exited,
|
status: ToolbxStatus::Exited,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(Ok(()), tbx.start());
|
assert_eq!(
|
||||||
|
Err(ToolbxError::CommandUnsuccessfulError(format!(
|
||||||
|
"Error: no container with name or ID \"{}\" found: no such container\n",
|
||||||
|
name
|
||||||
|
))),
|
||||||
|
tbx.start()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_cmd_toolbx_list_containers() -> String {
|
pub fn run_cmd_toolbx_list_containers() -> String {
|
||||||
|
|||||||
Reference in New Issue
Block a user