@@ -86,6 +86,10 @@ pub struct Expect {
8686 Option < Duration > ,
8787 Option < u32 > ,
8888 ) > ,
89+ metrics_create : Vec < ( i32 , String ) > ,
90+ metrics_increment : Vec < ( i32 , i64 ) > ,
91+ metrics_record : Vec < ( i32 , u64 ) > ,
92+ metrics_get : Vec < ( i32 , u64 ) > ,
8993}
9094
9195impl Expect {
@@ -106,6 +110,10 @@ impl Expect {
106110 add_header_map_value : vec ! [ ] ,
107111 send_local_response : vec ! [ ] ,
108112 http_call : vec ! [ ] ,
113+ metrics_create : vec ! [ ] ,
114+ metrics_increment : vec ! [ ] ,
115+ metrics_record : vec ! [ ] ,
116+ metrics_get : vec ! [ ] ,
109117 }
110118 }
111119
@@ -571,4 +579,92 @@ impl Expect {
571579 }
572580 }
573581 }
582+
583+ pub fn set_expect_metric_create ( & mut self , metric_type : i32 , name : & str ) {
584+ self . expect_count += 1 ;
585+ self . metrics_create . push ( ( metric_type, name. to_string ( ) ) ) ;
586+ }
587+
588+ pub fn get_expect_metric_create ( & mut self , metric_type : i32 , name : & str ) {
589+ match self . metrics_create . len ( ) {
590+ 0 => {
591+ if !self . allow_unexpected {
592+ self . expect_count -= 1 ;
593+ }
594+ set_status ( ExpectStatus :: Unexpected ) ;
595+ }
596+ _ => {
597+ self . expect_count -= 1 ;
598+ let expected_metric_type = self . metrics_create . remove ( 0 ) ;
599+ let expect_status = expected_metric_type == ( metric_type, name. to_string ( ) ) ;
600+ set_expect_status ( expect_status) ;
601+ }
602+ }
603+ }
604+
605+ pub fn set_expect_metric_increment ( & mut self , metric_id : i32 , offset : i64 ) {
606+ self . expect_count += 1 ;
607+ self . metrics_increment . push ( ( metric_id, offset) ) ;
608+ }
609+
610+ pub fn get_expect_metric_increment ( & mut self , metric_id : i32 , offset : i64 ) {
611+ match self . metrics_increment . len ( ) {
612+ 0 => {
613+ if !self . allow_unexpected {
614+ self . expect_count -= 1 ;
615+ }
616+ set_status ( ExpectStatus :: Unexpected ) ;
617+ }
618+ _ => {
619+ self . expect_count -= 1 ;
620+ let expected_metric_increment_tuple = self . metrics_increment . remove ( 0 ) ;
621+ let expect_status = expected_metric_increment_tuple == ( metric_id, offset) ;
622+ set_expect_status ( expect_status) ;
623+ }
624+ }
625+ }
626+
627+ pub fn set_expect_metric_record ( & mut self , metric_id : i32 , value : u64 ) {
628+ self . expect_count += 1 ;
629+ self . metrics_record . push ( ( metric_id, value) ) ;
630+ }
631+
632+ pub fn get_expect_metric_record ( & mut self , metric_id : i32 , value : u64 ) {
633+ match self . metrics_record . len ( ) {
634+ 0 => {
635+ if !self . allow_unexpected {
636+ self . expect_count -= 1 ;
637+ }
638+ set_status ( ExpectStatus :: Unexpected ) ;
639+ }
640+ _ => {
641+ self . expect_count -= 1 ;
642+ let expected_metric_record_tuple = self . metrics_record . remove ( 0 ) ;
643+ let expect_status = expected_metric_record_tuple == ( metric_id, value) ;
644+ set_expect_status ( expect_status) ;
645+ }
646+ }
647+ }
648+
649+ pub fn set_expect_metric_get ( & mut self , metric_id : i32 , value : u64 ) {
650+ self . expect_count += 1 ;
651+ self . metrics_get . push ( ( metric_id, value) ) ;
652+ }
653+
654+ pub fn get_expect_metric_get ( & mut self , metric_id : i32 , value : u64 ) {
655+ match self . metrics_get . len ( ) {
656+ 0 => {
657+ if !self . allow_unexpected {
658+ self . expect_count -= 1 ;
659+ }
660+ set_status ( ExpectStatus :: Unexpected ) ;
661+ }
662+ _ => {
663+ self . expect_count -= 1 ;
664+ let expected_get_metric_tuple = self . metrics_get . remove ( 0 ) ;
665+ let expect_status = expected_get_metric_tuple == ( metric_id, value) ;
666+ set_expect_status ( expect_status) ;
667+ }
668+ }
669+ }
574670}
0 commit comments