From 296a4e66472ff10543a5b1029fbedbbe73138535 Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee <107522312+lavafroth@users.noreply.github.com> Date: Mon, 24 Nov 2025 07:27:45 +0530 Subject: [PATCH] tests: add tests for authfile --- src/authfile.rs | 21 +++++++++++++++++++++ tests/fixtures/valid_authfile | 1 + 2 files changed, 22 insertions(+) create mode 100644 tests/fixtures/valid_authfile diff --git a/src/authfile.rs b/src/authfile.rs index 5af5aad..25f7b48 100644 --- a/src/authfile.rs +++ b/src/authfile.rs @@ -35,3 +35,24 @@ pub enum Error { #[error("failed to parse entity: {0}")] PublicKeyParsing(#[from] crate::entity::Error), } + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn test_read_nonexistent_file() { + let nonexistent = Path::new("tests/fixtures/nonexistent.txt"); + match read(nonexistent).await { + Err(Error::FileNotReadable(_)) => {} + _ => panic!("reading nonexistent authfile succeded: should have failed"), + }; + } + + #[tokio::test] + async fn test_valid_authfile() { + read(Path::new("tests/fixtures/valid_authfile")) + .await + .expect("failed to read valid authfile fixture"); + } +} diff --git a/tests/fixtures/valid_authfile b/tests/fixtures/valid_authfile new file mode 100644 index 0000000..cbd1e6a --- /dev/null +++ b/tests/fixtures/valid_authfile @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA/wbGoIUsbBHFbnXj2g+23C8sUgYkZTq0TrBm0MMWnx h@cafe