@@ -468,39 +468,28 @@ struct MockReportPeers {
468468}
469469
470470impl 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+ ) ) ;
492485}
493486
494487#[ async_trait]
495488impl PeersImpl for MockReportPeers {
496489 fn peers ( & self ) -> Box < dyn Iterator < Item = PeerAddress > + Send + ' _ > {
497490 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 ( ) ,
504493 )
505494 }
506495
@@ -526,10 +515,10 @@ impl PeersImpl for MockReportPeers {
526515 report : EventReport ,
527516 ) -> Result < ( ) , ClientError > {
528517 assert_eq ! ( update_id, self . update_id, "update ID matches" ) ;
529- if peer == Self :: valid_peer ( ) {
518+ if peer == Self :: VALID_PEER {
530519 _ = self . report_sender . send ( report) . await ;
531520 Ok ( ( ) )
532- } else if peer == Self :: invalid_peer ( ) {
521+ } else if peer == Self :: INVALID_PEER {
533522 Err ( ClientError :: ErrorResponse ( ResponseValue :: new (
534523 installinator_client:: types:: Error {
535524 error_code : None ,
@@ -539,7 +528,7 @@ impl PeersImpl for MockReportPeers {
539528 StatusCode :: UNPROCESSABLE_ENTITY ,
540529 Default :: default ( ) ,
541530 ) ) )
542- } else if peer == Self :: unresponsive_peer ( ) {
531+ } else if peer == Self :: UNRESPONSIVE_PEER {
543532 // The real implementation generates a reqwest::Error, which can't be
544533 // created outside of the reqwest library. Generate a different error.
545534 Err ( ClientError :: InvalidRequest ( "unresponsive peer" . to_owned ( ) ) )
0 commit comments