Skip to content

Commit a1a7223

Browse files
test(trogon-nats): cover InvalidCredentials path when credentials file is missing
Call connect() with NatsAuth::Credentials pointing to a non-existent path to exercise the Err branch of with_credentials_file() and verify it returns ConnectError::InvalidCredentials with the expected message.
1 parent ed4cfe5 commit a1a7223

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

rsworkspace/crates/trogon-nats/src/connect.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,28 @@ mod tests {
275275
"ConnectionFailed must expose a source error"
276276
);
277277
}
278+
279+
/// Calling `connect()` with `NatsAuth::Credentials` pointing to a
280+
/// non-existent file must return `ConnectError::InvalidCredentials`
281+
/// (exercises the `Err(e)` branch of `with_credentials_file()`).
282+
#[tokio::test]
283+
async fn connect_with_missing_credentials_file_returns_invalid_credentials() {
284+
let config = NatsConfig::new(
285+
vec!["nats://127.0.0.1:4222".to_string()],
286+
NatsAuth::Credentials("/nonexistent/path/to/creds.nk".into()),
287+
);
288+
289+
let err = connect(&config, Duration::from_millis(100))
290+
.await
291+
.expect_err("expected an error for missing credentials file");
292+
293+
assert!(
294+
matches!(err, ConnectError::InvalidCredentials(_)),
295+
"missing credentials file must produce ConnectError::InvalidCredentials; got: {err}"
296+
);
297+
assert!(
298+
err.to_string().contains("Failed to load credentials file"),
299+
"error message must mention credentials file; got: {err}"
300+
);
301+
}
278302
}

0 commit comments

Comments
 (0)