Skip to content

Commit

Permalink
add test test_get_traces_from_request_body_with_span_links
Browse files Browse the repository at this point in the history
  • Loading branch information
nhulston committed Feb 18, 2025
1 parent 32ed77c commit 83c96fe
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions trace-utils/src/trace_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,66 @@ mod tests {
}
}

#[tokio::test]
async fn test_get_traces_from_request_body_with_span_links() {
let trace_input = json!([[{
"service": "test-service",
"name": "test-name",
"resource": "test-resource",
"trace_id": 111,
"span_id": 222,
"parent_id": 333,
"start": 1,
"duration": 5,
"error": 0,
"meta": {},
"metrics": {},
"span_links": [{
"trace_id": 999,
"span_id": 888,
"trace_id_high": 777,
"attributes": {"key": "value"},
"tracestate": "vendor=value"
// flags field intentionally omitted
}]
}]]);

let expected_output = vec![vec![pb::Span {
service: "test-service".to_string(),
name: "test-name".to_string(),
resource: "test-resource".to_string(),
trace_id: 111,
span_id: 222,
parent_id: 333,
start: 1,
duration: 5,
error: 0,
meta: HashMap::new(),
metrics: HashMap::new(),
meta_struct: HashMap::new(),
r#type: String::new(),
span_links: vec![pb::SpanLink {
trace_id: 999,
span_id: 888,
trace_id_high: 777,
attributes: HashMap::from([
("key".to_string(), "value".to_string())
]),
tracestate: "vendor=value".to_string(),
flags: 0, // Should default to 0 when omitted
}],
}]];

let bytes = rmp_serde::to_vec(&trace_input).unwrap();
let request = Request::builder()
.body(hyper::body::Body::from(bytes))
.unwrap();

let res = get_traces_from_request_body(request.into_body()).await;
assert!(res.is_ok(), "Failed to deserialize: {:?}", res);
assert_eq!(res.unwrap().1, expected_output);
}

#[test]
fn test_get_root_span_index_from_complete_trace() {
let trace = vec![
Expand Down

0 comments on commit 83c96fe

Please sign in to comment.