Add source orchestration contract tests

This commit is contained in:
andrussal 2026-03-08 15:14:47 +01:00
parent 6405d31ebd
commit feeafa4eaf

View File

@ -69,7 +69,19 @@ impl SourceOrchestrationPlan {
#[cfg(test)]
mod tests {
use super::{SourceOrchestrationMode, SourceOrchestrationPlan};
use crate::scenario::{ExistingCluster, sources::ScenarioSources};
use crate::scenario::{ExistingCluster, ExternalNodeSource, sources::ScenarioSources};
#[test]
fn managed_sources_are_planned() {
let plan = SourceOrchestrationPlan::try_from_sources(&ScenarioSources::default())
.expect("managed sources should build a source orchestration plan");
assert!(matches!(
plan.mode(),
SourceOrchestrationMode::Managed { .. }
));
assert!(plan.external_sources().is_empty());
}
#[test]
fn attached_sources_are_planned() {
@ -86,6 +98,46 @@ mod tests {
SourceOrchestrationMode::Attached { .. }
));
}
#[test]
fn attached_sources_keep_external_nodes() {
let sources = ScenarioSources::default()
.with_attach(ExistingCluster::for_compose_project(
"test-project".to_string(),
))
.with_external_node(ExternalNodeSource::new(
"external-0".to_owned(),
"http://127.0.0.1:1".to_owned(),
));
let plan = SourceOrchestrationPlan::try_from_sources(&sources)
.expect("attached sources with external nodes should build");
assert!(matches!(
plan.mode(),
SourceOrchestrationMode::Attached { .. }
));
assert_eq!(plan.external_sources().len(), 1);
assert_eq!(plan.external_sources()[0].label(), "external-0");
}
#[test]
fn external_only_sources_are_planned() {
let sources = ScenarioSources::default()
.with_external_node(ExternalNodeSource::new(
"external-0".to_owned(),
"http://127.0.0.1:1".to_owned(),
))
.into_external_only();
let plan = SourceOrchestrationPlan::try_from_sources(&sources)
.expect("external-only sources should build a source orchestration plan");
assert!(matches!(
plan.mode(),
SourceOrchestrationMode::ExternalOnly { .. }
));
assert_eq!(plan.external_sources().len(), 1);
assert_eq!(plan.external_sources()[0].label(), "external-0");
}
}
fn mode_from_sources(sources: &ScenarioSources) -> SourceOrchestrationMode {