Skip to content

Commit

Permalink
refactor: Improve behavior_tests so that cargo test works without --a…
Browse files Browse the repository at this point in the history
…ll-features (#231)

* Use meta instead

Signed-off-by: Xuanwo <[email protected]>

* Extend support

Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Apr 7, 2022
1 parent ef63b54 commit d686914
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/behavior/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
use std::io;

use anyhow::Result;
use futures::AsyncWriteExt;
use futures::StreamExt;
use log::debug;
use opendal::io_util::CompressAlgorithm;
use opendal::ObjectMode;
use opendal::Operator;
use opendal_test::services;
Expand Down Expand Up @@ -54,7 +52,9 @@ macro_rules! behavior_tests {
test_read_range,
test_read_not_exist,
test_read_with_dir_path,
#[cfg(feature = "compress")]
test_read_decompress_gzip,
#[cfg(feature = "compress")]
test_read_decompress_gzip_with,

test_stat,
Expand All @@ -76,13 +76,16 @@ macro_rules! behavior_tests {
}

macro_rules! behavior_test {
($service:ident, $($test:ident),*,) => {
($service:ident, $($(#[$meta:meta])* $test:ident),*,) => {
paste::item! {
mod [<$service>] {
use super::*;

$(
#[tokio::test]
$(
#[$meta]
)*
async fn [< $test >]() -> Result<()> {
init_logger();

Expand Down Expand Up @@ -345,8 +348,10 @@ async fn test_read_with_dir_path(op: Operator) -> Result<()> {
}

// Read a compressed file.
#[cfg(feature = "compress")]
async fn test_read_decompress_gzip(op: Operator) -> Result<()> {
use async_compression::futures::write::GzipEncoder;
use futures::AsyncWriteExt;

let path = format!("{}.gz", uuid::Uuid::new_v4());
debug!("Generate a random file: {}", &path);
Expand Down Expand Up @@ -375,8 +380,11 @@ async fn test_read_decompress_gzip(op: Operator) -> Result<()> {
}

// Read a compressed file with algo.
#[cfg(feature = "compress")]
async fn test_read_decompress_gzip_with(op: Operator) -> Result<()> {
use async_compression::futures::write::GzipEncoder;
use futures::AsyncWriteExt;
use opendal::io_util::CompressAlgorithm;

let path = format!("{}.gz", uuid::Uuid::new_v4());
debug!("Generate a random file: {}", &path);
Expand Down

0 comments on commit d686914

Please sign in to comment.