Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/clippy-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"owner":"clippy",
"problemMatcher": [
{
"owner": "cargo-clippy",
"pattern": [
{
"regexp": "^(error|warning|info|Error|Warning|Info): (.*)$",
"severity": 1,
"message": 2
},
{
"regexp": "^\\s+--> (.*):(\\d+):(\\d+)$",
"file": 1,
"line": 2,
"column":3
}
]
}
]
}
52 changes: 36 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [main]
workflow_dispatch:

concurrency:
concurrency:
group: ${{ github.head_ref || github.ref }}
cancel-in-progress: true

Expand All @@ -21,12 +21,13 @@ jobs:
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: echo "::add-matcher::.github/clippy-matcher.json"
- run: cargo clippy --all-targets --all-features -- -D warnings
run-tests:
runs-on: ubuntu-latest
Expand All @@ -37,13 +38,32 @@ jobs:
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Setup test coverage env
run: |
cargo install grcov
rustup component add llvm-tools
- run: cargo test --locked
env:
LLVM_PROFILE_FILE: target/debug/coverage/grcov-%p-%m.profraw
RUSTFLAGS: -Cinstrument-coverage
- name: Generate coverage
run: |
grcov target/debug/coverage/grcov-*.profraw \
--branch \
--ignore-not-existing \
--binary-path ./target/debug/ \
--source-dir ./src \
--output-types cobertura,markdown \
--ignore "/*" \
--output-path ./target/debug/coverage/
- name: Set summary
run: cat ./target/debug/coverage/markdown.md >> $GITHUB_STEP_SUMMARY
build-container:
permissions:
packages: write
Expand All @@ -61,8 +81,8 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- id: build-image
run: |
pack build ghcr.io/simonerm/imtrand:next \
--buildpack paketo-community/rust \
--builder paketobuildpacks/builder-jammy-buildpackless-base:latest \
--cache-image ghcr.io/simonerm/imtrand-cache:next \
--publish
pack build ghcr.io/simonerm/imtrand:next \
--buildpack paketo-community/rust \
--builder paketobuildpacks/builder-jammy-buildpackless-base:latest \
--cache-image ghcr.io/simonerm/imtrand-cache:next \
--publish
39 changes: 39 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async fn main() {
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
#[derive(Debug)]
enum AppError {
MissingMimeType,
InvalidMimeType(String),
Expand Down Expand Up @@ -190,3 +191,41 @@ async fn create_document(
headers.insert("Content-Type", "image/jpeg".parse().unwrap());
Ok((headers, default))
}

#[cfg(test)]
mod tests {
use axum_typed_multipart::FieldMetadata;

use super::*;

#[tokio::test]
#[should_panic]
async fn test_create_document() {
// Create the inputs your handler expects
let input: TypedMultipart<TransformRequest> = TypedMultipart(TransformRequest {
image: FieldData {
metadata: FieldMetadata {
name: Some("test".to_string()),
file_name: Some("test".to_string()),
content_type: Some("test".to_string()),
headers: HeaderMap::new(),
},
contents: Bytes::new(),
},
layers: vec![FieldData {
metadata: FieldMetadata {
name: Some("test".to_string()),
file_name: Some("test".to_string()),
content_type: Some("test".to_string()),
headers: HeaderMap::new(),
},
contents: Bytes::new(),
}],
});

// Call the handler directly
create_document(input).await.unwrap();
// Assert on the response
// Additional assertions...
}
}