Skip to content

Commit

Permalink
ci: refactor e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine committed Oct 21, 2024
1 parent 0e43e8d commit f5df769
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 106 deletions.
12 changes: 12 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: "setup"
description: "setup environment for s3s"
runs:
using: "composite"
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
30 changes: 11 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,42 +86,34 @@ jobs:
- uses: taiki-e/install-action@cargo-audit
- run: cargo audit -D warnings

mint:
mint-proxy-minio:
name: e2e (mint, s3s-proxy, minio)
needs: skip-check
if: needs.skip-check.outputs.should_skip != 'true'
name: e2e (s3s-proxy, mint)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- uses: ./.github/actions/setup
- run: docker pull minio/mint:edge
- run: docker pull minio/minio:latest
- run: cargo install --path crates/s3s-proxy
- run: just install s3s-proxy
- run: ./scripts/e2e-mint.sh
- run: ./scripts/report-mint.py /tmp/mint/log.json
- uses: actions/upload-artifact@v4
with:
name: e2e-mint-logs
name: mint-proxy-minio.logs
path: ./target/s3s-proxy.log

e2e-fs:
name: e2e (s3s-e2e, s3s-fs)
needs: skip-check
if: needs.skip-check.outputs.should_skip != 'true'
name: e2e (s3s-fs, s3s-e2e)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- uses: ./.github/actions/setup
- run: just install s3s-e2e
- run: just install s3s-fs
- run: ./scripts/e2e-fs.sh
- uses: actions/upload-artifact@v4
with:
name: e2e-fs-logs
path: |
./target/s3s-fs.log
./target/s3s-e2e.log
name: e2e-fs.logs
path: ./target/s3s-fs.log
6 changes: 5 additions & 1 deletion crates/s3s-fs/src/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ impl S3 for FileSystem {
async fn delete_bucket(&self, req: S3Request<DeleteBucketInput>) -> S3Result<S3Response<DeleteBucketOutput>> {
let input = req.input;
let path = self.get_bucket_path(&input.bucket)?;
try_!(fs::remove_dir_all(path).await);
if path.exists() {
try_!(fs::remove_dir_all(path).await);
} else {
return Err(s3_error!(NoSuchBucket));
}
Ok(S3Response::new(DeleteBucketOutput {}))
}

Expand Down
5 changes: 3 additions & 2 deletions crates/s3s-test/e2e/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use s3s_test::TestFixture;
use s3s_test::TestSuite;

use std::fmt;
use std::process::Termination;
use std::sync::Arc;

use aws_sdk_s3::error::ProvideErrorMetadata;
Expand Down Expand Up @@ -115,7 +116,7 @@ impl Basic {
}
}

fn main() {
fn main() -> impl Termination {
s3s_test::cli::main(|tcx| {
macro_rules! case {
($s:ident, $x:ident, $c:ident) => {{
Expand All @@ -126,5 +127,5 @@ fn main() {
}

case!(E2E, Basic, test_list_buckets);
});
})
}
52 changes: 35 additions & 17 deletions crates/s3s-test/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::path::Path;
use std::path::PathBuf;
use std::process::ExitCode;
use std::process::Termination;

use crate::report::FnResult;
use crate::report::Report;
use crate::tcx::TestContext;

use clap::Parser;
Expand Down Expand Up @@ -37,18 +41,13 @@ fn status(passed: bool) -> ColoredString {
}
}

#[tokio::main]
async fn async_main(opt: &Opt, register: impl FnOnce(&mut TestContext)) -> Result<(), StdError> {
let mut tcx = TestContext::new();
register(&mut tcx);

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

if let Some(ref json_path) = opt.json {
let report_json = serde_json::to_string_pretty(&report)?;
std::fs::write(json_path, report_json)?;
}
fn write_report(json_path: &Path, report: &Report) -> Result<(), StdError> {
let report_json = serde_json::to_string_pretty(&report)?;
std::fs::write(json_path, report_json)?;
Ok(())
}

fn print_summary(report: &Report) {
let w = format!("{:.3}", report.duration_ms).len();

for suite in &report.suites {
Expand Down Expand Up @@ -87,16 +86,35 @@ async fn async_main(opt: &Opt, register: impl FnOnce(&mut TestContext)) -> Resul
let status = status(report.suite_count.all_passed());
let duration = report.duration_ms;
println!("{status} {duration:>w$.3}ms");
}

Ok(())
#[tokio::main]
async fn async_main(opt: &Opt, register: impl FnOnce(&mut TestContext)) -> ExitCode {
let mut tcx = TestContext::new();
register(&mut tcx);

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

if let Some(ref json_path) = opt.json {
if let Err(err) = write_report(json_path, &report) {
eprintln!("Failed to write report: {err}");
return ExitCode::from(2);
}
}

print_summary(&report);

if report.suite_count.all_passed() {
ExitCode::from(0)
} else {
ExitCode::from(1)
}
}

pub fn main(register: impl FnOnce(&mut TestContext)) {
#[must_use]
pub fn main(register: impl FnOnce(&mut TestContext)) -> impl Termination {
dotenvy::dotenv().ok();
setup_tracing();
let opt = Opt::parse();
if let Err(err) = async_main(&opt, register) {
eprintln!("{err}");
std::process::exit(1);
}
async_main(&opt, register)
}
7 changes: 0 additions & 7 deletions scripts/assert-unchanged.sh

This file was deleted.

53 changes: 0 additions & 53 deletions scripts/download-model.py

This file was deleted.

11 changes: 4 additions & 7 deletions scripts/e2e-fs.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/bin/bash -ex

cargo build -p s3s-fs --bins --release --features binary
cargo build -p s3s-test --bins --release

DATA_DIR="/tmp/s3s-e2e"
mkdir -p "$DATA_DIR"

if [ -z "$RUST_LOG" ]; then
export RUST_LOG="s3s_fs=debug,s3s=debug"
fi

./target/release/s3s-fs \
killall s3s-fs

s3s-fs \
--access-key AKEXAMPLES3S \
--secret-key SKEXAMPLES3S \
--host localhost \
Expand All @@ -31,6 +30,4 @@ if [ -z "$RUST_LOG" ]; then
fi
export RUST_BACKTRACE=full

./target/release/s3s-e2e "$@" | tee target/s3s-e2e.log

killall s3s-fs
s3s-e2e "$@"

0 comments on commit f5df769

Please sign in to comment.