Skip to content

Commit 2d7b42f

Browse files
committed
Make topic-UUri tests more readable
1 parent 46d4ab9 commit 2d7b42f

File tree

3 files changed

+26
-69
lines changed

3 files changed

+26
-69
lines changed

up-subscription/src/handlers/subscribe.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ impl RequestHandler for SubscriptionRequestHandler {
121121

122122
#[cfg(test)]
123123
mod tests {
124+
use std::str::FromStr;
125+
124126
use super::*;
125127
use test_case::test_case;
126128
use tokio::sync::mpsc::{self};
@@ -396,33 +398,16 @@ mod tests {
396398
}
397399

398400
// [utest->dsn~usubscription-subscribe-invalid-topic~1]
399-
#[test_case(UUri::default(); "Bad topic UUri")]
400-
#[test_case(UUri {
401-
authority_name: String::from("*"),
402-
ue_id: test_lib::helpers::TOPIC_LOCAL1_ID,
403-
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
404-
resource_id: test_lib::helpers::TOPIC_LOCAL1_RESOURCE as u32,
405-
..Default::default()
406-
}; "Wildcard authority in topic UUri")]
407-
#[test_case(UUri {
408-
authority_name: test_lib::helpers::LOCAL_AUTHORITY.into(),
409-
ue_id: 0xFFFF_0000,
410-
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
411-
resource_id: test_lib::helpers::TOPIC_LOCAL1_RESOURCE as u32,
412-
..Default::default()
413-
}; "Wildcard entity id in topic UUri")]
414-
#[test_case(UUri {
415-
authority_name: test_lib::helpers::LOCAL_AUTHORITY.into(),
416-
ue_id: test_lib::helpers::TOPIC_LOCAL1_ID,
417-
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
418-
resource_id: 0x0000_FFFF,
419-
..Default::default()
420-
}; "Wildcard resource id in topic UUri")]
401+
#[test_case("up:/0/0/0"; "Bad topic UUri")]
402+
#[test_case("up://*/100000/1/8AC7"; "Wildcard authority in topic UUri")]
403+
#[test_case("up://LOCAL/100000/1/FFFF"; "Wildcard entity id in topic UUri")]
404+
#[test_case("up://LOCAL/FFFF0000/1/8AC7"; "Wildcard resource id in topic UUri")]
421405
#[tokio::test]
422-
async fn test_invalid_topic_uri(topic: UUri) {
406+
async fn test_invalid_topic_uri(topic: &str) {
423407
helpers::init_once();
424408

425409
// create request and other required object(s)
410+
let topic = UUri::from_str(topic).expect("Test parameter UUri failed to parse");
426411
let subscribe_request = test_lib::helpers::subscription_request(topic, None);
427412
let request_payload = UPayload::try_from_protobuf(subscribe_request.clone()).unwrap();
428413
let message_attributes = UAttributes {

up-subscription/src/handlers/unregister_for_notifications.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ impl RequestHandler for UnregisterNotificationsRequestHandler {
6464
ServiceInvocationError::InvalidArgument(format!("Invalid topic uri '{topic}': {e}"))
6565
})?;
6666

67+
// TODO: can/should we actually use the topic alongside the subscriber, for notification-removal?
68+
// UGH - this entire notifications storage thing doesn't work, can only store one topic per subscriber atm. Needs fixed...
69+
6770
// Interact with notification manager backend
6871
let se = NotificationEvent::RemoveNotifyee {
6972
subscriber: source.clone(),
@@ -89,6 +92,7 @@ impl RequestHandler for UnregisterNotificationsRequestHandler {
8992
#[cfg(test)]
9093
mod tests {
9194
use super::*;
95+
use std::str::FromStr;
9296
use test_case::test_case;
9397
use tokio::sync::mpsc::{self};
9498

@@ -252,32 +256,16 @@ mod tests {
252256
}
253257

254258
// [utest->dsn~usubscription-unregister-notifications-invalid-topic~1]
255-
#[test_case(UUri::default(); "Bad topic UUri")]
256-
#[test_case(UUri {
257-
authority_name: String::from("*"),
258-
ue_id: test_lib::helpers::TOPIC_LOCAL1_ID,
259-
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
260-
resource_id: test_lib::helpers::TOPIC_LOCAL1_RESOURCE as u32,
261-
..Default::default()
262-
}; "Wildcard authority in topic UUri")]
263-
#[test_case(UUri {
264-
authority_name: test_lib::helpers::LOCAL_AUTHORITY.into(),
265-
ue_id: 0xFFFF_0000,
266-
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
267-
resource_id: test_lib::helpers::TOPIC_LOCAL1_RESOURCE as u32,
268-
..Default::default()
269-
}; "Wildcard entity id in topic UUri")]
270-
#[test_case(UUri {
271-
authority_name: test_lib::helpers::LOCAL_AUTHORITY.into(),
272-
ue_id: test_lib::helpers::TOPIC_LOCAL1_ID,
273-
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
274-
resource_id: 0x0000_FFFF,
275-
..Default::default()
276-
}; "Wildcard resource id in topic UUri")]
259+
#[test_case("up:/0/0/0"; "Bad topic UUri")]
260+
#[test_case("up://*/100000/1/8AC7"; "Wildcard authority in topic UUri")]
261+
#[test_case("up://LOCAL/100000/1/FFFF"; "Wildcard entity id in topic UUri")]
262+
#[test_case("up://LOCAL/FFFF0000/1/8AC7"; "Wildcard resource id in topic UUri")]
277263
#[tokio::test]
278-
async fn test_invalid_topic_uri(topic: UUri) {
264+
async fn test_invalid_topic_uri(topic: &str) {
279265
helpers::init_once();
280266

267+
// create request and other required object(s)
268+
let topic = UUri::from_str(topic).expect("Test parameter UUri failed to parse");
281269
// create request and other required object(s)
282270
let subscribe_request = test_lib::helpers::subscription_request(topic, None);
283271
let request_payload = UPayload::try_from_protobuf(subscribe_request.clone()).unwrap();

up-subscription/src/handlers/unsubscribe.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl RequestHandler for UnubscribeRequestHandler {
9696
#[cfg(test)]
9797
mod tests {
9898
use super::*;
99+
use std::str::FromStr;
99100
use test_case::test_case;
100101
use tokio::sync::mpsc::{self};
101102

@@ -267,33 +268,16 @@ mod tests {
267268
}
268269

269270
// [utest->dsn~usubscription-unsubscribe-invalid-topic~1]
270-
#[test_case(UUri::default(); "Bad topic UUri")]
271-
#[test_case(UUri {
272-
authority_name: String::from("*"),
273-
ue_id: test_lib::helpers::TOPIC_LOCAL1_ID,
274-
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
275-
resource_id: test_lib::helpers::TOPIC_LOCAL1_RESOURCE as u32,
276-
..Default::default()
277-
}; "Wildcard authority in topic UUri")]
278-
#[test_case(UUri {
279-
authority_name: test_lib::helpers::LOCAL_AUTHORITY.into(),
280-
ue_id: 0xFFFF_0000,
281-
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
282-
resource_id: test_lib::helpers::TOPIC_LOCAL1_RESOURCE as u32,
283-
..Default::default()
284-
}; "Wildcard entity id in topic UUri")]
285-
#[test_case(UUri {
286-
authority_name: test_lib::helpers::LOCAL_AUTHORITY.into(),
287-
ue_id: test_lib::helpers::TOPIC_LOCAL1_ID,
288-
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
289-
resource_id: 0x0000_FFFF,
290-
..Default::default()
291-
}; "Wildcard resource id in topic UUri")]
271+
#[test_case("up:/0/0/0"; "Bad topic UUri")]
272+
#[test_case("up://*/100000/1/8AC7"; "Wildcard authority in topic UUri")]
273+
#[test_case("up://LOCAL/100000/1/FFFF"; "Wildcard entity id in topic UUri")]
274+
#[test_case("up://LOCAL/FFFF0000/1/8AC7"; "Wildcard resource id in topic UUri")]
292275
#[tokio::test]
293-
async fn test_invalid_topic_uri(topic: UUri) {
276+
async fn test_invalid_topic_uri(topic: &str) {
294277
helpers::init_once();
295278

296279
// create request and other required object(s)
280+
let topic = UUri::from_str(topic).expect("Test parameter UUri failed to parse");
297281
let subscribe_request = test_lib::helpers::subscription_request(topic, None);
298282
let request_payload = UPayload::try_from_protobuf(subscribe_request.clone()).unwrap();
299283
let message_attributes = UAttributes {

0 commit comments

Comments
 (0)