Skip to content

Commit 20e94e3

Browse files
committed
fix: use matches! assertions to verify specific error variants in tests
1 parent 8c125f4 commit 20e94e3

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

crates/stackable-operator/src/config_overrides.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ mod tests {
220220
]);
221221

222222
let result = overrides.apply(&base);
223-
assert!(result.is_err(), "removing a nonexistent path should fail");
223+
assert!(
224+
matches!(result.unwrap_err(), Error::ApplyJsonPatch { source } if source.to_string()
225+
== "operation '/0' failed at path '/nonexistent': path is invalid"),
226+
"removing a nonexistent path should fail"
227+
);
224228
}
225229

226230
#[test]
@@ -231,7 +235,8 @@ mod tests {
231235

232236
let result = overrides.apply(&base);
233237
assert!(
234-
result.is_err(),
238+
matches!(result.unwrap_err(), Error::DeserializeJsonPatchOperation { source, index: 0 } if source.to_string()
239+
== "missing field `op` at line 1 column 19"),
235240
"invalid patch operation should return an error"
236241
);
237242
}
@@ -256,7 +261,11 @@ mod tests {
256261
let overrides = JsonConfigOverrides::UserProvided("not valid json".to_owned());
257262

258263
let result = overrides.apply(&base);
259-
assert!(result.is_err(), "invalid JSON should return an error");
264+
assert!(
265+
matches!(result.unwrap_err(), Error::ParseUserProvidedJson { source } if source.to_string()
266+
== "expected ident at line 1 column 2"),
267+
"invalid JSON should return an error"
268+
);
260269
}
261270

262271
#[test]

0 commit comments

Comments
 (0)