#![allow(unused_imports)]
use skywalking_rust::common::time::TimeFetcher;
use skywalking_rust::context::propagation::context::PropagationContext;
use skywalking_rust::context::propagation::decoder::decode_propagation;
use skywalking_rust::context::propagation::encoder::encode_propagation;
use skywalking_rust::context::trace_context::TracingContext;
use std::sync::Arc;
struct MockTimeFetcher {}
impl TimeFetcher for MockTimeFetcher {
fn get(&self) -> i64 {
100
}
}
#[test]
fn basic() {
let data = "1-MQ==-NQ==-3-bWVzaA==-aW5zdGFuY2U=-L2FwaS92MS9oZWFsdGg=-ZXhhbXBsZS5jb206ODA4MA==";
let res = decode_propagation(data).unwrap();
assert!(res.do_sample);
assert_eq!(res.parent_trace_id, "1");
assert_eq!(res.parent_trace_segment_id, "5");
assert_eq!(res.parent_span_id, 3);
assert_eq!(res.parent_service, "mesh");
assert_eq!(res.parent_service_instance, "instance");
assert_eq!(res.destination_endpoint, "/api/v1/health");
assert_eq!(res.destination_address, "example.com:8080");
}
#[test]
fn less_field() {
let data = "1-MQ==-NQ==-3-bWVzaA==-aW5zdGFuY2U=-L2FwaS92MS9oZWFsdGg=";
let res = decode_propagation(data);
assert!(res.is_err());
}
#[test]
fn more_field() {
let data = "1-MQ==-NQ==-3-bWVzaA==-aW5zdGFuY2U=-L2FwaS92MS9oZWFsdGg=-ZXhhbXBsZS5jb206ODA4MA==-hogehoge";
let res = decode_propagation(data);
assert!(res.is_err());
}
#[test]
fn invalid_sample() {
let data = "3-MQ==-NQ==-3-bWVzaA==-aW5zdGFuY2U=-L2FwaS92MS9oZWFsdGg=-ZXhhbXBsZS5jb206ODA4MA==";
let res = decode_propagation(data);
assert!(res.is_err());
}
#[test]
fn basic_encode() {
let time_fetcher = MockTimeFetcher {};
let tc = TracingContext::default_internal(Arc::new(time_fetcher), "mesh", "instance");
let res = encode_propagation(&tc, "/api/v1/health", "example.com:8080");
let res2 = decode_propagation(&res).unwrap();
assert!(res2.do_sample);
assert_eq!("/api/v1/health", res2.destination_endpoint);
assert_eq!("example.com:8080", res2.destination_address)
}