Skip to content

Commit 675e4ce

Browse files
committed
update error tests to check entire cause chain
Signed-off-by: Petros Angelatos <[email protected]>
1 parent 09c2251 commit 675e4ce

File tree

6 files changed

+123
-53
lines changed

6 files changed

+123
-53
lines changed

src/balancerd/tests/server.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use mz_frontegg_auth::{
3030
};
3131
use mz_frontegg_mock::{FronteggMockServer, models::ApiToken, models::UserConfig};
3232
use mz_ore::cast::CastFrom;
33+
use mz_ore::error::ErrorExt;
3334
use mz_ore::id_gen::{conn_id_org_uuid, org_id_conn_bits};
3435
use mz_ore::metrics::MetricsRegistry;
3536
use mz_ore::now::SYSTEM_TIME;
@@ -234,7 +235,10 @@ async fn test_balancer() {
234235
.unwrap();
235236
let _ = cancel.cancel_query(tls).await;
236237
let e = pin!(copy).next().await.unwrap().unwrap_err();
237-
assert_contains!(e.to_string(), "canceling statement due to user request");
238+
assert_contains!(
239+
e.to_string_with_causes(),
240+
"canceling statement due to user request"
241+
);
238242

239243
// Various tests about reloading of certs.
240244

src/environmentd/tests/auth.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use mz_frontegg_auth::{
4545
use mz_frontegg_mock::{
4646
FronteggMockServer, models::ApiToken, models::TenantApiTokenConfig, models::UserConfig,
4747
};
48+
use mz_ore::error::ErrorExt;
4849
use mz_ore::metrics::MetricsRegistry;
4950
use mz_ore::now::{NowFn, SYSTEM_TIME};
5051
use mz_ore::retry::Retry;
@@ -1159,7 +1160,10 @@ async fn test_auth_base_require_tls_frontegg() {
11591160
ssl_mode: SslMode::Require,
11601161
configure: Box::new(|b| Ok(b.set_verify(SslVerifyMode::NONE))),
11611162
assert: Assert::Err(Box::new(|err| {
1162-
assert_contains!(err.to_string(), "unauthorized login to user 'mz_system'");
1163+
assert_contains!(
1164+
err.to_string_with_causes(),
1165+
"unauthorized login to user 'mz_system'"
1166+
);
11631167
})),
11641168
},
11651169
TestCase::Http {
@@ -1192,7 +1196,10 @@ async fn test_auth_base_require_tls_frontegg() {
11921196
ssl_mode: SslMode::Require,
11931197
configure: Box::new(|b| Ok(b.set_verify(SslVerifyMode::NONE))),
11941198
assert: Assert::Err(Box::new(|err| {
1195-
assert_contains!(err.to_string(), "unauthorized login to user 'mz_system'");
1199+
assert_contains!(
1200+
err.to_string_with_causes(),
1201+
"unauthorized login to user 'mz_system'"
1202+
);
11961203
})),
11971204
},
11981205
TestCase::Http {
@@ -1226,7 +1233,10 @@ async fn test_auth_base_require_tls_frontegg() {
12261233
ssl_mode: SslMode::Require,
12271234
configure: Box::new(|b| Ok(b.set_verify(SslVerifyMode::NONE))),
12281235
assert: Assert::Err(Box::new(|err| {
1229-
assert_contains!(err.to_string(), "unauthorized login to user 'PUBLIC'");
1236+
assert_contains!(
1237+
err.to_string_with_causes(),
1238+
"unauthorized login to user 'PUBLIC'"
1239+
);
12301240
})),
12311241
},
12321242
TestCase::Http {
@@ -1304,7 +1314,7 @@ async fn test_auth_base_disable_tls() {
13041314
configure: Box::new(|_| Ok(())),
13051315
assert: Assert::Err(Box::new(|err| {
13061316
assert_eq!(
1307-
err.to_string(),
1317+
err.to_string_with_causes(),
13081318
"error performing TLS handshake: server does not support TLS",
13091319
)
13101320
})),
@@ -1331,7 +1341,10 @@ async fn test_auth_base_disable_tls() {
13311341
ssl_mode: SslMode::Disable,
13321342
configure: Box::new(|_| Ok(())),
13331343
assert: Assert::DbErr(Box::new(|err| {
1334-
assert_contains!(err.to_string(), "unauthorized login to user 'mz_system'");
1344+
assert_contains!(
1345+
err.to_string_with_causes(),
1346+
"unauthorized login to user 'mz_system'"
1347+
);
13351348
})),
13361349
},
13371350
],
@@ -1451,7 +1464,10 @@ async fn test_auth_base_require_tls() {
14511464
ssl_mode: SslMode::Prefer,
14521465
configure: Box::new(|b| Ok(b.set_verify(SslVerifyMode::NONE))),
14531466
assert: Assert::DbErr(Box::new(|err| {
1454-
assert_contains!(err.to_string(), "unauthorized login to user 'mz_system'");
1467+
assert_contains!(
1468+
err.to_string_with_causes(),
1469+
"unauthorized login to user 'mz_system'"
1470+
);
14551471
})),
14561472
},
14571473
],
@@ -1488,7 +1504,10 @@ async fn test_auth_intermediate_ca_no_intermediary() {
14881504
ssl_mode: SslMode::Require,
14891505
configure: Box::new(|b| b.set_ca_file(ca.ca_cert_path())),
14901506
assert: Assert::Err(Box::new(|err| {
1491-
assert_contains!(err.to_string(), "unable to get local issuer certificate");
1507+
assert_contains!(
1508+
err.to_string_with_causes(),
1509+
"unable to get local issuer certificate"
1510+
);
14921511
})),
14931512
},
14941513
TestCase::Http {

src/environmentd/tests/pgwire.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use fallible_iterator::FallibleIterator;
1919
use mz_adapter::session::DEFAULT_DATABASE_NAME;
2020
use mz_environmentd::test_util::{self, PostgresErrorExt};
2121
use mz_ore::collections::CollectionExt;
22+
use mz_ore::error::ErrorExt;
2223
use mz_ore::retry::Retry;
2324
use mz_ore::{assert_err, assert_ok};
2425
use mz_pgrepr::{Numeric, Record};
@@ -40,7 +41,8 @@ fn test_bind_params() {
4041
match client.query("SELECT ROW(1, 2) = $1", &[&"(1,2)"]) {
4142
Ok(_) => panic!("query with invalid parameters executed successfully"),
4243
Err(err) => assert!(
43-
err.to_string().contains("operator does not exist"),
44+
err.to_string_with_causes()
45+
.contains("operator does not exist"),
4446
"unexpected error: {err}"
4547
),
4648
}

src/environmentd/tests/server.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use mz_ore::cast::CastFrom;
3939
use mz_ore::cast::CastLossy;
4040
use mz_ore::cast::TryCastFrom;
4141
use mz_ore::collections::CollectionExt;
42+
use mz_ore::error::ErrorExt;
4243
use mz_ore::metrics::MetricsRegistry;
4344
use mz_ore::now::{NowFn, SYSTEM_TIME, to_datetime};
4445
use mz_ore::retry::Retry;
@@ -2121,7 +2122,7 @@ fn test_max_connections_on_all_interfaces() {
21212122
let (mut ws, _resp) = tungstenite::connect(ws_url.clone()).unwrap();
21222123
let err = test_util::auth_with_ws(&mut ws, BTreeMap::default()).unwrap_err();
21232124
assert_contains!(
2124-
err.to_string(),
2125+
err.to_string_with_causes(),
21252126
"creating connection would violate max_connections limit (desired: 2, limit: 2, current: 1)"
21262127
);
21272128
}
@@ -2213,7 +2214,7 @@ fn test_max_connections_on_all_interfaces() {
22132214
panic!("unexpected success connecting to server");
22142215
};
22152216
assert_contains!(
2216-
failure.to_string(),
2217+
failure.to_string_with_causes(),
22172218
"creating connection would violate max_connections limit (desired: 7, limit: 2, current: 6)"
22182219
);
22192220
}
@@ -2314,7 +2315,7 @@ async fn test_max_connections_limits() {
23142315
connect_regular_user()
23152316
.await
23162317
.expect_err("connect should fail")
2317-
.to_string(),
2318+
.to_string_with_causes(),
23182319
"creating connection would violate max_connections limit"
23192320
);
23202321

@@ -2327,7 +2328,7 @@ async fn test_max_connections_limits() {
23272328
connect_regular_user()
23282329
.await
23292330
.expect_err("connect should fail")
2330-
.to_string(),
2331+
.to_string_with_causes(),
23312332
"creating connection would violate max_connections limit"
23322333
);
23332334

@@ -2344,15 +2345,15 @@ async fn test_max_connections_limits() {
23442345
connect_regular_user()
23452346
.await
23462347
.expect_err("connect should fail")
2347-
.to_string(),
2348+
.to_string_with_causes(),
23482349
"creating connection would violate max_connections limit"
23492350
);
23502351

23512352
assert_contains!(
23522353
connect_regular_user()
23532354
.await
23542355
.expect_err("connect should fail")
2355-
.to_string(),
2356+
.to_string_with_causes(),
23562357
"creating connection would violate max_connections limit"
23572358
);
23582359

@@ -2367,7 +2368,7 @@ async fn test_max_connections_limits() {
23672368
connect_external_admin()
23682369
.await
23692370
.expect_err("connect should fail")
2370-
.to_string(),
2371+
.to_string_with_causes(),
23712372
"creating connection would violate max_connections limit"
23722373
);
23732374

@@ -2386,7 +2387,7 @@ async fn test_max_connections_limits() {
23862387
connect_regular_user()
23872388
.await
23882389
.expect_err("connect should fail")
2389-
.to_string(),
2390+
.to_string_with_causes(),
23902391
"creating connection would violate max_connections limit"
23912392
);
23922393

@@ -2400,7 +2401,7 @@ async fn test_max_connections_limits() {
24002401
let client = match connect_regular_user().await {
24012402
Err(e) => {
24022403
assert_contains!(
2403-
e.to_string(),
2404+
e.to_string_with_causes(),
24042405
"creating connection would violate max_connections limit"
24052406
);
24062407
return Err(());
@@ -3126,7 +3127,7 @@ fn test_cancel_read_then_write() {
31263127
.batch_execute("insert into foo select a, case when mz_unsafe.mz_sleep(ts) > 0 then 0 end as ts from foo")
31273128
.unwrap_err();
31283129
assert_contains!(
3129-
err.to_string(),
3130+
err.to_string_with_causes(),
31303131
"statement timeout"
31313132
);
31323133
client1
@@ -3137,7 +3138,7 @@ fn test_cancel_read_then_write() {
31373138
.batch_execute("insert into foo values ('blah', 1);")
31383139
.unwrap_err();
31393140
assert_contains!(
3140-
err.to_string(),
3141+
err.to_string_with_causes(),
31413142
"canceling statement"
31423143
);
31433144
});
@@ -3947,8 +3948,14 @@ async fn test_github_25388() {
39473948
.await
39483949
{
39493950
Ok(_) => Err("unexpected query success".to_string()),
3950-
Err(err) if err.to_string().contains("dependency was removed") => Ok(()),
3951-
Err(err) => Err(err.to_string()),
3951+
Err(err)
3952+
if err
3953+
.to_string_with_causes()
3954+
.contains("dependency was removed") =>
3955+
{
3956+
Ok(())
3957+
}
3958+
Err(err) => Err(err.to_string_with_causes()),
39523959
}
39533960
})
39543961
.await
@@ -3976,8 +3983,14 @@ async fn test_github_25388() {
39763983
.await
39773984
{
39783985
Ok(_) => Err("unexpected query success".to_string()),
3979-
Err(err) if err.to_string().contains("dependency was removed") => Ok(()),
3980-
Err(err) => Err(err.to_string()),
3986+
Err(err)
3987+
if err
3988+
.to_string_with_causes()
3989+
.contains("dependency was removed") =>
3990+
{
3991+
Ok(())
3992+
}
3993+
Err(err) => Err(err.to_string_with_causes()),
39813994
}
39823995
})
39833996
.await

0 commit comments

Comments
 (0)