refactor: Refactored all cli tests to use purpose-built assertions
This commit is contained in:
@@ -42,14 +42,14 @@ mod tests {
|
||||
) {
|
||||
let result = Cli::command().try_get_matches_from(["managarr", "sonarr", "list", subcommand]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_episodes_requires_series_id() {
|
||||
let result = Cli::command().try_get_matches_from(["managarr", "sonarr", "list", "episodes"]);
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
@@ -61,7 +61,7 @@ mod tests {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "sonarr", "list", "episode-files"]);
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
@@ -73,7 +73,7 @@ mod tests {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "sonarr", "list", "episode-history"]);
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
@@ -92,13 +92,14 @@ mod tests {
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
|
||||
if let Some(Command::Sonarr(SonarrCommand::List(episode_history_command))) =
|
||||
let Some(Command::Sonarr(SonarrCommand::List(episode_history_command))) =
|
||||
result.unwrap().command
|
||||
{
|
||||
assert_eq!(episode_history_command, expected_args);
|
||||
}
|
||||
else {
|
||||
panic!("Unexpected command type");
|
||||
};
|
||||
assert_eq!(episode_history_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -106,7 +107,7 @@ mod tests {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "sonarr", "list", "downloads", "--count"]);
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_err!(&result);
|
||||
assert_eq!(result.unwrap_err().kind(), ErrorKind::InvalidValue);
|
||||
}
|
||||
|
||||
@@ -115,12 +116,13 @@ mod tests {
|
||||
let expected_args = SonarrListCommand::Downloads { count: 500 };
|
||||
let result = Cli::try_parse_from(["managarr", "sonarr", "list", "downloads"]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
|
||||
if let Some(Command::Sonarr(SonarrCommand::List(downloads_command))) = result.unwrap().command
|
||||
{
|
||||
assert_eq!(downloads_command, expected_args);
|
||||
}
|
||||
let Some(Command::Sonarr(SonarrCommand::List(downloads_command))) = result.unwrap().command
|
||||
else {
|
||||
panic!("Unexpected command type");
|
||||
};
|
||||
assert_eq!(downloads_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -128,7 +130,7 @@ mod tests {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "sonarr", "list", "history", "--events"]);
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_err!(&result);
|
||||
assert_eq!(result.unwrap_err().kind(), ErrorKind::InvalidValue);
|
||||
}
|
||||
|
||||
@@ -137,11 +139,13 @@ mod tests {
|
||||
let expected_args = SonarrListCommand::History { events: 500 };
|
||||
let result = Cli::try_parse_from(["managarr", "sonarr", "list", "history"]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
|
||||
if let Some(Command::Sonarr(SonarrCommand::List(history_command))) = result.unwrap().command {
|
||||
assert_eq!(history_command, expected_args);
|
||||
}
|
||||
let Some(Command::Sonarr(SonarrCommand::List(history_command))) = result.unwrap().command
|
||||
else {
|
||||
panic!("Unexpected command type");
|
||||
};
|
||||
assert_eq!(history_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -149,7 +153,7 @@ mod tests {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "sonarr", "list", "logs", "--events"]);
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_err!(&result);
|
||||
assert_eq!(result.unwrap_err().kind(), ErrorKind::InvalidValue);
|
||||
}
|
||||
|
||||
@@ -161,11 +165,12 @@ mod tests {
|
||||
};
|
||||
let result = Cli::try_parse_from(["managarr", "sonarr", "list", "logs"]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
|
||||
if let Some(Command::Sonarr(SonarrCommand::List(logs_command))) = result.unwrap().command {
|
||||
assert_eq!(logs_command, expected_args);
|
||||
}
|
||||
let Some(Command::Sonarr(SonarrCommand::List(logs_command))) = result.unwrap().command else {
|
||||
panic!("Unexpected command type");
|
||||
};
|
||||
assert_eq!(logs_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -174,12 +179,13 @@ mod tests {
|
||||
let result =
|
||||
Cli::try_parse_from(["managarr", "sonarr", "list", "episodes", "--series-id", "1"]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
|
||||
if let Some(Command::Sonarr(SonarrCommand::List(episodes_command))) = result.unwrap().command
|
||||
{
|
||||
assert_eq!(episodes_command, expected_args);
|
||||
}
|
||||
let Some(Command::Sonarr(SonarrCommand::List(episodes_command))) = result.unwrap().command
|
||||
else {
|
||||
panic!("Unexpected command type");
|
||||
};
|
||||
assert_eq!(episodes_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -194,13 +200,14 @@ mod tests {
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
|
||||
if let Some(Command::Sonarr(SonarrCommand::List(episode_files_command))) =
|
||||
let Some(Command::Sonarr(SonarrCommand::List(episode_files_command))) =
|
||||
result.unwrap().command
|
||||
{
|
||||
assert_eq!(episode_files_command, expected_args);
|
||||
}
|
||||
else {
|
||||
panic!("Unexpected command type");
|
||||
};
|
||||
assert_eq!(episode_files_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -214,7 +221,7 @@ mod tests {
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
@@ -232,7 +239,7 @@ mod tests {
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
@@ -252,7 +259,7 @@ mod tests {
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -260,7 +267,7 @@ mod tests {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "sonarr", "list", "series-history"]);
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
@@ -279,11 +286,13 @@ mod tests {
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
|
||||
if let Some(Command::Sonarr(SonarrCommand::List(series_command))) = result.unwrap().command {
|
||||
assert_eq!(series_command, expected_args);
|
||||
}
|
||||
let Some(Command::Sonarr(SonarrCommand::List(series_command))) = result.unwrap().command
|
||||
else {
|
||||
panic!("Unexpected command type");
|
||||
};
|
||||
assert_eq!(series_command, expected_args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,7 +348,7 @@ mod tests {
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -365,7 +374,7 @@ mod tests {
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -391,7 +400,7 @@ mod tests {
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -417,7 +426,7 @@ mod tests {
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -443,7 +452,7 @@ mod tests {
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -471,7 +480,7 @@ mod tests {
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -497,7 +506,7 @@ mod tests {
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -523,7 +532,7 @@ mod tests {
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -553,7 +562,7 @@ mod tests {
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_ok!(&result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user