Skip to content

Commit

Permalink
improve tests readability
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDmtri committed Mar 14, 2024
1 parent b943dbb commit 9e2b74b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 90 deletions.
72 changes: 18 additions & 54 deletions influxdb/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ async fn test_authed_write_and_read() {
#[async_std::test]
#[cfg(not(tarpaulin_include))]
async fn test_wrong_authed_write_and_read() {
use http::StatusCode;

const TEST_NAME: &str = "test_wrong_authed_write_and_read";

run_test(
Expand All @@ -140,16 +142,9 @@ async fn test_wrong_authed_write_and_read() {
let write_result = client.query(write_query).await;
assert_result_err(&write_result);
match write_result {
Err(Error::ApiError(code)) => {
if code != 403 {
panic!(
"Should be an ApiError(403), but code received was: {}",
code
);
}
}
Err(Error::ApiError(code)) if code == StatusCode::UNAUTHORIZED.as_u16() => {}
_ => panic!(
"Should be an AuthorizationError: {}",
"Should be an ApiError(UNAUTHORIZED): {}",
write_result.unwrap_err()
),
}
Expand All @@ -158,16 +153,9 @@ async fn test_wrong_authed_write_and_read() {
let read_result = client.query(read_query).await;
assert_result_err(&read_result);
match read_result {
Err(Error::ApiError(code)) => {
if code != 403 {
panic!(
"Should be an ApiError(403), but code received was: {}",
code
);
}
}
Err(Error::ApiError(code)) if code == StatusCode::UNAUTHORIZED.as_u16() => {}
_ => panic!(
"Should be an AuthorizationError: {}",
"Should be an ApiError(UNAUTHORIZED): {}",
read_result.unwrap_err()
),
}
Expand All @@ -178,16 +166,9 @@ async fn test_wrong_authed_write_and_read() {
let read_result = client.query(read_query).await;
assert_result_err(&read_result);
match read_result {
Err(Error::ApiError(code)) => {
if code != 401 {
panic!(
"Should be an ApiError(401), but code received was: {}",
code
);
}
}
Err(Error::ApiError(code)) if code == StatusCode::FORBIDDEN.as_u16() => {}
_ => panic!(
"Should be an AuthenticationError: {}",
"Should be an ApiError(UNAUTHENTICATED): {}",
read_result.unwrap_err()
),
}
Expand All @@ -211,6 +192,8 @@ async fn test_wrong_authed_write_and_read() {
#[async_std::test]
#[cfg(not(tarpaulin_include))]
async fn test_non_authed_write_and_read() {
use http::StatusCode;

const TEST_NAME: &str = "test_non_authed_write_and_read";

run_test(
Expand All @@ -229,16 +212,9 @@ async fn test_non_authed_write_and_read() {
let write_result = non_authed_client.query(write_query).await;
assert_result_err(&write_result);
match write_result {
Err(Error::ApiError(code)) => {
if code != 403 {
panic!(
"Should be an ApiError(403), but code received was: {}",
code
);
}
}
Err(Error::ApiError(code)) if code == StatusCode::UNAUTHORIZED.as_u16() => {}
_ => panic!(
"Should be an AuthorizationError: {}",
"Should be an ApiError(UNAUTHORIZED): {}",
write_result.unwrap_err()
),
}
Expand All @@ -248,16 +224,9 @@ async fn test_non_authed_write_and_read() {

assert_result_err(&read_result);
match read_result {
Err(Error::ApiError(code)) => {
if code != 403 {
panic!(
"Should be an ApiError(403), but code received was: {}",
code
);
}
}
Err(Error::ApiError(code)) if code == StatusCode::UNAUTHORIZED.as_u16() => {}
_ => panic!(
"Should be an AuthorizationError: {}",
"Should be an ApiError(UNAUTHORIZED): {}",
read_result.unwrap_err()
),
}
Expand Down Expand Up @@ -315,6 +284,8 @@ async fn test_write_and_read_field() {
#[cfg(feature = "serde")]
#[cfg(not(tarpaulin_include))]
async fn test_json_non_authed_read() {
use http::StatusCode;

const TEST_NAME: &str = "test_json_non_authed_read";

run_test(
Expand All @@ -332,16 +303,9 @@ async fn test_json_non_authed_read() {
let read_result = non_authed_client.json_query(read_query).await;
assert_result_err(&read_result);
match read_result {
Err(Error::ApiError(code)) => {
if code != 403 {
panic!(
"Should be an ApiError(403), but code received was: {}",
code
);
}
}
Err(Error::ApiError(code)) if code == StatusCode::UNAUTHORIZED.as_u16() => {}
_ => panic!(
"Should be a AuthorizationError: {}",
"Should be an ApiError(UNAUTHORIZED): {}",
read_result.unwrap_err()
),
}
Expand Down
48 changes: 12 additions & 36 deletions influxdb/tests/integration_tests_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ async fn test_authed_write_and_read() {
#[async_std::test]
#[cfg(not(tarpaulin))]
async fn test_wrong_authed_write_and_read() {
use http::StatusCode;

run_test(
|| async move {
let client = Client::new("http://127.0.0.1:2086", "mydb").with_token("falsetoken");
Expand All @@ -57,16 +59,9 @@ async fn test_wrong_authed_write_and_read() {
let write_result = client.query(&write_query).await;
assert_result_err(&write_result);
match write_result {
Err(Error::ApiError(code)) => {
if code != 403 {
panic!(
"Should be an ApiError(403), but code received was: {}",
code
);
}
}
Err(Error::ApiError(code)) if code == StatusCode::UNAUTHORIZED.as_u16() => {}
_ => panic!(
"Should be an AuthorizationError: {}",
"Should be an ApiError(UNAUTHORIZED): {}",
write_result.unwrap_err()
),
}
Expand All @@ -75,16 +70,9 @@ async fn test_wrong_authed_write_and_read() {
let read_result = client.query(&read_query).await;
assert_result_err(&read_result);
match read_result {
Err(Error::ApiError(code)) => {
if code != 403 {
panic!(
"Should be an ApiError(403), but code received was: {}",
code
);
}
}
Err(Error::ApiError(code)) if code == StatusCode::UNAUTHORIZED.as_u16() => {}
_ => panic!(
"Should be an AuthorizationError: {}",
"Should be an ApiError(UNAUTHORIZED): {}",
read_result.unwrap_err()
),
}
Expand All @@ -100,6 +88,8 @@ async fn test_wrong_authed_write_and_read() {
#[async_std::test]
#[cfg(not(tarpaulin))]
async fn test_non_authed_write_and_read() {
use http::StatusCode;

run_test(
|| async move {
let non_authed_client = Client::new("http://127.0.0.1:2086", "mydb");
Expand All @@ -109,16 +99,9 @@ async fn test_non_authed_write_and_read() {
let write_result = non_authed_client.query(&write_query).await;
assert_result_err(&write_result);
match write_result {
Err(Error::ApiError(code)) => {
if code != 403 {
panic!(
"Should be an ApiError(403), but code received was: {}",
code
);
}
}
Err(Error::ApiError(code)) if code == StatusCode::UNAUTHORIZED.as_u16() => {}
_ => panic!(
"Should be an AuthorizationError: {}",
"Should be an ApiError(UNAUTHORIZED): {}",
write_result.unwrap_err()
),
}
Expand All @@ -127,16 +110,9 @@ async fn test_non_authed_write_and_read() {
let read_result = non_authed_client.query(&read_query).await;
assert_result_err(&read_result);
match read_result {
Err(Error::ApiError(code)) => {
if code != 403 {
panic!(
"Should be an ApiError(403), but code received was: {}",
code
);
}
}
Err(Error::ApiError(code)) if code == StatusCode::UNAUTHORIZED.as_u16() => {}
_ => panic!(
"Should be an AuthorizationError: {}",
"Should be an ApiError(UNAUTHORIZED): {}",
read_result.unwrap_err()
),
}
Expand Down

0 comments on commit 9e2b74b

Please sign in to comment.