Commit 06891a44 authored by Nugine's avatar Nugine
Browse files

feat(s3s-test): impl filter

parent 443e1829
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ dotenvy = "0.15.7"
serde_json = "1.0.128"
indexmap = "2.6.0"
colored = "2.1.0"
regex = "1.11.0"
nugine-rust-utils = "0.3.1"

[dependencies.aws-config]
version = "1.5.8"
+66 −46
Original line number Diff line number Diff line
@@ -114,10 +114,13 @@ impl Basic {

        let buckets = ["test-list-buckets-1", "test-list-buckets-2"];

        {
            for &bucket in &buckets {
                delete_bucket_loose(s3, bucket).await?;
            }
        }

        {
            for &bucket in &buckets {
                create_bucket(s3, bucket).await?;
            }
@@ -129,10 +132,13 @@ impl Basic {
                assert!(bucket_list.contains(&bucket));
                s3.head_bucket().bucket(bucket).send().await?;
            }
        }

        {
            for &bucket in &buckets {
                delete_bucket_strict(s3, bucket).await?;
            }
        }

        Ok(())
    }
@@ -144,8 +150,14 @@ impl Basic {
        let keys = ["file-1", "file-2", "file-3"];
        let content = "hello world 你好世界 123456 !@#$%😂^&*()";

        {
            for key in &keys {
                delete_object_loose(s3, bucket, key).await?;
            }
            delete_bucket_loose(s3, bucket).await?;
        }

        {
            create_bucket(s3, bucket).await?;

            for &key in &keys {
@@ -164,12 +176,14 @@ impl Basic {
                assert!(object_list.contains(&key));
                s3.head_object().bucket(bucket).key(key).send().await?;
            }
        }

        {
            for &key in &keys {
                delete_object_strict(s3, bucket, key).await?;
            }

            delete_bucket_strict(s3, bucket).await?;
        }

        Ok(())
    }
@@ -181,9 +195,12 @@ impl Basic {
        let key = "file-1";
        let content = "hello world 你好世界 123456 !@#$%😂^&*()";

        {
            delete_object_loose(s3, bucket, key).await?;
            delete_bucket_loose(s3, bucket).await?;
        }

        {
            create_bucket(s3, bucket).await?;

            s3.put_object()
@@ -198,9 +215,12 @@ impl Basic {
            let body = resp.body.collect().await?;
            let body = String::from_utf8(body.to_vec())?;
            assert_eq!(body, content);
        }

        {
            delete_object_strict(s3, bucket, key).await?;
            delete_bucket_strict(s3, bucket).await?;
        }

        Ok(())
    }
+16 −0
Original line number Diff line number Diff line
use std::ops::Not;
use std::path::Path;
use std::path::PathBuf;
use std::process::ExitCode;
@@ -10,6 +11,7 @@ use crate::tcx::TestContext;
use clap::Parser;
use colored::ColoredString;
use colored::Colorize;
use regex::RegexSet;

type StdError = Box<dyn std::error::Error + Send + Sync + 'static>;

@@ -31,6 +33,9 @@ fn setup_tracing() {
struct Opt {
    #[clap(long)]
    json: Option<PathBuf>,

    #[clap(long)]
    filter: Vec<String>,
}

fn status(passed: bool) -> ColoredString {
@@ -93,6 +98,17 @@ async fn async_main(opt: &Opt, register: impl FnOnce(&mut TestContext)) -> ExitC
    let mut tcx = TestContext::new();
    register(&mut tcx);

    if opt.filter.is_empty().not() {
        let filter_set = match RegexSet::new(&opt.filter) {
            Ok(x) => x,
            Err(err) => {
                eprintln!("Failed to build filter set: {err}");
                return ExitCode::from(2);
            }
        };
        tcx.filter(&filter_set);
    }

    let report = crate::runner::run(&mut tcx).await;

    if let Some(ref json_path) = opt.json {
+15 −0
Original line number Diff line number Diff line
@@ -7,10 +7,12 @@ use crate::traits::TestSuite;
use std::any::type_name;
use std::future::Future;
use std::marker::PhantomData;
use std::ops::Not;
use std::pin::Pin;
use std::sync::Arc;

use indexmap::IndexMap;
use regex::RegexSet;

pub(crate) type ArcAny = Arc<dyn std::any::Any + Send + Sync + 'static>;
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
@@ -94,6 +96,19 @@ impl TestContext {
            _marker: PhantomData,
        }
    }

    pub fn filter(&mut self, filter_set: &RegexSet) {
        self.suites.retain(|_, suite| {
            suite.fixtures.retain(|_, fixture| {
                fixture.cases.retain(|_, case| {
                    let id = format!("{}/{}/{}", suite.name, fixture.name, case.name);
                    filter_set.is_match(&id)
                });
                fixture.cases.is_empty().not()
            });
            suite.fixtures.is_empty().not()
        });
    }
}

pub struct SuiteBuilder<'a, S> {