This commit is contained in:
Mateusz Gruszczyński committed 2026-10-07 08:51:04 +02:00
1 parent a9f9450f80
commit 762eb9e28b
81 files changed
+1242 -1095

No files matched your search

+131
View File
@@ -198,9 +198,140 @@ mod tests {
assert_eq!(assignment.force_ssl, None);
assert!(assignment.websockets);
assert!(!assignment.cache_enabled);
assert_eq!(assignment.compression_enabled, None);
assert_eq!(assignment.compression_zstd, None);
assert_eq!(assignment.compression_br, None);
assert_eq!(assignment.compression_gzip, None);
assert_eq!(assignment.compression_deflate, None);
assert!(!assignment.passive_health.enabled);
}
#[test]
fn published_assignment_stays_routable_as_503_when_service_is_missing() {
let mut desired = crate::config::demo_config("127.0.0.1:9000".parse().unwrap());
desired.vhosts.clear();
desired.docker_agents.agents.push(Agent {
id: "node1".into(),
name: "Node 1".into(),
endpoint: "http://10.0.0.2:9876".into(),
token: "012345678901234567890123".into(),
base_domain: "docker1.lab.local".into(),
listener_ids: vec!["http".into()],
assignments: vec![Assignment {
service_key: "container:app:8080/tcp".into(),
hostname: "app".into(),
compression_enabled: Some(false),
compression_zstd: Some(false),
..Default::default()
}],
..Default::default()
});
let mut observed = observation(service(), vec![]);
observed.get_mut("node1").unwrap().inventory.as_mut().unwrap().services.clear();
let effective = effective_config(desired, &observed).unwrap();
assert_eq!(effective.vhosts.len(), 1);
assert!(effective.vhosts[0].backends.is_empty());
assert!(effective.vhosts[0].transient_unavailable);
assert_eq!(effective.vhosts[0].compression.enabled, Some(false));
assert_eq!(effective.vhosts[0].compression.zstd, Some(false));
let policy = crate::config::ValidationPolicy {
proxy_addr: "127.0.0.1:8080".parse().unwrap(),
admin_addr: "127.0.0.1:9090".parse().unwrap(),
tls_addr: None,
cert_dir: None,
data_dir: None,
};
let snapshot = crate::config::compile(effective, 0, &policy).unwrap();
let route = snapshot
.select_on(
"app.docker1.lab.local",
"/",
"127.0.0.1:8080".parse().unwrap(),
false,
)
.unwrap();
assert!(route.unavailable);
assert!(route.pool.is_none());
assert!(route.backend.is_none());
}
#[test]
fn failed_agent_observation_with_last_inventory_keeps_backend_materialized() {
let mut desired = crate::config::demo_config("127.0.0.1:9000".parse().unwrap());
desired.vhosts.clear();
desired.docker_agents.agents.push(Agent {
id: "node1".into(),
name: "Node 1".into(),
endpoint: "http://10.0.0.2:9876".into(),
token: "012345678901234567890123".into(),
base_domain: "docker1.lab.local".into(),
listener_ids: vec!["http".into()],
assignments: vec![Assignment {
service_key: "container:app:8080/tcp".into(),
hostname: "app".into(),
compression_enabled: Some(true),
compression_gzip: Some(false),
compression_br: Some(true),
..Default::default()
}],
..Default::default()
});
let mut observed = observation(
service(),
vec![HostAddress {
ip: "10.2.3.4".into(),
source: "interface".into(),
interface: "eno1".into(),
scope: "private".into(),
}],
);
let state = observed.get_mut("node1").unwrap();
state.ok = false;
state.error = Some("temporary agent outage".into());
let effective = effective_config(desired, &observed).unwrap();
assert_eq!(effective.vhosts.len(), 1);
assert_eq!(effective.vhosts[0].backends.len(), 1);
assert!(!effective.vhosts[0].transient_unavailable);
assert_eq!(effective.vhosts[0].compression.enabled, Some(true));
assert_eq!(effective.vhosts[0].compression.gzip, Some(false));
assert_eq!(effective.vhosts[0].compression.br, Some(true));
}
#[test]
fn disabling_agent_stops_discovery_but_keeps_published_hostname_as_503() {
let mut desired = crate::config::demo_config("127.0.0.1:9000".parse().unwrap());
desired.vhosts.clear();
desired.docker_agents.agents.push(Agent {
id: "node1".into(),
name: "Node 1".into(),
endpoint: "http://10.0.0.2:9876".into(),
token: "012345678901234567890123".into(),
base_domain: "docker1.lab.local".into(),
listener_ids: vec!["http".into()],
enabled: false,
assignments: vec![Assignment {
service_key: "container:app:8080/tcp".into(),
hostname: "app".into(),
..Default::default()
}],
..Default::default()
});
let observed = observation(
service(),
vec![HostAddress {
ip: "10.2.3.4".into(),
source: "interface".into(),
interface: "eno1".into(),
scope: "private".into(),
}],
);
let effective = effective_config(desired, &observed).unwrap();
assert_eq!(effective.vhosts.len(), 1);
assert!(effective.vhosts[0].backends.is_empty());
assert!(effective.vhosts[0].transient_unavailable);
}
#[test]
fn docker_assignment_propagates_explicit_passive_health_policy() {
let mut desired = crate::config::demo_config("127.0.0.1:9000".parse().unwrap());