refactor(test): clean up CLI test helpers and improve code clarity
Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
This commit is contained in:
parent
f98ac3f87d
commit
d290ac8528
2 changed files with 9 additions and 12 deletions
|
|
@ -4,16 +4,13 @@ use std::sync::Mutex;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
/// Shared test server state
|
/// Shared test server state - kept alive for the duration of all tests
|
||||||
struct SharedServer {
|
struct SharedServer {
|
||||||
address: String,
|
address: String,
|
||||||
admin_password: String,
|
admin_password: String,
|
||||||
#[allow(dead_code)]
|
_db_url: String,
|
||||||
db_url: String,
|
_temp_dir: TempDir,
|
||||||
#[allow(dead_code)]
|
_process: std::process::Child,
|
||||||
temp_dir: TempDir,
|
|
||||||
#[allow(dead_code)]
|
|
||||||
process: std::process::Child,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Single shared test server for all CLI tests
|
/// Single shared test server for all CLI tests
|
||||||
|
|
@ -106,9 +103,9 @@ fn ensure_server_started() -> Result<(String, String), String> {
|
||||||
*server = Some(SharedServer {
|
*server = Some(SharedServer {
|
||||||
address: address.clone(),
|
address: address.clone(),
|
||||||
admin_password: admin_password.to_string(),
|
admin_password: admin_password.to_string(),
|
||||||
db_url,
|
_db_url: db_url,
|
||||||
temp_dir,
|
_temp_dir: temp_dir,
|
||||||
process,
|
_process: process,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ fn test_add_roaster_with_authentication() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||||
let roaster: Value =
|
let roaster: Value = serde_json::from_str(&stdout)
|
||||||
serde_json::from_str(&stdout).expect(&format!("Should output valid JSON, got: {}", stdout));
|
.unwrap_or_else(|_| panic!("Should output valid JSON, got: {}", stdout));
|
||||||
|
|
||||||
assert_eq!(roaster["name"], "Test Roasters");
|
assert_eq!(roaster["name"], "Test Roasters");
|
||||||
assert_eq!(roaster["country"], "UK");
|
assert_eq!(roaster["country"], "UK");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue