diff --git a/swarm-authelia-bridge-sock/src/lib.rs b/swarm-authelia-bridge-sock/src/lib.rs index 890669f9..849961cd 100644 --- a/swarm-authelia-bridge-sock/src/lib.rs +++ b/swarm-authelia-bridge-sock/src/lib.rs @@ -75,7 +75,7 @@ pub struct AgentIdentity { /// The bridge's answer to a [`BridgeRequest`]. /// /// `#[serde(tag = "status")]` rather than a bare `Result`-shaped wrapper: an -/// external tag reads directly as one of three named outcomes on the wire +/// external tag reads directly as a named outcome on the wire /// (`{"status":"created",...}`), with no separate "was this an error" /// boolean to keep in sync with which variant it is. #[derive(Debug, Clone, Serialize, Deserialize)] @@ -111,8 +111,13 @@ mod tests { use super::{AgentIdentity, BridgeRequest, BridgeResponse}; /// Pins the external-tag wire shape — a reader off the wire (or a log - /// line) should be able to tell the three outcomes apart without + /// line) should be able to tell the outcomes apart without /// cross-referencing this crate's source. + /// + /// **Every variant, deliberately.** A test that claims to pin the wire + /// shape and covers all but one is worse than a narrower one: the next + /// variant gets added with nothing to remind its author that this is + /// where the shape is settled. #[test] fn response_variants_tag_on_status() { let created = serde_json::to_value(BridgeResponse::Created).unwrap(); @@ -121,6 +126,17 @@ mod tests { let exists = serde_json::to_value(BridgeResponse::AlreadyExists).unwrap(); assert_eq!(exists, serde_json::json!({"status": "already_exists"})); + let agents = serde_json::to_value(BridgeResponse::Agents { + agents: vec![AgentIdentity { + name: "atlas".to_owned(), + }], + }) + .unwrap(); + assert_eq!( + agents, + serde_json::json!({"status": "agents", "agents": [{"name": "atlas"}]}) + ); + let err = serde_json::to_value(BridgeResponse::Error { message: "boom".to_owned(), })