@@ -2,6 +2,7 @@ use std::time::Duration;
22
33use anyhow:: bail;
44use http:: { Request , Uri } ;
5+ use spin_common:: { assert_matches, assert_not_matches} ;
56use spin_factor_outbound_http:: { OutboundHttpFactor , SelfRequestOrigin } ;
67use spin_factor_outbound_networking:: OutboundNetworkingFactor ;
78use spin_factor_variables:: VariablesFactor ;
@@ -31,10 +32,10 @@ async fn allowed_host_is_allowed() -> anyhow::Result<()> {
3132
3233 // Different systems handle the discard prefix differently; some will
3334 // immediately reject it while others will silently let it time out
34- match future_resp . unwrap_ready ( ) . unwrap ( ) {
35- Err ( ErrorCode :: ConnectionRefused | ErrorCode :: ConnectionTimeout ) => ( ) ,
36- other => bail ! ( "expected Err(ConnectionRefused | ConnectionTimeout), got {other:?}" ) ,
37- } ;
35+ assert_matches ! (
36+ future_resp . unwrap_ready ( ) . unwrap ( ) ,
37+ Err ( ErrorCode :: ConnectionRefused | ErrorCode :: ConnectionTimeout ) ,
38+ ) ;
3839 Ok ( ( ) )
3940}
4041
@@ -52,10 +53,10 @@ async fn self_request_smoke_test() -> anyhow::Result<()> {
5253
5354 // Different systems handle the discard prefix differently; some will
5455 // immediately reject it while others will silently let it time out
55- match future_resp . unwrap_ready ( ) . unwrap ( ) {
56- Err ( ErrorCode :: ConnectionRefused | ErrorCode :: ConnectionTimeout ) => ( ) ,
57- other => bail ! ( "expected Err(ConnectionRefused | ConnectionTimeout), got {other:?}" ) ,
58- } ;
56+ assert_matches ! (
57+ future_resp . unwrap_ready ( ) . unwrap ( ) ,
58+ Err ( ErrorCode :: ConnectionRefused | ErrorCode :: ConnectionTimeout ) ,
59+ ) ;
5960 Ok ( ( ) )
6061}
6162
@@ -67,10 +68,10 @@ async fn disallowed_host_fails() -> anyhow::Result<()> {
6768 let req = Request :: get ( "https://denied.test" ) . body ( Default :: default ( ) ) ?;
6869 let mut future_resp = wasi_http. send_request ( req, test_request_config ( ) ) ?;
6970 future_resp. ready ( ) . await ;
70- match future_resp . unwrap_ready ( ) . unwrap ( ) {
71- Ok ( _ ) => bail ! ( "expected Err, got Ok" ) ,
72- Err ( err ) => assert ! ( matches! ( err , ErrorCode :: HttpRequestDenied ) ) ,
73- } ;
71+ assert_matches ! (
72+ future_resp . unwrap_ready ( ) . unwrap ( ) ,
73+ Err ( ErrorCode :: HttpRequestDenied ) ,
74+ ) ;
7475 Ok ( ( ) )
7576}
7677
@@ -89,11 +90,11 @@ async fn disallowed_private_ips_fails() -> anyhow::Result<()> {
8990 Ok ( _) => { }
9091 // If private IPs are disallowed, we should get an error saying the destination is prohibited
9192 Err ( err) if !allow_private_ips => {
92- assert ! ( matches! ( err, ErrorCode :: DestinationIpProhibited ) )
93+ assert_matches ! ( err, ErrorCode :: DestinationIpProhibited ) ;
9394 }
9495 // Otherwise, we should get some non-DestinationIpProhibited error
9596 Err ( err) => {
96- assert ! ( !matches! ( err, ErrorCode :: DestinationIpProhibited ) )
97+ assert_not_matches ! ( err, ErrorCode :: DestinationIpProhibited ) ;
9798 }
9899 } ;
99100 Ok ( ( ) )
0 commit comments