@@ -468,39 +468,28 @@ struct MockReportPeers {
468
468
}
469
469
470
470
impl MockReportPeers {
471
- // SocketAddr::new is not a const fn in stable Rust as of this writing
472
- fn valid_peer ( ) -> PeerAddress {
473
- PeerAddress :: new ( SocketAddr :: new (
474
- IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) ) ,
475
- 2000 ,
476
- ) )
477
- }
478
-
479
- fn invalid_peer ( ) -> PeerAddress {
480
- PeerAddress :: new ( SocketAddr :: new (
481
- IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 ) ) ,
482
- 2000 ,
483
- ) )
484
- }
485
-
486
- fn unresponsive_peer ( ) -> PeerAddress {
487
- PeerAddress :: new ( SocketAddr :: new (
488
- IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 ) ) ,
489
- 2000 ,
490
- ) )
491
- }
471
+ const VALID_PEER : PeerAddress = PeerAddress :: new ( SocketAddr :: new (
472
+ IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) ) ,
473
+ 2000 ,
474
+ ) ) ;
475
+
476
+ const INVALID_PEER : PeerAddress = PeerAddress :: new ( SocketAddr :: new (
477
+ IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 ) ) ,
478
+ 2000 ,
479
+ ) ) ;
480
+
481
+ const UNRESPONSIVE_PEER : PeerAddress = PeerAddress :: new ( SocketAddr :: new (
482
+ IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 ) ) ,
483
+ 2000 ,
484
+ ) ) ;
492
485
}
493
486
494
487
#[ async_trait]
495
488
impl PeersImpl for MockReportPeers {
496
489
fn peers ( & self ) -> Box < dyn Iterator < Item = PeerAddress > + Send + ' _ > {
497
490
Box :: new (
498
- [
499
- Self :: valid_peer ( ) ,
500
- Self :: invalid_peer ( ) ,
501
- Self :: unresponsive_peer ( ) ,
502
- ]
503
- . into_iter ( ) ,
491
+ [ Self :: VALID_PEER , Self :: INVALID_PEER , Self :: UNRESPONSIVE_PEER ]
492
+ . into_iter ( ) ,
504
493
)
505
494
}
506
495
@@ -526,10 +515,10 @@ impl PeersImpl for MockReportPeers {
526
515
report : EventReport ,
527
516
) -> Result < ( ) , ClientError > {
528
517
assert_eq ! ( update_id, self . update_id, "update ID matches" ) ;
529
- if peer == Self :: valid_peer ( ) {
518
+ if peer == Self :: VALID_PEER {
530
519
_ = self . report_sender . send ( report) . await ;
531
520
Ok ( ( ) )
532
- } else if peer == Self :: invalid_peer ( ) {
521
+ } else if peer == Self :: INVALID_PEER {
533
522
Err ( ClientError :: ErrorResponse ( ResponseValue :: new (
534
523
installinator_client:: types:: Error {
535
524
error_code : None ,
@@ -539,7 +528,7 @@ impl PeersImpl for MockReportPeers {
539
528
StatusCode :: UNPROCESSABLE_ENTITY ,
540
529
Default :: default ( ) ,
541
530
) ) )
542
- } else if peer == Self :: unresponsive_peer ( ) {
531
+ } else if peer == Self :: UNRESPONSIVE_PEER {
543
532
// The real implementation generates a reqwest::Error, which can't be
544
533
// created outside of the reqwest library. Generate a different error.
545
534
Err ( ClientError :: InvalidRequest ( "unresponsive peer" . to_owned ( ) ) )
0 commit comments