use cratefield_core::PushError;
fn every_recipient() -> Vec<cratefield_core::Recipient> {
let all = [
cratefield_core::Recipient::apns("conformance-device-token"),
cratefield_core::Recipient::fcm("conformance-registration-token"),
cratefield_core::Recipient::web_push(
"https://push.example.test/conformance",
"BConformanceP256dhKey",
"ConformanceAuthKey",
),
];
for recipient in &all {
match recipient {
cratefield_core::Recipient::Apns { .. }
| cratefield_core::Recipient::Fcm { .. }
| cratefield_core::Recipient::WebPush { .. } => {}
}
}
all.to_vec()
}
pub async fn push_recipient_conformance(
push: &dyn cratefield_core::Push,
serves: &[cratefield_core::Platform],
) {
let notification = cratefield_core::Notification::new("conformance", "probe");
for recipient in every_recipient() {
let platform = recipient.platform();
let result = push.send(&recipient, ¬ification).await;
let unsupported = matches!(
&result,
Err(PushError::Rejected(message)) if message.contains("unsupported recipient")
);
if serves.contains(&platform) {
assert!(
!unsupported,
"adapter claims to serve {platform} but rejected its recipient as unsupported"
);
} else {
assert!(
unsupported,
"adapter does not serve {platform}: the port's answer is \
PushError::Rejected(\"unsupported recipient…\"), got {result:?}"
);
}
}
}
pub fn assert_wasm_safe_deps(module_crate: &str) {
let output =
std::process::Command::new(std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()))
.args(["tree", "-p", module_crate, "--edges", "normal"])
.output()
.unwrap_or_else(|err| panic!("cargo tree failed: {err}"));
assert!(
output.status.success(),
"cargo tree failed for {module_crate}"
);
let tree = String::from_utf8_lossy(&output.stdout);
for forbidden in ["worker v", "wasm-bindgen v", "tokio v", "reqwest v"] {
assert!(
!tree.contains(forbidden),
"{module_crate} pulls forbidden dependency `{}`:\n{tree}",
forbidden.trim_end_matches(" v")
);
}
}