//! The plugin handling and the supervisor, against a fake plugin (a shell //! script) instead of AWS. The real thing is in `live_tests.rs`. use super::*; #[test] fn the_ssm_target_names_cluster_task_and_container_runtime() { let t = EcsTask { cluster: "triple-c".into(), task_id: "9fb3a6cf".into(), runtime_id: "9fb3a6cf-0791508406".into(), }; assert_eq!(t.ssm_target(), "ecs:triple-c_9fb3a6cf_9fb3a6cf-0791508406"); } #[test] fn arns_are_reduced_to_their_names() { assert_eq!( last_arn_segment("arn:aws:ecs:us-west-2:123456789012:cluster/triple-c", "cluster/"), "triple-c" ); assert_eq!( last_arn_segment("arn:aws:ecs:us-west-2:123456789012:task/triple-c/9fb3a6cf", "/"), "9fb3a6cf" ); assert_eq!(last_arn_segment("triple-c", "cluster/"), "triple-c"); assert_eq!(last_arn_segment("9fb3a6cf", "/"), "9fb3a6cf"); } #[test] fn the_plugin_endpoint_follows_the_partition() { assert_eq!(ssm_endpoint("us-west-2"), "https://ssm.us-west-2.amazonaws.com"); assert_eq!(ssm_endpoint("cn-north-1"), "https://ssm.cn-north-1.amazonaws.com.cn"); } #[test] fn a_port_clash_is_recognised_on_every_platform() { assert!(is_port_in_use("listen tcp 127.0.0.1:4: bind: address already in use")); assert!(is_port_in_use( "bind: Only one usage of each socket address (protocol/network address/port) is normally permitted." )); assert!(!is_port_in_use("TargetNotConnected")); } #[test] fn backoff_grows_then_holds() { assert!(reconnect_delay(1) < reconnect_delay(2)); assert_eq!(reconnect_delay(5), reconnect_delay(500)); } #[cfg(unix)] mod with_a_fake_plugin { use super::*; use std::os::unix::fs::PermissionsExt; use std::sync::atomic::{AtomicU32, Ordering}; /// A fake `session-manager-plugin`: a shell script. fn script(dir: &Path, name: &str, body: &str) -> PathBuf { let p = dir.join(name); std::fs::write(&p, format!("#!/bin/sh\n{body}\n")).unwrap(); std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o755)).unwrap(); p } /// Runs the script as `/bin/sh