WP-12: contract and failing tests for the Kubernetes overview
Some checks failed
CI / backend (push) Has been cancelled
CI / frontend (push) Has been cancelled
CI / ui (push) Has been cancelled

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Dennis Nemec
2026-09-02 22:29:36 +02:00
parent 684695e71a
commit 51ec216910
14 changed files with 922 additions and 0 deletions

View File

@ -0,0 +1,91 @@
use std::sync::Arc;
use domain::cluster::{WorkloadKind, WorkloadRef};
use domain::DomainError;
use crate::test_fakes::MemCluster;
use crate::ClusterService;
fn gitea() -> WorkloadRef {
WorkloadRef {
namespace: "gitea".into(),
kind: WorkloadKind::Deployment,
name: "gitea".into(),
}
}
fn svc() -> (Arc<MemCluster>, ClusterService) {
let gw = Arc::new(MemCluster::default());
(gw.clone(), ClusterService::new(gw))
}
#[tokio::test]
async fn overview_lists_workloads_and_distinct_images() {
let (_, s) = svc();
let o = s.overview().await.unwrap();
assert_eq!(o.workloads.len(), 2);
assert_eq!(
o.images(),
vec!["bitnami/postgresql:16.4.0", "gitea/gitea:1.22.3"]
);
}
#[tokio::test]
async fn restart_and_scale_are_forwarded_with_validation() {
let (gw, s) = svc();
s.restart(gitea()).await.unwrap();
s.scale(gitea(), 2).await.unwrap();
assert!(matches!(
s.scale(gitea(), -1).await.unwrap_err(),
DomainError::Validation(_)
));
assert!(matches!(
s.scale(gitea(), 999).await.unwrap_err(),
DomainError::Validation(_)
));
let bad = WorkloadRef {
namespace: "Bad Name".into(),
..gitea()
};
assert!(matches!(
s.restart(bad).await.unwrap_err(),
DomainError::Validation(_)
));
assert_eq!(
*gw.actions.lock().unwrap(),
vec![
"restart gitea/deployment/gitea",
"scale gitea/deployment/gitea 2"
]
);
}
#[tokio::test]
async fn set_image_defaults_to_the_first_container_and_validates_image() {
let (gw, s) = svc();
s.set_image(gitea(), None, "gitea/gitea:1.23.0")
.await
.unwrap();
s.set_image(gitea(), Some("sidecar".into()), "x/y:1")
.await
.unwrap();
assert!(matches!(
s.set_image(gitea(), None, "has space").await.unwrap_err(),
DomainError::Validation(_)
));
let unknown = WorkloadRef {
name: "nope".into(),
..gitea()
};
assert_eq!(
s.set_image(unknown, None, "x/y:1").await.unwrap_err(),
DomainError::NotFound
);
assert_eq!(
*gw.actions.lock().unwrap(),
vec![
"image gitea/deployment/gitea gitea=gitea/gitea:1.23.0",
"image gitea/deployment/gitea sidecar=x/y:1"
]
);
}

View File

@ -1,4 +1,5 @@
mod auth_service_tests;
mod cluster_tests;
mod inventory_tests;
mod jobs_tests;
mod scheduler_tests;