MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / test_day

Function test_day

chirpstack/src/storage/metrics.rs:419–483  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

417
418 #[tokio::test]
419 async fn test_day() {
420 let _guard = test::prepare().await;
421
422 let records = vec![
423 Record {
424 time: Local.with_ymd_and_hms(2018, 1, 1, 1, 0, 0).unwrap(),
425 kind: Kind::ABSOLUTE,
426 metrics: [("foo".into(), 1f64), ("bar".into(), 2f64)]
427 .iter()
428 .cloned()
429 .collect(),
430 },
431 Record {
432 time: Local.with_ymd_and_hms(2018, 1, 1, 2, 0, 0).unwrap(),
433 kind: Kind::ABSOLUTE,
434 metrics: [("foo".into(), 3f64), ("bar".into(), 4f64)]
435 .iter()
436 .cloned()
437 .collect(),
438 },
439 Record {
440 time: Local.with_ymd_and_hms(2018, 1, 2, 1, 0, 0).unwrap(),
441 kind: Kind::ABSOLUTE,
442 metrics: [("foo".into(), 5f64), ("bar".into(), 6f64)]
443 .iter()
444 .cloned()
445 .collect(),
446 },
447 ];
448 for r in &records {
449 save("test", r, &[Aggregation::DAY]).await.unwrap();
450 }
451
452 let resp = get(
453 "test",
454 Kind::ABSOLUTE,
455 Aggregation::DAY,
456 Local.with_ymd_and_hms(2018, 1, 1, 1, 0, 0).unwrap(),
457 Local.with_ymd_and_hms(2018, 1, 2, 1, 0, 0).unwrap(),
458 )
459 .await
460 .unwrap();
461
462 assert_eq!(
463 vec![
464 Record {
465 time: Local.with_ymd_and_hms(2018, 1, 1, 0, 0, 0).unwrap(),
466 kind: Kind::ABSOLUTE,
467 metrics: [("foo".into(), 4f64), ("bar".into(), 6f64)]
468 .iter()
469 .cloned()
470 .collect(),
471 },
472 Record {
473 time: Local.with_ymd_and_hms(2018, 1, 2, 0, 0, 0).unwrap(),
474 kind: Kind::ABSOLUTE,
475 metrics: [("foo".into(), 5f64), ("bar".into(), 6f64)]
476 .iter()

Callers

nothing calls this directly

Calls 4

prepareFunction · 0.85
unwrapMethod · 0.80
saveFunction · 0.70
getFunction · 0.70

Tested by

no test coverage detected