Skip to content

Commit 88fa72e

Browse files
committed
Fix covered OFT specitem IDs
Also added missing tests for UMessage and UAttributes.
1 parent efd9e21 commit 88fa72e

4 files changed

Lines changed: 60 additions & 32 deletions

File tree

build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2424
format!("{}uprotocol/v1/uuid.proto", UPROTOCOL_BASE_URI),
2525
// [impl->req~uri-data-model-proto~1]
2626
format!("{}uprotocol/v1/uri.proto", UPROTOCOL_BASE_URI),
27+
// [impl->req~uattributes-data-model-impl~1]
28+
// [impl->req~uattributes-data-model-proto~1]
2729
format!("{}uprotocol/v1/uattributes.proto", UPROTOCOL_BASE_URI),
2830
format!("{}uprotocol/v1/ucode.proto", UPROTOCOL_BASE_URI),
31+
// [impl->req~umessage-data-model-impl~1]
32+
// [impl->req~umessage-data-model-proto~1]
2933
format!("{}uprotocol/v1/umessage.proto", UPROTOCOL_BASE_URI),
3034
// [impl->req~ustatus-data-model-impl~1]
3135
// [impl->req~ustatus-data-model-proto~1]

src/uattributes.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub use upriority::*;
2323
pub use crate::up_core_api::uattributes::*;
2424
use crate::UUID;
2525

26-
const UPRIORITY_DEFAULT: UPriority = UPriority::UPRIORITY_CS1;
26+
pub(crate) const UPRIORITY_DEFAULT: UPriority = UPriority::UPRIORITY_CS1;
2727

2828
#[derive(Debug)]
2929
pub enum UAttributesError {
@@ -62,9 +62,8 @@ impl UAttributes {
6262
/// Checks if a given priority class is the default priority class.
6363
///
6464
/// Messages that do not have a priority class set explicity, are assigned to
65-
/// the default prioritiy class.
65+
/// the default priority class.
6666
pub(crate) fn is_default_priority(prio: UPriority) -> bool {
67-
// [impl->dsn~up-attributes-priority~1]
6867
prio == UPRIORITY_DEFAULT
6968
}
7069

@@ -146,11 +145,9 @@ impl UAttributes {
146145
pub fn check_expired(&self) -> Result<(), UAttributesError> {
147146
let ttl = match self.ttl {
148147
Some(t) if t > 0 => u64::from(t),
149-
// [impl->dsn~up-attributes-ttl~1]
150148
_ => return Ok(()),
151149
};
152150

153-
// [impl->dsn~up-attributes-ttl-timeout~1]
154151
if let Some(creation_time) = self.id.as_ref().and_then(UUID::get_time) {
155152
let delta = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
156153
Ok(duration) => {
@@ -195,15 +192,11 @@ mod tests {
195192
}
196193

197194
#[test_case(None, None, false; "for message without ID nor TTL")]
198-
// [utest->dsn~up-attributes-ttl~1]
199195
#[test_case(None, Some(0), false; "for message without ID with TTL 0")]
200196
#[test_case(None, Some(500), false; "for message without ID with TTL")]
201197
#[test_case(Some(build_n_ms_in_past(1000)), None, false; "for message with ID without TTL")]
202-
// [utest->dsn~up-attributes-ttl~1]
203198
#[test_case(Some(build_n_ms_in_past(1000)), Some(0), false; "for message with ID and TTL 0")]
204-
// [utest->dsn~up-attributes-ttl-timeout~1]
205199
#[test_case(Some(build_n_ms_in_past(1000)), Some(500), true; "for message with ID and expired TTL")]
206-
// [utest->dsn~up-attributes-ttl-timeout~1]
207200
#[test_case(Some(build_n_ms_in_past(1000)), Some(2000), false; "for message with ID and non-expired TTL")]
208201
fn test_is_expired(id: Option<UUID>, ttl: Option<u32>, should_be_expired: bool) {
209202
let attributes = UAttributes {

src/umessage.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,9 @@ impl UMessage {
141141
self.attributes
142142
.as_ref()
143143
.and_then(|attribs| attribs.priority.enum_value().ok())
144-
// [impl->dsn~up-attributes-priority~1]
145144
.map(|prio| {
146145
if prio == UPriority::UPRIORITY_UNSPECIFIED {
147-
UPriority::UPRIORITY_CS1
146+
crate::uattributes::UPRIORITY_DEFAULT
148147
} else {
149148
prio
150149
}

src/umessage/umessagebuilder.rs

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ impl UMessageBuilder {
279279
priority: request_attributes
280280
.priority
281281
.enum_value_or(UPriority::UPRIORITY_CS4),
282-
// [impl->dsn~up-attributes-response-ttl~1]
283282
ttl: request_attributes.ttl,
284283
..Default::default()
285284
}
@@ -372,9 +371,6 @@ impl UMessageBuilder {
372371
pub fn with_priority(&mut self, priority: UPriority) -> &mut UMessageBuilder {
373372
// [impl->dsn~up-attributes-request-priority~1]
374373
if self.message_type == UMessageType::UMESSAGE_TYPE_REQUEST
375-
// up-spec erroneously uses this name to define a requirement
376-
// for the response's priority class ...
377-
// [impl->dsn~up-attributes-response-reqid~1]
378374
|| self.message_type == UMessageType::UMESSAGE_TYPE_RESPONSE
379375
{
380376
assert!(priority.value() >= UPriority::UPRIORITY_CS4.value())
@@ -530,7 +526,6 @@ impl UMessageBuilder {
530526
/// # }
531527
/// ```
532528
pub fn with_comm_status(&mut self, comm_status: UCode) -> &mut UMessageBuilder {
533-
// [impl->dsn~up-attributes-response-commstatus~1]
534529
assert!(self.message_type == UMessageType::UMESSAGE_TYPE_RESPONSE);
535530
self.comm_status = Some(comm_status.into());
536531
self
@@ -800,6 +795,7 @@ mod tests {
800795

801796
use super::*;
802797

798+
use protobuf::Message;
803799
use test_case::test_case;
804800

805801
const METHOD_TO_INVOKE: &str = "//my-vehicle/4D123/2/6FA3";
@@ -820,7 +816,6 @@ mod tests {
820816

821817
// [utest->dsn~up-attributes-permission-level~1]
822818
#[test_case(Some(5), None, None; "with permission level")]
823-
// [utest->dsn~up-attributes-response-commstatus~1]
824819
#[test_case(None, Some(UCode::NOT_FOUND), None; "with commstatus")]
825820
// [utest->dsn~up-attributes-request-token~1]
826821
#[test_case(None, None, Some(String::from("my-token")); "with token")]
@@ -843,7 +838,6 @@ mod tests {
843838

844839
// [utest->dsn~up-attributes-permission-level~1]
845840
#[test_case(Some(5), None, None; "with permission level")]
846-
// [utest->dsn~up-attributes-response-commstatus~1]
847841
#[test_case(None, Some(UCode::NOT_FOUND), None; "with commstatus")]
848842
// [utest->dsn~up-attributes-request-token~1]
849843
#[test_case(None, None, Some(String::from("my-token")); "with token")]
@@ -870,17 +864,15 @@ mod tests {
870864
#[test_case(Some(5), None, None; "with permission level")]
871865
// [utest->dsn~up-attributes-request-token~1]
872866
#[test_case(None, Some(String::from("my-token")), None; "with token")]
873-
// up-spec erroneously uses this name to define a requirement
874-
// for the response's priority class ...
875-
// [utest->dsn~up-attributes-response-reqid~1]
867+
// [utest->dsn~up-attributes-request-priority~1]
876868
#[test_case(None, None, Some(UPriority::UPRIORITY_UNSPECIFIED); "with priority UNSPECIFIED")]
877-
// [utest->dsn~up-attributes-response-reqid~1]
869+
// [utest->dsn~up-attributes-request-priority~1]
878870
#[test_case(None, None, Some(UPriority::UPRIORITY_CS0); "with priority CS0")]
879-
// [utest->dsn~up-attributes-response-reqid~1]
871+
// [utest->dsn~up-attributes-request-priority~1]
880872
#[test_case(None, None, Some(UPriority::UPRIORITY_CS1); "with priority CS1")]
881-
// [utest->dsn~up-attributes-response-reqid~1]
873+
// [utest->dsn~up-attributes-request-priority~1]
882874
#[test_case(None, None, Some(UPriority::UPRIORITY_CS2); "with priority CS2")]
883-
// [utest->dsn~up-attributes-response-reqid~1]
875+
// [utest->dsn~up-attributes-request-priority~1]
884876
#[test_case(None, None, Some(UPriority::UPRIORITY_CS3); "with priority CS3")]
885877
#[should_panic]
886878
fn test_response_message_builder_panics(
@@ -904,7 +896,6 @@ mod tests {
904896
}
905897
}
906898

907-
// [utest->dsn~up-attributes-response-commstatus~1]
908899
#[test_case(Some(UCode::NOT_FOUND), None; "for comm status")]
909900
// [utest->dsn~up-attributes-request-priority~1]
910901
#[test_case(None, Some(UPriority::UPRIORITY_UNSPECIFIED); "for priority class unspecified")]
@@ -953,6 +944,8 @@ mod tests {
953944
}
954945

955946
#[test]
947+
// [utest->req~uattributes-data-model-impl~1]
948+
// [utest->req~umessage-data-model-impl~1]
956949
fn test_build_retains_all_publish_attributes() {
957950
let message_id = UUID::build();
958951
let traceparent = String::from("traceparent");
@@ -963,9 +956,9 @@ mod tests {
963956
.with_traceparent(&traceparent)
964957
.build_with_payload("locked", UPayloadFormat::UPAYLOAD_FORMAT_TEXT)
965958
.expect("should have been able to create message");
959+
966960
// [utest->dsn~up-attributes-id~1]
967961
assert_eq!(message.id_unchecked(), &message_id);
968-
// [utest->dsn~up-attributes-priority~1]
969962
assert!(UAttributes::is_default_priority(
970963
message.priority_unchecked()
971964
));
@@ -985,9 +978,20 @@ mod tests {
985978
message.payload_format_unchecked(),
986979
UPayloadFormat::UPAYLOAD_FORMAT_TEXT
987980
);
981+
982+
// [utest->req~uattributes-data-model-proto~1]
983+
// [utest->req~umessage-data-model-proto~1]
984+
let proto = message
985+
.write_to_bytes()
986+
.expect("failed to serialize to protobuf");
987+
let deserialized_message =
988+
UMessage::parse_from_bytes(proto.as_slice()).expect("failed to deserialize protobuf");
989+
assert_eq!(message, deserialized_message);
988990
}
989991

990992
#[test]
993+
// [utest->req~uattributes-data-model-impl~1]
994+
// [utest->req~umessage-data-model-impl~1]
991995
fn test_build_retains_all_notification_attributes() {
992996
let message_id = UUID::build();
993997
let traceparent = String::from("traceparent");
@@ -1001,6 +1005,7 @@ mod tests {
10011005
.with_traceparent(&traceparent)
10021006
.build_with_payload("locked", UPayloadFormat::UPAYLOAD_FORMAT_TEXT)
10031007
.expect("should have been able to create message");
1008+
10041009
// [utest->dsn~up-attributes-id~1]
10051010
assert_eq!(message.id_unchecked(), &message_id);
10061011
assert_eq!(message.priority_unchecked(), UPriority::UPRIORITY_CS2);
@@ -1019,9 +1024,20 @@ mod tests {
10191024
message.payload_format_unchecked(),
10201025
UPayloadFormat::UPAYLOAD_FORMAT_TEXT
10211026
);
1027+
1028+
// [utest->req~uattributes-data-model-proto~1]
1029+
// [utest->req~umessage-data-model-proto~1]
1030+
let proto = message
1031+
.write_to_bytes()
1032+
.expect("failed to serialize to protobuf");
1033+
let deserialized_message =
1034+
UMessage::parse_from_bytes(proto.as_slice()).expect("failed to deserialize protobuf");
1035+
assert_eq!(message, deserialized_message);
10221036
}
10231037

10241038
#[test]
1039+
// [utest->req~uattributes-data-model-impl~1]
1040+
// [utest->req~umessage-data-model-impl~1]
10251041
fn test_build_retains_all_request_attributes() {
10261042
let message_id = UUID::build();
10271043
let token = String::from("token");
@@ -1062,6 +1078,15 @@ mod tests {
10621078
message.payload_format_unchecked(),
10631079
UPayloadFormat::UPAYLOAD_FORMAT_TEXT
10641080
);
1081+
1082+
// [utest->req~uattributes-data-model-proto~1]
1083+
// [utest->req~umessage-data-model-proto~1]
1084+
let proto = message
1085+
.write_to_bytes()
1086+
.expect("failed to serialize to protobuf");
1087+
let deserialized_message =
1088+
UMessage::parse_from_bytes(proto.as_slice()).expect("failed to deserialize protobuf");
1089+
assert_eq!(message, deserialized_message);
10651090
}
10661091

10671092
#[test]
@@ -1086,14 +1111,10 @@ mod tests {
10861111
// [utest->dsn~up-attributes-id~1]
10871112
assert_eq!(message.id_unchecked(), &response_message_id);
10881113
assert_eq!(message.commstatus_unchecked(), UCode::DEADLINE_EXCEEDED);
1089-
// up-spec erroneously uses this name to define a requirement
1090-
// for the response's priority class ...
1091-
// [utest->dsn~up-attributes-response-reqid~1]
10921114
assert_eq!(message.priority_unchecked(), UPriority::UPRIORITY_CS5);
10931115
assert_eq!(message.request_id_unchecked(), &request_message_id);
10941116
assert_eq!(message.sink_unchecked(), &reply_to_address);
10951117
assert_eq!(message.source_unchecked(), &method_to_invoke);
1096-
// [utest->dsn~up-attributes-response-ttl~1]
10971118
assert_eq!(message.ttl_unchecked(), 5000);
10981119
// [utest->dsn~up-attributes-response-type~1]
10991120
assert_eq!(
@@ -1108,6 +1129,8 @@ mod tests {
11081129
}
11091130

11101131
#[test]
1132+
// [utest->req~uattributes-data-model-impl~1]
1133+
// [utest->req~umessage-data-model-impl~1]
11111134
fn test_build_retains_all_response_attributes() {
11121135
let message_id = UUID::build();
11131136
let request_id = UUID::build();
@@ -1128,9 +1151,9 @@ mod tests {
11281151
.with_traceparent(&traceparent)
11291152
.build()
11301153
.expect("should have been able to create message");
1154+
11311155
// [utest->dsn~up-attributes-id~1]
11321156
assert_eq!(message.id_unchecked(), &message_id);
1133-
// [utest->dsn~up-attributes-response-commstatus~1]
11341157
assert_eq!(message.commstatus_unchecked(), UCode::DEADLINE_EXCEEDED);
11351158
assert_eq!(message.priority_unchecked(), UPriority::UPRIORITY_CS5);
11361159
assert_eq!(message.request_id_unchecked(), &request_id);
@@ -1149,5 +1172,14 @@ mod tests {
11491172
UPayloadFormat::UPAYLOAD_FORMAT_UNSPECIFIED
11501173
);
11511174
assert!(message.payload.is_none());
1175+
1176+
// [utest->req~uattributes-data-model-proto~1]
1177+
// [utest->req~umessage-data-model-proto~1]
1178+
let proto = message
1179+
.write_to_bytes()
1180+
.expect("failed to serialize to protobuf");
1181+
let deserialized_message =
1182+
UMessage::parse_from_bytes(proto.as_slice()).expect("failed to deserialize protobuf");
1183+
assert_eq!(message, deserialized_message);
11521184
}
11531185
}

0 commit comments

Comments
 (0)