Skip to content

Commit

Permalink
Test Petstore API in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ramosbugs committed Jan 18, 2024
1 parent 488c71b commit d793c7c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
49 changes: 45 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

env:
CARGO_TERM_COLOR: always
RUST_LOG: info

jobs:
test:
Expand All @@ -33,6 +34,30 @@ jobs:
toolchain: ${{ matrix.rust_os.rust }}
components: rustfmt

- name: Install AWS SAM CLI
uses: aws-actions/setup-sam@v2
with:
use-installer: true

# The Petstore example builds for ARM64, but GitHub runners are all x86-64, so we need QEMU.
# See https://github.com/aws/aws-sam-cli/issues/3169#issuecomment-906729604.
- name: Install QEMU
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

- name: Install Zig toolchain
uses: korandoru/setup-zig@v1
with:
zig-version: 0.10.0

# See https://www.cargo-lambda.info/guide/getting-started.html#github-actions.
- name: Install Cargo Lambda
uses: jaxxstorm/action-install-gh-release@v1
with:
repo: cargo-lambda/cargo-lambda
tag: v1.0.1
platform: linux
arch: x86_64

# Newer dependency versions may not support rustc 1.70, so we use a Cargo.lock file for those
# builds along with `--locked`.
- name: Use Rust 1.70 lockfile
Expand All @@ -41,9 +66,25 @@ jobs:
cp Cargo-1.70.lock Cargo.lock
echo "CARGO_LOCKED=--locked" >> $GITHUB_ENV
# FIXME: also run petstore integration tests
- name: Run default tests
run: cargo ${CARGO_LOCKED} test
run: cargo ${CARGO_LOCKED} test -vv

- name: Build Petstore example SAM template
working-directory: examples/petstore
run: sam build

# NB: Most of the logs produced here will be in the Post action!
- name: Start Petstore example local API
uses: JarvusInnovations/background-action@v1
with:
run: sam local start-api &
wait-on: tcp:localhost:3000
working-directory: examples/petstore
tail: true
log-output-if: true

- name: Run Petstore example integration tests
run: cargo test -p petstore -vv -- --ignored

clippy-fmt:
name: Cargo fmt + clippy (MSRV only)
Expand All @@ -62,12 +103,12 @@ jobs:
run: cp Cargo-1.70.lock Cargo.lock

- name: Run Clippy
run: cargo --locked clippy --all -- --deny warnings
run: cargo --locked clippy --all -vv -- --deny warnings

# Cargo fmt doesn't run build.rs, so we need to run clippy first in order for
# openapi-lambda-test to pass (since it depends on the .openapi-lambda output directory).
- name: Check fmt
run: cargo --locked fmt --all -- --check
run: cargo --locked fmt --all -vv -- --check

audit:
name: Cargo Audit (stable only)
Expand Down
1 change: 0 additions & 1 deletion examples/petstore/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use pretty_assertions::assert_eq;
use reqwest::{Client, StatusCode, Url};
use serde_json::json;

// FIXME: run this in CI.
#[tokio::test]
// Since this test depends on the API running separately (either locally or in AWS), we only run
// the test when specifically requested (see
Expand Down

0 comments on commit d793c7c

Please sign in to comment.