@@ -2,6 +2,7 @@ use std::time::Duration;
2
2
3
3
use anyhow:: bail;
4
4
use http:: { Request , Uri } ;
5
+ use spin_common:: { assert_matches, assert_not_matches} ;
5
6
use spin_factor_outbound_http:: { OutboundHttpFactor , SelfRequestOrigin } ;
6
7
use spin_factor_outbound_networking:: OutboundNetworkingFactor ;
7
8
use spin_factor_variables:: VariablesFactor ;
@@ -31,10 +32,10 @@ async fn allowed_host_is_allowed() -> anyhow::Result<()> {
31
32
32
33
// Different systems handle the discard prefix differently; some will
33
34
// 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
+ ) ;
38
39
Ok ( ( ) )
39
40
}
40
41
@@ -52,10 +53,10 @@ async fn self_request_smoke_test() -> anyhow::Result<()> {
52
53
53
54
// Different systems handle the discard prefix differently; some will
54
55
// 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
+ ) ;
59
60
Ok ( ( ) )
60
61
}
61
62
@@ -67,10 +68,10 @@ async fn disallowed_host_fails() -> anyhow::Result<()> {
67
68
let req = Request :: get ( "https://denied.test" ) . body ( Default :: default ( ) ) ?;
68
69
let mut future_resp = wasi_http. send_request ( req, test_request_config ( ) ) ?;
69
70
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
+ ) ;
74
75
Ok ( ( ) )
75
76
}
76
77
@@ -89,11 +90,11 @@ async fn disallowed_private_ips_fails() -> anyhow::Result<()> {
89
90
Ok ( _) => { }
90
91
// If private IPs are disallowed, we should get an error saying the destination is prohibited
91
92
Err ( err) if !allow_private_ips => {
92
- assert ! ( matches! ( err, ErrorCode :: DestinationIpProhibited ) )
93
+ assert_matches ! ( err, ErrorCode :: DestinationIpProhibited ) ;
93
94
}
94
95
// Otherwise, we should get some non-DestinationIpProhibited error
95
96
Err ( err) => {
96
- assert ! ( !matches! ( err, ErrorCode :: DestinationIpProhibited ) )
97
+ assert_not_matches ! ( err, ErrorCode :: DestinationIpProhibited ) ;
97
98
}
98
99
} ;
99
100
Ok ( ( ) )
0 commit comments