Skip to content

Commit 3be8617

Browse files
committed
Test Petstore API in CI
1 parent 488c71b commit 3be8617

File tree

2 files changed

+75
-6
lines changed

2 files changed

+75
-6
lines changed

.github/workflows/main.yml

+74-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
env:
1212
CARGO_TERM_COLOR: always
13+
RUST_LOG: info
1314

1415
jobs:
1516
test:
@@ -41,9 +42,78 @@ jobs:
4142
cp Cargo-1.70.lock Cargo.lock
4243
echo "CARGO_LOCKED=--locked" >> $GITHUB_ENV
4344
44-
# FIXME: also run petstore integration tests
4545
- name: Run default tests
46-
run: cargo ${CARGO_LOCKED} test
46+
run: cargo ${CARGO_LOCKED} test -vv
47+
48+
petstore-test:
49+
name: Run Petstore example tests
50+
runs-on: ${{ matrix.rust_os.os }}
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
rust_os:
55+
- { rust: 1.70.0, os: ubuntu-22.04 }
56+
- { rust: stable, os: ubuntu-22.04 }
57+
- { rust: beta, os: ubuntu-22.04 }
58+
- { rust: nightly, os: ubuntu-22.04 }
59+
60+
steps:
61+
- uses: actions/checkout@v4
62+
63+
- name: Install Rust toolchain
64+
uses: dtolnay/rust-toolchain@master
65+
with:
66+
toolchain: ${{ matrix.rust_os.rust }}
67+
components: rustfmt
68+
69+
- name: Install AWS SAM CLI
70+
uses: aws-actions/setup-sam@v2
71+
with:
72+
use-installer: true
73+
74+
# The Petstore example builds for ARM64, but GitHub runners are all x86-64, so we need QEMU.
75+
# See https://github.com/aws/aws-sam-cli/issues/3169#issuecomment-906729604.
76+
- name: Install QEMU
77+
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
78+
79+
- name: Install Zig toolchain
80+
uses: korandoru/setup-zig@v1
81+
with:
82+
zig-version: 0.10.0
83+
84+
# See https://www.cargo-lambda.info/guide/getting-started.html#github-actions.
85+
- name: Install Cargo Lambda
86+
uses: jaxxstorm/action-install-gh-release@v1
87+
with:
88+
repo: cargo-lambda/cargo-lambda
89+
tag: v1.0.1
90+
platform: linux
91+
arch: x86_64
92+
93+
# Newer dependency versions may not support rustc 1.70, so we use a Cargo.lock file for those
94+
# builds along with `--locked`.
95+
- name: Use Rust 1.70 lockfile
96+
if: ${{ matrix.rust_os.rust == '1.70.0' }}
97+
run: |
98+
cp Cargo-1.70.lock Cargo.lock
99+
echo "CARGO_LOCKED=--locked" >> $GITHUB_ENV
100+
101+
- name: Build Petstore example SAM template
102+
working-directory: examples/petstore
103+
run: sam build
104+
105+
# NB: Most of the logs produced here will be in the Post action!
106+
- name: Start Petstore example local API
107+
uses: JarvusInnovations/background-action@v1
108+
with:
109+
run: sam local start-api &
110+
wait-on: tcp:localhost:3000
111+
working-directory: examples/petstore
112+
tail: true
113+
log-output-if: true
114+
115+
- name: Run Petstore example integration tests
116+
run: cargo test -p petstore -vv -- --ignored
47117

48118
clippy-fmt:
49119
name: Cargo fmt + clippy (MSRV only)
@@ -62,12 +132,12 @@ jobs:
62132
run: cp Cargo-1.70.lock Cargo.lock
63133

64134
- name: Run Clippy
65-
run: cargo --locked clippy --all -- --deny warnings
135+
run: cargo --locked clippy --all -vv -- --deny warnings
66136

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

72142
audit:
73143
name: Cargo Audit (stable only)

examples/petstore/tests/integration.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use pretty_assertions::assert_eq;
22
use reqwest::{Client, StatusCode, Url};
33
use serde_json::json;
44

5-
// FIXME: run this in CI.
65
#[tokio::test]
76
// Since this test depends on the API running separately (either locally or in AWS), we only run
87
// the test when specifically requested (see
@@ -85,7 +84,7 @@ async fn test_integration() {
8584
let response = client
8685
.post(base_url.join("pet").unwrap())
8786
.header("Authorization", "Bearer foobar")
88-
.header("Content-Type", "test/plain")
87+
.header("Content-Type", "text/plain")
8988
.body(r#"{"name": "foo", "photoUrls": []}"#)
9089
.send()
9190
.await

0 commit comments

Comments
 (0)