Skip to content

Commit f4dedab

Browse files
committed
Add missing OFT specitem coverage for UStatus
1 parent 877ec80 commit f4dedab

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2727
format!("{}uprotocol/v1/uattributes.proto", UPROTOCOL_BASE_URI),
2828
format!("{}uprotocol/v1/ucode.proto", UPROTOCOL_BASE_URI),
2929
format!("{}uprotocol/v1/umessage.proto", UPROTOCOL_BASE_URI),
30+
// [impl->req~ustatus-data-model-impl~1]
31+
// [impl->req~ustatus-data-model-proto~1]
3032
format!("{}uprotocol/v1/ustatus.proto", UPROTOCOL_BASE_URI),
3133
// not used in the SDK yet, but for completeness sake
3234
format!("{}uprotocol/v1/file.proto", UPROTOCOL_BASE_URI),

src/ustatus.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,45 @@ impl Error for UStatus {}
158158
mod tests {
159159
use super::*;
160160

161-
use protobuf::{Enum, EnumOrUnknown};
161+
use protobuf::{well_known_types::any::Any, Enum, EnumOrUnknown, Message};
162+
163+
#[test]
164+
// [utest->req~ustatus-data-model-impl~1]
165+
fn test_ustatus_fail_with_code() {
166+
let details = vec![Any {
167+
type_url: "https://google.com/timestamp".to_string(),
168+
..Default::default()
169+
}];
170+
UCode::VALUES.iter().for_each(|code| {
171+
let mut ustatus = UStatus::fail_with_code(*code, "the message");
172+
// just make sure that the field exists and we can assign a value to it
173+
ustatus.details = details.clone();
174+
assert!(
175+
ustatus.code.enum_value().is_ok_and(|v| v == *code)
176+
&& ustatus.message.is_some_and(|v| v == "the message")
177+
);
178+
});
179+
}
180+
181+
#[test]
182+
// [utest->req~ustatus-data-model-proto~1]
183+
fn test_proto_serialization() {
184+
let ustatus = UStatus {
185+
code: UCode::CANCELLED.into(),
186+
message: Some("the message".to_string()),
187+
details: vec![Any {
188+
type_url: "https://google.com/timestamp".to_string(),
189+
..Default::default()
190+
}],
191+
..Default::default()
192+
};
193+
let proto = ustatus
194+
.write_to_bytes()
195+
.expect("failed to serialize to protobuf");
196+
let deserialized_status =
197+
UStatus::parse_from_bytes(proto.as_slice()).expect("failed to deserialize protobuf");
198+
assert_eq!(ustatus, deserialized_status);
199+
}
162200

163201
#[test]
164202
fn test_is_failed() {

0 commit comments

Comments
 (0)