From 30a4a53c67a829a79ae78a92be512288a32dd381 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 7 May 2024 22:31:26 +1000 Subject: [PATCH] Move `test_graph_ql_error_type` to mod `error` Signed-off-by: Jiahao XU --- .../src/gh_api_client/error.rs | 34 +++++++++++++++++++ .../src/gh_api_client/request.rs | 34 ------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/crates/binstalk-git-repo-api/src/gh_api_client/error.rs b/crates/binstalk-git-repo-api/src/gh_api_client/error.rs index 9d2c73d3..2aa0b8bb 100644 --- a/crates/binstalk-git-repo-api/src/gh_api_client/error.rs +++ b/crates/binstalk-git-repo-api/src/gh_api_client/error.rs @@ -135,3 +135,37 @@ struct GraphQLLocation { line: u64, column: u64, } + +#[cfg(test)] +mod test { + use super::*; + use crate::gh_api_client::error::GraphQLErrorType; + use serde::de::value::{BorrowedStrDeserializer, Error}; + + macro_rules! assert_matches { + ($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => { + match $expression { + $pattern $(if $guard)? => true, + expr => { + panic!( + "assertion failed: `{expr:?}` does not match `{}`", + stringify!($pattern $(if $guard)?) + ) + } + } + } + } + + #[test] + fn test_graph_ql_error_type() { + let deserialize = |input: &str| { + GraphQLErrorType::deserialize(BorrowedStrDeserializer::<'_, Error>::new(input)).unwrap() + }; + + assert_matches!(deserialize("RATE_LIMITED"), GraphQLErrorType::RateLimited); + assert_matches!( + deserialize("rATE_LIMITED"), + GraphQLErrorType::Other(val) if val == CompactString::new("rATE_LIMITED") + ); + } +} diff --git a/crates/binstalk-git-repo-api/src/gh_api_client/request.rs b/crates/binstalk-git-repo-api/src/gh_api_client/request.rs index 968103c9..ec390aae 100644 --- a/crates/binstalk-git-repo-api/src/gh_api_client/request.rs +++ b/crates/binstalk-git-repo-api/src/gh_api_client/request.rs @@ -285,37 +285,3 @@ pub(super) async fn fetch_release_artifacts( .await .map_err(|err| err.context("Restful API")) } - -#[cfg(test)] -mod test { - use super::*; - use crate::gh_api_client::error::GraphQLErrorType; - use serde::de::value::{BorrowedStrDeserializer, Error}; - - macro_rules! assert_matches { - ($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => { - match $expression { - $pattern $(if $guard)? => true, - expr => { - panic!( - "assertion failed: `{expr:?}` does not match `{}`", - stringify!($pattern $(if $guard)?) - ) - } - } - } - } - - #[test] - fn test_graph_ql_error_type() { - let deserialize = |input: &str| { - GraphQLErrorType::deserialize(BorrowedStrDeserializer::<'_, Error>::new(input)).unwrap() - }; - - assert_matches!(deserialize("RATE_LIMITED"), GraphQLErrorType::RateLimited); - assert_matches!( - deserialize("rATE_LIMITED"), - GraphQLErrorType::Other(val) if val == CompactString::new("rATE_LIMITED") - ); - } -}