90 lines
2.5 KiB
Rust
90 lines
2.5 KiB
Rust
|
|
//! Unit tests for `ComputeError` `Display` impls and variant structure.
|
||
|
|
|
||
|
|
use std::time::Duration;
|
||
|
|
|
||
|
|
use ontoref_compute::{ComputeError, InstanceHandle};
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn spawn_error_display() {
|
||
|
|
let e = ComputeError::Spawn("hcloud returned 422".into());
|
||
|
|
assert!(e.to_string().contains("spawn failed"));
|
||
|
|
assert!(e.to_string().contains("hcloud returned 422"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn destroy_error_display() {
|
||
|
|
let e = ComputeError::Destroy("timeout during delete".into());
|
||
|
|
assert!(e.to_string().contains("destroy failed"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn status_error_display() {
|
||
|
|
let e = ComputeError::Status("describe returned 500".into());
|
||
|
|
assert!(e.to_string().contains("status query failed"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn list_error_display() {
|
||
|
|
let e = ComputeError::List("JSON parse error".into());
|
||
|
|
assert!(e.to_string().contains("list query failed"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn not_found_display_contains_handle() {
|
||
|
|
let h = InstanceHandle::new("hetzner-999999");
|
||
|
|
let e = ComputeError::NotFound(h);
|
||
|
|
assert!(e.to_string().contains("hetzner-999999"));
|
||
|
|
assert!(e.to_string().contains("not found"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn provider_unavailable_display() {
|
||
|
|
let e = ComputeError::ProviderUnavailable("connection refused".into());
|
||
|
|
assert!(e.to_string().contains("provider unavailable"));
|
||
|
|
assert!(e.to_string().contains("connection refused"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn timeout_display_contains_duration() {
|
||
|
|
let e = ComputeError::Timeout(Duration::from_secs(30));
|
||
|
|
let s = e.to_string();
|
||
|
|
assert!(s.contains("timeout"), "got: {s}");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn invalid_spec_display() {
|
||
|
|
let e = ComputeError::InvalidSpec("location required".into());
|
||
|
|
assert!(e.to_string().contains("invalid spec"));
|
||
|
|
assert!(e.to_string().contains("location required"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn auth_error_display() {
|
||
|
|
let e = ComputeError::Auth("HCLOUD_TOKEN not set".into());
|
||
|
|
assert!(e.to_string().contains("auth error"));
|
||
|
|
assert!(e.to_string().contains("HCLOUD_TOKEN"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn out_of_memory_display_contains_handle_and_size() {
|
||
|
|
let e = ComputeError::OutOfMemory {
|
||
|
|
handle: InstanceHandle::new("hetzner-12345"),
|
||
|
|
size_mb: 8_192,
|
||
|
|
};
|
||
|
|
let s = e.to_string();
|
||
|
|
assert!(s.contains("hetzner-12345"), "got: {s}");
|
||
|
|
assert!(s.contains("8192"), "got: {s}");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn catalog_error_display() {
|
||
|
|
let e = ComputeError::Catalog("oras pull failed: 401".into());
|
||
|
|
assert!(e.to_string().contains("catalog error"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn internal_error_display() {
|
||
|
|
let e = ComputeError::Internal("unexpected response tag".into());
|
||
|
|
assert!(e.to_string().contains("provider internal error"));
|
||
|
|
}
|