Skip to content

Commit

Permalink
tests: update integration
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxiaohei committed Aug 27, 2023
1 parent deb93de commit c764ba8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
rustup component add rustfmt
rustup target add wasm32-wasi
cargo install wasm-tools
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
shared-key: "unittest"
- name: Build testing wasm
run: ./tests/build_tests_wasm.sh
- name: Run Tests
Expand Down
49 changes: 49 additions & 0 deletions tests/integration-test/src/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,52 @@ pub async fn test_rust_basic(wasm: &str) -> Result<()> {
assert_eq!(headers.get("x-served-by").unwrap(), "land-edge");
Ok(())
}

pub async fn test_rust_fetch(wasm: &str) -> Result<()> {
let client = reqwest::Client::new();
let resp = client
.get(RUMTIME_SERVER)
.header("x-land-module", wasm)
.send()
.await?;
info!("resp: {:?}", resp);
assert_eq!(resp.status(), 200);
let body = resp.text().await?;
assert!(body.contains("Rust Programming Language"));
Ok(())
}

pub async fn test_rust_router(wasm: &str) -> Result<()> {
let client = reqwest::Client::new();
let resp = client
.get(format!("{}/hello", RUMTIME_SERVER))
.header("x-land-module", wasm)
.send()
.await?;
info!("resp: {:?}", resp);
assert_eq!(resp.status(), 200);
let body = resp.text().await?;
assert_eq!(body, "Hello, World");

let resp = client
.get(format!("{}/foo/bar", RUMTIME_SERVER))
.header("x-land-module", wasm)
.send()
.await?;
info!("resp: {:?}", resp);
assert_eq!(resp.status(), 200);
let body = resp.text().await?;
assert_eq!(body, "Foo Bar");

let resp = client
.get(format!("{}/params/xyz", RUMTIME_SERVER))
.header("x-land-module", wasm)
.send()
.await?;
info!("resp: {:?}", resp);
assert_eq!(resp.status(), 200);
let body = resp.text().await?;
assert_eq!(body, "value: xyz");

Ok(())
}
7 changes: 3 additions & 4 deletions tests/integration-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ async fn main() {
info!("create wasm-dist dir: {:?}", wasm_dist);
}

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

match name {
"rust-basic" => case::test_rust_basic(wasm).await?,
//"rust-fetch" => case::test_rust_fetch(wasm).await?,
//"rust-router" => case::test_rust_router(wasm).await?,
"rust-fetch" => case::test_rust_fetch(wasm).await?,
"rust-router" => case::test_rust_router(wasm).await?,
_ => return Err(anyhow::anyhow!("unknown template name: {}", name)),
}

Expand Down

0 comments on commit c764ba8

Please sign in to comment.