Skip to content

Commit c96a090

Browse files
authored
Merge pull request #2247 from fermyon/move-over
Move wasi-http integration tests over to new testing framework
2 parents 9974863 + 7b2ac0b commit c96a090

File tree

35 files changed

+1828
-2254
lines changed

35 files changed

+1828
-2254
lines changed

.github/actions/spin-ci-dependencies/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ inputs:
7272
required: false
7373
type: string
7474

75+
docker:
76+
description: 'setup docker'
77+
required: false
78+
default: 'false'
79+
type: bool
80+
7581
runs:
7682
using: "composite"
7783
steps:

.github/workflows/build.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
if: failure()
4949
uses: andymckay/[email protected]
5050

51-
## This is separated out to remove e2e-tests dependency on windows/mac builds
51+
## This is separated out to remove full integration tests dependencies on windows/mac builds
5252
build-rust-ubuntu:
5353
name: Build Spin Ubuntu
5454
runs-on: ubuntu-latest
@@ -157,11 +157,15 @@ jobs:
157157
rust-cache: true
158158
nomad: true
159159

160-
- name: Cargo Unit and Integration Tests
160+
- name: Run Unit Tests
161161
run: |
162-
make test-unit test-integration
163-
env:
164-
CARGO_INCREMENTAL: 0
162+
make test-unit
163+
164+
- name: Run Integration Tests
165+
run: |
166+
make test-integration
167+
# Only run integration tests on macOS as they will be run on ubuntu separately
168+
if: ${{ matrix.runner == 'macos-latest' }}
165169

166170
test-go:
167171
name: Test Spin SDK - Go
@@ -193,7 +197,7 @@ jobs:
193197
- name: "Test Go SDK"
194198
run: make test-sdk-go
195199

196-
e2e-tests:
200+
all-integration-tests:
197201
# run on a larger runner for more SSD/resource access
198202
runs-on: ubuntu-22.04-4core-spin
199203
if: ${{ github.repository_owner == 'fermyon' }}
@@ -225,6 +229,6 @@ jobs:
225229
mv grain-linux-x64 grain
226230
echo "$PWD" >> $GITHUB_PATH
227231
228-
- name: Run e2e tests
232+
- name: Run Full Integration Tests
229233
run: |
230-
make test-spin-up
234+
make test-integration-full

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ wit-component = "0.19.0"
108108

109109
[features]
110110
default = ["llm"]
111-
all-tests = ["e2e-tests"]
112-
e2e-tests = []
111+
all-tests = ["extern-dependencies-tests"]
112+
extern-dependencies-tests = []
113113
llm = ["spin-trigger-http/llm"]
114114
llm-metal = ["llm", "spin-trigger-http/llm-metal"]
115115
llm-cublas = ["llm", "spin-trigger-http/llm-cublas"]

Makefile

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,6 @@ CERT_NAME ?= local
33
SPIN_DOC_NAME ?= new-doc.md
44
export PATH := target/debug:target/release:$(HOME)/.cargo/bin:$(PATH)
55

6-
ARCH = $(shell uname -p)
7-
8-
## dependencies for e2e-tests
9-
E2E_BUILD_SPIN ?= false
10-
E2E_FETCH_SPIN ?= true
11-
E2E_TESTS_DOCKERFILE ?= e2e-tests.Dockerfile
12-
MYSQL_IMAGE ?= mysql:8.0.22
13-
REDIS_IMAGE ?= redis:7.0.8-alpine3.17
14-
POSTGRES_IMAGE ?= postgres:14.7-alpine
15-
REGISTRY_IMAGE ?= registry:2
16-
E2E_SPIN_RELEASE_VOLUME_MOUNT ?=
17-
E2E_SPIN_DEBUG_VOLUME_MOUNT ?=
18-
19-
## overrides for aarch64
20-
ifneq ($(ARCH),x86_64)
21-
MYSQL_IMAGE = arm64v8/mysql:8.0.32
22-
REDIS_IMAGE = arm64v8/redis:6.0-alpine3.17
23-
POSTGRES_IMAGE = arm64v8/postgres:14.7
24-
REGISTRY_IMAGE = arm64v8/registry:2
25-
E2E_TESTS_DOCKERFILE = e2e-tests-aarch64.Dockerfile
26-
endif
27-
28-
ifneq (,$(wildcard $(shell pwd)/target/release/spin))
29-
E2E_SPIN_RELEASE_VOLUME_MOUNT = -v $(shell pwd)/target/release/spin:/from-host/target/release/spin
30-
endif
31-
32-
ifneq (,$(wildcard $(shell pwd)/target/debug/spin))
33-
E2E_SPIN_DEBUG_VOLUME_MOUNT = -v $(shell pwd)/target/debug/spin:/from-host/target/debug/spin
34-
endif
35-
36-
## Reset volume mounts for e2e-tests if Darwin because the
37-
## spin binaries built on macOS won't run in the docker container
38-
ifeq ($(shell uname -s),Darwin)
39-
E2E_SPIN_RELEASE_VOLUME_MOUNT =
40-
E2E_SPIN_DEBUG_VOLUME_MOUNT =
41-
E2E_BUILD_SPIN = true
42-
endif
43-
446
## overrides for Windows
457
ifeq ($(OS),Windows_NT)
468
LOG_LEVEL_VAR =
@@ -87,20 +49,21 @@ update-cargo-locks:
8749

8850
.PHONY: test-unit
8951
test-unit:
90-
$(LOG_LEVEL_VAR) cargo test --all --no-fail-fast -- --skip integration_tests --skip spinup_tests --skip cloud_tests --nocapture
52+
$(LOG_LEVEL_VAR) cargo test --all --no-fail-fast -- --skip integration_tests --nocapture
9153

9254
.PHONY: test-crate
9355
test-crate:
94-
$(LOG_LEVEL_VAR) cargo test -p $(crate) --no-fail-fast -- --skip integration_tests --skip spinup_tests --skip cloud_tests --nocapture
56+
$(LOG_LEVEL_VAR) cargo test -p $(crate) --no-fail-fast -- --skip integration_tests --nocapture
9557

58+
# Run the integration tests without the tests that use some sort of assumed external depedency (e.g., Docker, a language toolchain, etc.)
9659
.PHONY: test-integration
9760
test-integration:
98-
cargo test -F e2e-tests -- runtime_tests --nocapture; \
99-
$(LOG_LEVEL_VAR) cargo test --test integration --no-fail-fast -- --skip spinup_tests --skip cloud_tests --nocapture
61+
cargo test --release integration_tests --no-default-features --no-fail-fast -- --nocapture
10062

101-
.PHONY: test-spin-up
102-
test-spin-up:
103-
cargo test --release spinup_tests --no-default-features --features e2e-tests --no-fail-fast -- --nocapture
63+
# Run all of the integration tests including those that use some sort of assumed external depedency (e.g., Docker, a language toolchain, etc.)
64+
.PHONY: test-integration-full
65+
test-integration-full:
66+
cargo test --release integration_tests --no-default-features --features extern-dependencies-tests --no-fail-fast -- --nocapture
10467

10568
.PHONY: test-sdk-go
10669
test-sdk-go:

build.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use std::{
88
use cargo_target_dep::build_target_dep;
99

1010
const TIMER_TRIGGER_INTEGRATION_TEST: &str = "examples/spin-timer/app-example";
11-
const WASI_HTTP_INTEGRATION_TEST: &str = "examples/wasi-http-rust-streaming-outgoing-body";
12-
const OUTBOUND_HTTP_POST_INTEGRATION_TEST: &str = "examples/http-rust-outbound-post";
1311

1412
fn main() {
1513
// Extract environment information to be passed to plugins.
@@ -84,8 +82,6 @@ error: the `wasm32-wasi` target is not installed
8482
build_wasm_test_program("timer_app_example.wasm", "examples/spin-timer/app-example");
8583

8684
cargo_build(TIMER_TRIGGER_INTEGRATION_TEST);
87-
cargo_build(WASI_HTTP_INTEGRATION_TEST);
88-
cargo_build(OUTBOUND_HTTP_POST_INTEGRATION_TEST);
8985
}
9086

9187
fn build_wasm_test_program(name: &'static str, root: &'static str) {

crates/templates/src/test_built_ins/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![cfg(test)]
22

3-
// Module for unit-testing the built-in templates when a full e2e test would be overkill.
3+
// Module for unit-testing the built-in templates when a full integration test would be overkill.
44
// If your test involves invoking the Spin CLI, or builds or runs an application, use
5-
// an e2e test.
5+
// an integration test.
66

77
use std::{collections::HashMap, path::PathBuf};
88

crates/test-codegen-macro/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ test = false
1212
[dependencies]
1313
heck = "0.4.0"
1414
quote = "1.0.32"
15+
syn = "2.0"

crates/test-codegen-macro/src/lib.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use std::{env, path::PathBuf};
44

55
/// This macro generates the `#[test]` functions for the runtime tests.
66
#[proc_macro]
7-
pub fn codegen_runtime_tests(_input: TokenStream) -> TokenStream {
7+
pub fn codegen_runtime_tests(input: TokenStream) -> TokenStream {
8+
let input = syn::parse_macro_input!(input);
9+
let ignores = ignores(input);
810
let mut tests = Vec::new();
911
let tests_path =
1012
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../tests/runtime-tests/tests");
@@ -20,9 +22,14 @@ pub fn codegen_runtime_tests(_input: TokenStream) -> TokenStream {
2022
let requires_services = entry.path().join("services").exists();
2123

2224
let name = test.file_stem().unwrap().to_str().unwrap();
25+
let ignore = if ignores.contains(&name.to_string()) {
26+
quote::quote!(#[ignore])
27+
} else {
28+
quote::quote!()
29+
};
2330
let ident = quote::format_ident!("{}", name.to_snake_case());
2431
let feature_attribute = if requires_services {
25-
quote::quote!(#[cfg(feature = "e2e-tests")])
32+
quote::quote!(#[cfg(feature = "extern-dependencies-tests")])
2633
} else {
2734
quote::quote!()
2835
};
@@ -35,6 +42,7 @@ pub fn codegen_runtime_tests(_input: TokenStream) -> TokenStream {
3542
// ```
3643
tests.push(quote::quote! {
3744
#[test]
45+
#ignore
3846
#feature_attribute
3947
fn #ident() {
4048
run(::std::path::PathBuf::from(#tests_path_string).join(#name))
@@ -44,3 +52,26 @@ pub fn codegen_runtime_tests(_input: TokenStream) -> TokenStream {
4452
}
4553
(quote::quote!(#(#tests)*)).into()
4654
}
55+
56+
fn ignores(input: syn::FieldValue) -> Vec<String> {
57+
let syn::Member::Named(n) = input.member else {
58+
panic!("codegen_runtime_tests!() requires a named field");
59+
};
60+
if n != "ignore" {
61+
panic!("codegen_runtime_tests!() only supports the `ignore` field");
62+
}
63+
let syn::Expr::Array(a) = input.expr else {
64+
panic!("codegen_runtime_tests!() requires an array of strings");
65+
};
66+
a.elems
67+
.iter()
68+
.map(|e| {
69+
if let syn::Expr::Lit(l) = e {
70+
if let syn::Lit::Str(s) = &l.lit {
71+
return s.value();
72+
}
73+
}
74+
panic!("codegen_runtime_tests!() requires an array of strings");
75+
})
76+
.collect()
77+
}

examples/http-rust-outbound-post/.cargo/config.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)