Skip to content

Commit

Permalink
tests: check that an invalid request is returned when the input is to…
Browse files Browse the repository at this point in the history
…o long when checking either text or annotated data
  • Loading branch information
Rolv-Apneseth committed Nov 16, 2024
1 parent ea5dcb2 commit a81a453
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ impl ServerClient {
#[cfg(test)]
mod tests {
use super::ServerClient;
use crate::api::check::Request;
use crate::{api::check::Request, error::Error};

#[tokio::test]
async fn test_server_ping() {
Expand All @@ -582,8 +582,16 @@ mod tests {
#[tokio::test]
async fn test_server_check_text() {
let client = ServerClient::from_env_or_default();

let req = Request::default().with_text("je suis une poupee");
assert!(client.check(&req).await.is_ok());

// Too long
let req = Request::default().with_text("Repeat ".repeat(1500));
assert!(client
.check(&req)
.await
.is_err_and(|e| matches!(e, Error::InvalidRequest(_))));
}

#[tokio::test]
Expand All @@ -593,6 +601,18 @@ mod tests {
.with_data_str("{\"annotation\":[{\"text\": \"je suis une poupee\"}]}")
.unwrap();
assert!(client.check(&req).await.is_ok());

// Too long
let req = Request::default()
.with_data_str(&format!(
"{{\"annotation\":[{{\"text\": \"{}\"}}]}}",
"repeat".repeat(1500)
))
.unwrap();
assert!(client
.check(&req)
.await
.is_err_and(|e| matches!(e, Error::InvalidRequest(_))));
}

#[tokio::test]
Expand Down

0 comments on commit a81a453

Please sign in to comment.