Move test_graph_ql_error_type to mod error

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2024-05-07 22:31:26 +10:00
parent 0708f6f348
commit 30a4a53c67
No known key found for this signature in database
GPG key ID: 76D1E687CA3C4928
2 changed files with 34 additions and 34 deletions

View file

@ -135,3 +135,37 @@ struct GraphQLLocation {
line: u64, line: u64,
column: 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")
);
}
}

View file

@ -285,37 +285,3 @@ pub(super) async fn fetch_release_artifacts(
.await .await
.map_err(|err| err.context("Restful API")) .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")
);
}
}