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

Function test_month

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

Source from the content-addressed store, hash-verified

551
552 #[tokio::test]
553 async fn test_month() {
554 let _guard = test::prepare().await;
555
556 let records = vec![
557 Record {
558 time: Local.with_ymd_and_hms(2018, 1, 1, 0, 0, 0).unwrap(),
559 kind: Kind::ABSOLUTE,
560 metrics: [("foo".into(), 1f64), ("bar".into(), 2f64)]
561 .iter()
562 .cloned()
563 .collect(),
564 },
565 Record {
566 time: Local.with_ymd_and_hms(2018, 1, 2, 0, 0, 0).unwrap(),
567 kind: Kind::ABSOLUTE,
568 metrics: [("foo".into(), 3f64), ("bar".into(), 4f64)]
569 .iter()
570 .cloned()
571 .collect(),
572 },
573 Record {
574 time: Local.with_ymd_and_hms(2018, 2, 1, 0, 0, 0).unwrap(),
575 kind: Kind::ABSOLUTE,
576 metrics: [("foo".into(), 5f64), ("bar".into(), 6f64)]
577 .iter()
578 .cloned()
579 .collect(),
580 },
581 ];
582 for r in &records {
583 save("test", r, &[Aggregation::MONTH]).await.unwrap();
584 }
585
586 let resp = get(
587 "test",
588 Kind::ABSOLUTE,
589 Aggregation::MONTH,
590 Local.with_ymd_and_hms(2018, 1, 1, 0, 0, 0).unwrap(),
591 Local.with_ymd_and_hms(2018, 2, 1, 0, 0, 0).unwrap(),
592 )
593 .await
594 .unwrap();
595
596 assert_eq!(
597 vec![
598 Record {
599 time: Local.with_ymd_and_hms(2018, 1, 1, 0, 0, 0).unwrap(),
600 kind: Kind::ABSOLUTE,
601 metrics: [("foo".into(), 4f64), ("bar".into(), 6f64)]
602 .iter()
603 .cloned()
604 .collect(),
605 },
606 Record {
607 time: Local.with_ymd_and_hms(2018, 2, 1, 0, 0, 0).unwrap(),
608 kind: Kind::ABSOLUTE,
609 metrics: [("foo".into(), 5f64), ("bar".into(), 6f64)]
610 .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