Skip to content

Commit c764ba8

Browse files
committed
tests: update integration
1 parent deb93de commit c764ba8

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

.github/workflows/unittest.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ jobs:
2323
rustup component add rustfmt
2424
rustup target add wasm32-wasi
2525
cargo install wasm-tools
26+
- name: Rust Cache
27+
uses: Swatinem/rust-cache@v2
28+
with:
29+
shared-key: "unittest"
2630
- name: Build testing wasm
2731
run: ./tests/build_tests_wasm.sh
2832
- name: Run Tests

tests/integration-test/src/case.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,52 @@ pub async fn test_rust_basic(wasm: &str) -> Result<()> {
1818
assert_eq!(headers.get("x-served-by").unwrap(), "land-edge");
1919
Ok(())
2020
}
21+
22+
pub async fn test_rust_fetch(wasm: &str) -> Result<()> {
23+
let client = reqwest::Client::new();
24+
let resp = client
25+
.get(RUMTIME_SERVER)
26+
.header("x-land-module", wasm)
27+
.send()
28+
.await?;
29+
info!("resp: {:?}", resp);
30+
assert_eq!(resp.status(), 200);
31+
let body = resp.text().await?;
32+
assert!(body.contains("Rust Programming Language"));
33+
Ok(())
34+
}
35+
36+
pub async fn test_rust_router(wasm: &str) -> Result<()> {
37+
let client = reqwest::Client::new();
38+
let resp = client
39+
.get(format!("{}/hello", RUMTIME_SERVER))
40+
.header("x-land-module", wasm)
41+
.send()
42+
.await?;
43+
info!("resp: {:?}", resp);
44+
assert_eq!(resp.status(), 200);
45+
let body = resp.text().await?;
46+
assert_eq!(body, "Hello, World");
47+
48+
let resp = client
49+
.get(format!("{}/foo/bar", RUMTIME_SERVER))
50+
.header("x-land-module", wasm)
51+
.send()
52+
.await?;
53+
info!("resp: {:?}", resp);
54+
assert_eq!(resp.status(), 200);
55+
let body = resp.text().await?;
56+
assert_eq!(body, "Foo Bar");
57+
58+
let resp = client
59+
.get(format!("{}/params/xyz", RUMTIME_SERVER))
60+
.header("x-land-module", wasm)
61+
.send()
62+
.await?;
63+
info!("resp: {:?}", resp);
64+
assert_eq!(resp.status(), 200);
65+
let body = resp.text().await?;
66+
assert_eq!(body, "value: xyz");
67+
68+
Ok(())
69+
}

tests/integration-test/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ async fn main() {
8282
info!("create wasm-dist dir: {:?}", wasm_dist);
8383
}
8484

85-
// let test_templates = ["rust-basic", "rust-fetch", "rust-router"];
86-
let test_templates = ["rust-basic"];
85+
let test_templates = ["rust-basic", "rust-fetch", "rust-router"];
8786
let mut target_files = HashMap::new();
8887
for name in test_templates.iter() {
8988
// build template project
@@ -189,8 +188,8 @@ async fn test_template_runtime(name: &str, wasm: &str) -> Result<()> {
189188

190189
match name {
191190
"rust-basic" => case::test_rust_basic(wasm).await?,
192-
//"rust-fetch" => case::test_rust_fetch(wasm).await?,
193-
//"rust-router" => case::test_rust_router(wasm).await?,
191+
"rust-fetch" => case::test_rust_fetch(wasm).await?,
192+
"rust-router" => case::test_rust_router(wasm).await?,
194193
_ => return Err(anyhow::anyhow!("unknown template name: {}", name)),
195194
}
196195

0 commit comments

Comments
 (0)