From a0e293fc1a3c907f66c6efc8ba88c1d8b46cb0ff Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 20 Sep 2024 19:19:13 +0100 Subject: [PATCH] fix: recheck tests --- src/tests/run.rs | 34 +++++++++++++++++++++++++--------- src/tests/scanner.rs | 10 +++++----- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/tests/run.rs b/src/tests/run.rs index b94d260..e97a108 100644 --- a/src/tests/run.rs +++ b/src/tests/run.rs @@ -2,7 +2,8 @@ use super::*; use anyhow::Result; -use kxio::network::StatusCode; +use kxio::network::{RequestBody, RequestMethod, SavedRequest, StatusCode}; +use pretty_assertions::assert_eq; #[tokio::test] async fn run_with_some_invalids() -> Result<()> { @@ -28,11 +29,19 @@ async fn run_with_some_invalids() -> Result<()> { std::env::set_var("GITHUB_SERVER_URL", "https://git.kemitix.net"); //when - run(net.into()).await?; + let result = run(net.clone().into()).await; //then - // TODO: add check that run fails because file_1.txt is invalid - // TODO: add check that network requests were made to get issues + assert!(result.is_err()); // there is an invalid file + let requests = net.requests(); + assert_eq!( + requests, + vec![SavedRequest::new( + RequestMethod::Get, + "https://git.kemitix.net/api/v1/repos/kemitix/test/issues?state=open", + RequestBody::None, + )] + ); Ok(()) } @@ -44,7 +53,7 @@ async fn run_with_no_invalids() -> Result<()> { net.add_get_response( "https://git.kemitix.net/api/v1/repos/kemitix/test/issues?state=open", StatusCode::OK, - r#"[{"number": 13}]"#, + r#"[{"number":23},{"number":43}]"#, ); let _env = THE_ENVIRONMENT.lock(); let fs = kxio::fs::temp()?; @@ -57,12 +66,19 @@ async fn run_with_no_invalids() -> Result<()> { std::env::set_var("GITHUB_SERVER_URL", "https://git.kemitix.net"); //when - - run(net.into()).await?; + let result = run(net.clone().into()).await; //then - // TODO: add check that run fails because file_1.txt is invalid - // TODO: add check that network requests were made to get issues + assert!(result.is_ok()); // there is an invalid file + let requests = net.requests(); + assert_eq!( + requests, + vec![SavedRequest::new( + RequestMethod::Get, + "https://git.kemitix.net/api/v1/repos/kemitix/test/issues?state=open", + RequestBody::None, + )] + ); Ok(()) } diff --git a/src/tests/scanner.rs b/src/tests/scanner.rs index adf3360..2d5b2b7 100644 --- a/src/tests/scanner.rs +++ b/src/tests/scanner.rs @@ -38,15 +38,15 @@ fn find_markers_in_dir() -> anyhow::Result<()> { assert_eq!( markers.to_string().lines().collect::>(), vec![ - "- Invalid: file_with_invalids.txt#2:", + "- Invalid: file_with_invalids.txt#3:", " It contains a todo comment: // TODO: this is it", - "- Invalid: file_with_invalids.txt#4:", + "- Invalid: file_with_invalids.txt#5:", " It also contains a fix-me comment: // FIXME: and this is it", - "- Closed : (3) file_with_invalids.txt#8:", + "- Closed : (3) file_with_invalids.txt#9:", " We also have a todo comment: // TODO: (#3) and it has an issue number, but it is closed", - "- Valid : (23) file_with_valids.txt#2:", + "- Valid : (23) file_with_valids.txt#3:", " It also has a todo comment: // TODO: (#23) and it has an issue number", - "- Valid : (43) file_with_valids.txt#4:", + "- Valid : (43) file_with_valids.txt#5:", " Here is a fix-me comment: // FIXME: (#43) and is also has an issue number" ] );