| 386 | |
| 387 | #[tokio::test] |
| 388 | pub async fn test_encode() { |
| 389 | let encoder = r#" |
| 390 | function encodeDownlink(input) { |
| 391 | if (input.data.enabled) { |
| 392 | return { |
| 393 | bytes: [0x01] |
| 394 | }; |
| 395 | } else { |
| 396 | return { |
| 397 | bytes: [0x02] |
| 398 | }; |
| 399 | } |
| 400 | } |
| 401 | "# |
| 402 | .to_string(); |
| 403 | |
| 404 | let vars: HashMap<String, String> = HashMap::new(); |
| 405 | |
| 406 | let mut input = prost_types::Struct::default(); |
| 407 | input.fields.insert( |
| 408 | "enabled".to_string(), |
| 409 | prost_types::Value { |
| 410 | kind: Some(prost_types::value::Kind::BoolValue(true)), |
| 411 | }, |
| 412 | ); |
| 413 | |
| 414 | let out = encode(10, &vars, &encoder, &input).await.unwrap(); |
| 415 | assert_eq!((10, vec![1]), out); |
| 416 | } |
| 417 | |
| 418 | #[tokio::test] |
| 419 | pub async fn test_encode_fport() { |